Added copyright lines for files I've edited this year.
[synfig.git] / synfig-core / trunk / src / synfig / value.cpp
index b942308..d80fbf9 100644 (file)
@@ -1,20 +1,22 @@
-/* === S I N F G =========================================================== */
+/* === S Y N F I G ========================================================= */
 /*!    \file value.cpp
 **     \brief Template Header
 **
-**     $Id: value.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
+**     $Id$
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007, 2008 Chris Moore
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **     \endlegal
 */
 /* ========================================================================= */
@@ -43,7 +45,7 @@
 
 #endif
 
-using namespace sinfg;
+using namespace synfig;
 using namespace std;
 using namespace etl;
 
@@ -64,50 +66,22 @@ ValueBase::ValueBase(Type x):
        data(0),
        loop_(0)
 {
-
        switch(type)
        {
-       case TYPE_BOOL:
-               static_cast<bool*>(data)=new bool();
-               break;
-       case TYPE_INTEGER:
-               static_cast<int*>(data)=new int();
-               break;
-       case TYPE_ANGLE:
-               static_cast<Angle*>(data)=new Angle();
-               break;
-       case TYPE_VECTOR:
-               static_cast<Vector*>(data)=new Vector();
-               break;
-       case TYPE_TIME:
-               static_cast<Time*>(data)=new Time();
-               break;
-       case TYPE_REAL:
-               static_cast<Real*>(data)=new Real();
-               break;
-       case TYPE_COLOR:
-               static_cast<Color*>(data)=new Color();
-               break;
-       case TYPE_SEGMENT:
-               static_cast<Segment*>(data)=new Segment();
-               break;
-       case TYPE_BLINEPOINT:
-               static_cast<BLinePoint*>(data)=new BLinePoint();
-               break;
-       case TYPE_LIST:
-               static_cast<list_type*>(data)=new list_type();
-               break;
-       case TYPE_STRING:
-               static_cast<String*>(data)=new String();
-               break;
-       case TYPE_GRADIENT:
-               static_cast<Gradient*>(data)=new Gradient();
-               break;
-       case TYPE_CANVAS:
-               static_cast<etl::handle<Canvas>*>(data)=new etl::handle<Canvas>();
-               break;
-       default:
-               break;
+       case TYPE_BOOL:                 data=static_cast<void*>(new bool());                            break;
+       case TYPE_INTEGER:              data=static_cast<void*>(new int());                                     break;
+       case TYPE_ANGLE:                data=static_cast<void*>(new Angle());                           break;
+       case TYPE_VECTOR:               data=static_cast<void*>(new Vector());                          break;
+       case TYPE_TIME:                 data=static_cast<void*>(new Time());                            break;
+       case TYPE_REAL:                 data=static_cast<void*>(new Real());                            break;
+       case TYPE_COLOR:                data=static_cast<void*>(new Color());                           break;
+       case TYPE_SEGMENT:              data=static_cast<void*>(new Segment());                         break;
+       case TYPE_BLINEPOINT:   data=static_cast<void*>(new BLinePoint());                      break;
+       case TYPE_LIST:                 data=static_cast<void*>(new list_type());                       break;
+       case TYPE_STRING:               data=static_cast<void*>(new String());                          break;
+       case TYPE_GRADIENT:             data=static_cast<void*>(new Gradient());                        break;
+       case TYPE_CANVAS:               data=static_cast<void*>(new etl::handle<Canvas>());     break;
+       default:                                                                                                                                        break;
        }
 }
 
@@ -122,9 +96,6 @@ ValueBase::get(const char*)const
        return get(String()).c_str();
 }
 
-
-
-
 void
 ValueBase::set(Canvas* x)
 {
@@ -145,13 +116,9 @@ ValueBase::set(etl::loose_handle<Canvas> x)
 {
        clear();
        if(x && x->is_inline())
-       {
                _set(etl::handle<Canvas>(x));
-       }
        else
-       {
                _set(etl::loose_handle<Canvas>(x));
-       }
        assert(get(x)==x);
 }
 
@@ -160,13 +127,9 @@ ValueBase::set(etl::handle<Canvas> x)
 {
        clear();
        if(x && x->is_inline())
-       {
                _set(etl::handle<Canvas>(x));
-       }
        else
-       {
                _set(etl::loose_handle<Canvas>(x));
-       }
        assert(get(x)==x);
 }
 
@@ -182,6 +145,12 @@ ValueBase::set(const char* x)
        _set(String(x));
 }
 
+void
+ValueBase::set(char* x)
+{
+       _set(String(x));
+}
+
 bool
 ValueBase::is_valid()const
 {
@@ -223,62 +192,32 @@ ValueBase::clear()
        {
                switch(type)
                {
-               case TYPE_BOOL:
-                       delete static_cast<bool*>(data);
-                       break;
-               case TYPE_INTEGER:
-                       delete static_cast<int*>(data);
-                       break;
-               case TYPE_ANGLE:
-                       delete static_cast<Angle*>(data);
-                       break;
-               case TYPE_VECTOR:
-                       delete static_cast<Vector*>(data);
-                       break;
-               case TYPE_TIME:
-                       delete static_cast<Time*>(data);
-                       break;
-               case TYPE_REAL:
-                       delete static_cast<Real*>(data);
-                       break;
-               case TYPE_COLOR:
-                       delete static_cast<Color*>(data);
-                       break;
-               case TYPE_SEGMENT:
-                       delete static_cast<Segment*>(data);
-                       break;
-               case TYPE_BLINEPOINT:
-                       delete static_cast<BLinePoint*>(data);
-                       break;
-               case TYPE_LIST:
-                       delete static_cast<list_type*>(data);
-                       break;
-               case TYPE_STRING:
-                       delete static_cast<String*>(data);
-                       break;
-               case TYPE_GRADIENT:
-                       delete static_cast<Gradient*>(data);
-                       break;
-
-
+               case TYPE_BOOL:                 delete static_cast<bool*>(data);                break;
+               case TYPE_INTEGER:              delete static_cast<int*>(data);                 break;
+               case TYPE_ANGLE:                delete static_cast<Angle*>(data);               break;
+               case TYPE_TIME:                 delete static_cast<Time*>(data);                break;
+               case TYPE_REAL:                 delete static_cast<Real*>(data);                break;
+               case TYPE_VECTOR:               delete static_cast<Vector*>(data);              break;
+               case TYPE_COLOR:                delete static_cast<Color*>(data);               break;
+               case TYPE_SEGMENT:              delete static_cast<Segment*>(data);             break;
+               case TYPE_BLINEPOINT:   delete static_cast<BLinePoint*>(data);  break;
+               case TYPE_LIST:                 delete static_cast<list_type*>(data);   break;
                case TYPE_CANVAS:
                {
                        etl::handle<Canvas> canvas(get(etl::loose_handle<Canvas>()));
                        if(canvas && canvas->is_inline())
-                       {
                                delete static_cast<etl::handle<Canvas>*>(data);
-                       }
                        else
-                       {
                                delete static_cast<etl::loose_handle<Canvas>*>(data);
-                       }
                        break;
                }
+               case TYPE_STRING:               delete static_cast<String*>(data);              break;
+               case TYPE_GRADIENT:             delete static_cast<Gradient*>(data);    break;
                default:
                        break;
                }
        }
-       
+
        ref_count.detach();
        data=0;
        type=TYPE_NIL;
@@ -288,75 +227,80 @@ ValueBase::clear()
 String
 ValueBase::type_name(Type id)
 {
+       // don't internationalize these type names - they're using in .sif files
        switch(id)
        {
-       case TYPE_REAL:
-               return "real";
-       case TYPE_TIME:
-               return "time";
-       case TYPE_INTEGER:
-               return "integer";
-       case TYPE_BOOL:
-               return "bool";
-       case TYPE_ANGLE:
-               return "angle";
-       case TYPE_VECTOR:
-               return "vector";
-       case TYPE_COLOR:
-               return "color";
-       case TYPE_STRING:
-               return "string";
-       case TYPE_CANVAS:
-               return "canvas";
-       case TYPE_LIST:
-               return "list";
-       case TYPE_SEGMENT:
-               return "segment";
-       case TYPE_GRADIENT:
-               return "gradient";
-       case TYPE_BLINEPOINT:
-               return "bline_point";
-       case TYPE_NIL:
-               return "nil";
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_BOOL:                 return N_("bool");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_INTEGER:              return N_("integer");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_ANGLE:                return N_("angle");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_TIME:                 return N_("time");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_REAL:                 return N_("real");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_VECTOR:               return N_("vector");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_COLOR:                return N_("color");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_SEGMENT:              return N_("segment");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_BLINEPOINT:   return N_("bline_point");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_LIST:                 return N_("list");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_CANVAS:               return N_("canvas");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_STRING:               return N_("string");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_GRADIENT:             return N_("gradient");
+               /* TRANSLATORS: this is the name of a type -- see http://synfig.org/Types */
+       case TYPE_NIL:                  return N_("nil");
        default:
                break;
        }
-       sinfg::warning("Encountered unknown ValueBase with an Type of %d",id);
+       synfig::warning("Encountered unknown ValueBase with an Type of %d",id);
 //     assert(0);
        return "UNKNOWN";
 }
 
+String
+ValueBase::type_local_name(Type id)
+{
+       return dgettext("synfig",type_name(id).c_str());
+}
+
 ValueBase::Type
 ValueBase::ident_type(const String &str)
 {
-       if(str=="nil" || str=="null")
-               return TYPE_NIL;
-       else if(str=="time" || str==_("time"))
-               return TYPE_TIME;
-       else if(str=="real" || str=="float" || str==_("real"))
-               return TYPE_REAL;
-       else if(str=="integer" || str=="int" || str==_("integer"))
-               return TYPE_INTEGER;
-       else if(str=="bool" || str==_("bool"))
-               return TYPE_BOOL;
-       else if(str=="angle" || str=="degrees" || str=="radians" || str=="rotations")
-               return TYPE_ANGLE;
-       else if(str=="vector" || str=="point")
-               return TYPE_VECTOR;
-       else if(str=="color")
-               return TYPE_COLOR;
-       else if(str=="string")
-               return TYPE_STRING;
-       else if(str=="canvas")
-               return TYPE_CANVAS;
-       else if(str=="list")
-               return TYPE_LIST;
-       else if(str=="segment")
-               return TYPE_SEGMENT;
-       else if(str=="gradient")
-               return TYPE_GRADIENT;
-       else if(str=="bline_point" || str=="blinepoint")
-               return TYPE_BLINEPOINT;
+       if(str=="nil" ||
+          str=="null")                         return TYPE_NIL;
+       else if(str=="time" ||
+                       str==_("time"))         return TYPE_TIME;
+       else if(str=="real" ||
+                       str=="float" ||
+                       str==_("real"))         return TYPE_REAL;
+       else if(str=="integer" ||
+                       str=="int" ||
+                       str==_("integer"))      return TYPE_INTEGER;
+       else if(str=="bool" ||
+                       str==_("bool"))         return TYPE_BOOL;
+       else if(str=="angle" ||
+                       str=="degrees" ||
+                       str=="radians" ||
+                       str=="rotations")       return TYPE_ANGLE;
+       else if(str=="vector" ||
+                       str=="point")           return TYPE_VECTOR;
+       else if(str=="color")           return TYPE_COLOR;
+       else if(str=="string")          return TYPE_STRING;
+       else if(str=="canvas")          return TYPE_CANVAS;
+       else if(str=="list")            return TYPE_LIST;
+       else if(str=="segment")         return TYPE_SEGMENT;
+       else if(str=="gradient")        return TYPE_GRADIENT;
+       else if(str=="bline_point" ||
+                       str=="blinepoint")      return TYPE_BLINEPOINT;
 
        return TYPE_NIL;
 }
@@ -368,39 +312,24 @@ ValueBase::operator==(const ValueBase& rhs)const
                return false;
        if(data==rhs.data)
                return true;
-       
+
        switch(get_type())
        {
-       case TYPE_TIME:
-               return get(Time()).is_equal(rhs.get(Time()));
-       case TYPE_REAL:
-               return abs(get(Real())-rhs.get(Real()))<=0.00000000000001;
-       case TYPE_INTEGER:
-               return get(int())==rhs.get(int());
-       case TYPE_BOOL:
-               return get(bool())==rhs.get(bool());
-       case TYPE_ANGLE:
-               return get(Angle())==rhs.get(Angle());
-       case TYPE_VECTOR:
-               return get(Vector()).is_equal_to(rhs.get(Vector()));
-       case TYPE_COLOR:
-               return get(Color())==rhs.get(Color());
-       case TYPE_STRING:
-               return get(String())==rhs.get(String());
-       case TYPE_CANVAS:
-               return get(Canvas::LooseHandle())==rhs.get(Canvas::LooseHandle());
-       case TYPE_LIST:
-               return get_list()==rhs.get_list();
-       case TYPE_SEGMENT:
-//             return get(Segment())==rhs.get(Segment());
-       case TYPE_GRADIENT:
-//             return get(Gradient())==rhs.get(Gradient());
-       case TYPE_BLINEPOINT:
-//             return get(BLinePoint())==rhs.get(BLinePoint());
+       case TYPE_TIME:                    return get(Time()).is_equal(rhs.get(Time()));
+       case TYPE_REAL:                    return abs(get(Real())-rhs.get(Real()))<=0.00000000000001;
+       case TYPE_INTEGER:                 return get(int())==rhs.get(int());
+       case TYPE_BOOL:                    return get(bool())==rhs.get(bool());
+       case TYPE_ANGLE:                   return get(Angle())==rhs.get(Angle());
+       case TYPE_VECTOR:                  return get(Vector()).is_equal_to(rhs.get(Vector()));
+       case TYPE_COLOR:                   return get(Color())==rhs.get(Color());
+       case TYPE_STRING:                  return get(String())==rhs.get(String());
+       case TYPE_CANVAS:                  return get(Canvas::LooseHandle())==rhs.get(Canvas::LooseHandle());
+       case TYPE_LIST:                    return get_list()==rhs.get_list();
+       case TYPE_SEGMENT:              // return get(Segment())==rhs.get(Segment());
+       case TYPE_GRADIENT:             // return get(Gradient())==rhs.get(Gradient());
+       case TYPE_BLINEPOINT:   // return get(BLinePoint())==rhs.get(BLinePoint());
        case TYPE_NIL:
-       default:
-               return false;
-               break;
+       default:                                   return false;
        }
        return false;
 }