utypes-common.hh

Go to the documentation of this file.
00001 // This file is part of UObject Component Architecture\n
00002 // (c) 2006 Gostai S.A.S.
00003 //
00004 // Permission to use, copy, modify, and redistribute this software for
00005 // non-commercial use is hereby granted.
00006 //
00007 // This software is provided "as is" without warranty of any kind,
00008 // either expressed or implied, including but not limited to the
00009 // implied warranties of fitness for a particular purpose.
00010 //
00011 // For more information, comments, bug reports: http://www.urbiforge.com
00012 
00013 #ifndef URBI_UTYPES_COMMON_HH
00014 # define URBI_UTYPES_COMMON_HH
00015 
00016 # include <cassert>
00017 
00020 
00021 namespace urbi
00022 {
00023 
00024   /*-------------.
00025   | UBlendType.  |
00026   `-------------*/
00027 
00028   //WARNING: synchronize with blendNames below, must be 0-based
00030   enum UBlendType
00031   {
00032     UMIX,
00033     UADD,
00034     UDISCARD,
00035     UQUEUE,
00036     UCANCEL,
00037     UNORMAL
00038   };
00039 
00040   namespace
00041   {
00042     const char* UBlendNames[]=
00043     {
00044       "mix",
00045       "add",
00046       "discard",
00047       "queue",
00048       "cancel",
00049       "normal",
00050     };
00051   }
00052 
00053   inline
00054   // FIXME: This is needed by urbi-sdk/uvar.cc.
00055   bool
00056   is_blendtype (int i)
00057   {
00058     return static_cast<int> (UMIX) <= i && i <= static_cast<int> (UNORMAL);
00059   }
00060 
00061   // values for enum-like properties
00062   inline
00063   const char*
00064   name (UBlendType u)
00065   {
00066     return UBlendNames[static_cast <int> (u)];
00067   }
00068 
00069   inline
00070   UBlendType
00071   ublendtype (const char* cp)
00072   {
00073     for (int i = 0; is_blendtype (i); ++i)
00074       if (STREQ (UBlendNames[i], cp))
00075         return static_cast<UBlendType> (i);
00076     assert (!"unknown blendtype");
00077   }
00078 
00079   /*------------.
00080   | UProperty.  |
00081   `------------*/
00082 
00084   enum UProperty
00085   {
00086     PROP_RANGEMIN,
00087     PROP_RANGEMAX,
00088     PROP_SPEEDMIN,
00089     PROP_SPEEDMAX,
00090     PROP_BLEND,
00091     PROP_DELTA,
00092   };
00093 
00094   namespace
00095   {
00096     const char* UPropertyNames[]=
00097     {
00098       "rangemin",
00099       "rangemax",
00100       "speedmin",
00101       "speedmax",
00102       "blend",
00103       "delta",
00104     };
00105   }
00106 
00107   // FIXME: This is needed by urbi-sdk/uvar.cc.
00108   inline
00109   bool
00110   is_propertytype (int i)
00111   {
00112     return (static_cast<int> (PROP_RANGEMAX) <= i
00113             && i <= static_cast<int> (PROP_DELTA));
00114   }
00115 
00116   // values for enum-like properties
00117   inline
00118   const char*
00119   name (UProperty u)
00120   {
00121     return UPropertyNames[static_cast <int> (u)];
00122   }
00123 
00124   inline
00125   UProperty
00126   uproperty (const char* cp)
00127   {
00128     for (int i = 0; is_propertytype (i); ++i)
00129       if (STREQ (UPropertyNames[i], cp))
00130         return static_cast<UProperty> (i);
00131     assert (!"unknown uproperty");
00132   }
00133 
00134 } // end namespace urbi
00135 
00136 #endif // ! URBI_UTYPES_COMMON_HH

Generated on Tue Apr 10 17:45:45 2007 for URBISDK by  doxygen 1.5.1