Urbi SDK Remote for C++  2.7.5
uvar.hh
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007, 2008, 2009, 2010, Gostai S.A.S.
00003  *
00004  * This software is provided "as is" without warranty of any kind,
00005  * either expressed or implied, including but not limited to the
00006  * implied warranties of fitness for a particular purpose.
00007  *
00008  * See the LICENSE file for more information.
00009  */
00010 
00012 #ifndef URBI_UVAR_HH
00013 # define URBI_UVAR_HH
00014 
00015 # include <iosfwd>
00016 # include <string>
00017 
00018 # include <libport/fwd.hh>
00019 # include <libport/ufloat.hh>
00020 
00021 # include <urbi/ucontext.hh>
00022 # include <urbi/uvalue.hh>
00023 # include <urbi/uprop.hh>
00024 # include <urbi/uproperty.hh>
00025 
00026 namespace urbi
00027 {
00033   class URBI_SDK_API UVar: public UContext
00034   {
00035   public:
00037     UVar();
00038     UVar(const std::string&, impl::UContextImpl* = 0);
00039     UVar(const std::string&, const std::string&, impl::UContextImpl* = 0);
00040     UVar(UObject&, const std::string&, impl::UContextImpl* = 0);
00041     UVar(const UVar&);
00042   private:
00043     UVar& operator=(const UVar&);
00044   public:
00045     ~UVar();
00046 
00047     // Bind to \a object.slot.
00048     void init(const std::string& varname, impl::UContextImpl* = 0);
00049     void init(const std::string& object, const std::string& slot,
00050               impl::UContextImpl* = 0);
00051     void setOwned();
00052 
00054     UDataType type() const;
00055 
00057     void syncValue();
00058 
00060     void keepSynchronized();
00061 
00062     void reset (ufloat);
00063 
00064     UVar& operator=(ufloat);
00065     UVar& operator=(const std::string&);
00067     UVar& operator=(const UBinary&);
00069     UVar& operator=(const UImage& i);
00071     UVar& operator=(const USound& s);
00072 
00073     UVar& operator=(const UList& l);
00074 
00075     UVar& operator=(const UDictionary& d);
00076 
00077     UVar& operator=(const UValue& v);
00078 
00079     template<typename T>
00080     UVar& operator=(const T&);
00081 
00082     template<typename T>
00083     bool operator ==(const T&) const;
00084 
00086     template<typename T> T as(T*) const;
00088     template<typename T> T as() const;
00090     template<typename T> T& fill(T&) const;
00091 
00092     operator int() const;
00093     operator bool() const;
00094 
00095     // Cast to a UBinary to make copy through this operator.
00096     operator const UBinary&() const;
00097 
00099     operator UBinary*() const;
00100 
00104     operator UImage() const;
00105 
00109     operator USound() const;
00110 
00111     operator ufloat() const;
00112     operator std::string() const;
00113     operator UList() const;
00114     operator UDictionary() const;
00115 
00117     void unnotify();
00118 
00120     ufloat& in();
00121     ufloat& out();
00122 
00124     bool owned;
00125 
00127     UProp rangemin;
00128     UProp rangemax;
00129     UProp speedmin;
00130     UProp speedmax;
00131     UProp delta;
00132     UProp blend;
00133     UProp constant;
00134 
00135     UValue getProp(UProperty prop);
00136     void setProp(UProperty prop, const UValue &v);
00137     void setProp(UProperty prop, ufloat v);
00138     void setProp(UProperty prop, const char * v);
00139     void setProp(UProperty prop, const std::string& v)
00140     {
00141       setProp(prop, v.c_str());
00142     }
00143 
00149     bool setBypass(bool enable=true);
00150 
00152     void useRTP(bool enable=true);
00153     impl::UVarImpl* impl_;
00154     const UValue& val() const;
00155     libport::utime_t timestamp() const;
00156 
00157 
00158     enum RtpMode {
00159       RTP_DEFAULT, 
00160       RTP_YES,     
00161       RTP_NO       
00162     };
00163 
00165     void check() const;
00166   private:
00168     UVardata* vardata;
00169     void __init();
00170 
00172 # define PRIVATE(Type, Name)                    \
00173   public:                                       \
00174     Type get_ ##  Name ()                       \
00175     {                                           \
00176       return Name;                              \
00177     }                                           \
00178     Type get_ ##  Name () const                 \
00179     {                                           \
00180       return Name;                              \
00181     }                                           \
00182     void set_ ##  Name (const Type& v)          \
00183     {                                           \
00184       Name = v;                                 \
00185     }                                           \
00186   private:                                      \
00187     Type Name;
00188 
00190     PRIVATE(std::string, name)
00191 
00192     
00193     PRIVATE(bool, temp);
00194 
00195     PRIVATE(RtpMode, rtp);
00196 
00198     PRIVATE(bool, local);
00199 # undef PRIVATE
00200 
00201     // Check that the invariants of this class are verified.
00202     bool invariant() const;
00203     friend class impl::UVarImpl;
00204   };
00205 
00206   /*-------------------------.
00207   | Inline implementations.  |
00208   `-------------------------*/
00209 
00211 #   define VAR_PROP_INIT                        \
00212   rangemin(*this, PROP_RANGEMIN),               \
00213   rangemax(*this, PROP_RANGEMAX),               \
00214   speedmin(*this, PROP_SPEEDMIN),               \
00215   speedmax(*this, PROP_SPEEDMAX),               \
00216   delta(*this, PROP_DELTA),                     \
00217   blend(*this, PROP_BLEND),                     \
00218   constant(*this, PROP_CONSTANT)
00219 
00221   URBI_SDK_API
00222   std::ostream& operator<< (std::ostream& o, const urbi::UVar& u);
00223 
00224 } // end namespace urbi
00225 
00226 # include <urbi/uvar.hxx>
00227 
00228 #endif // ! URBI_UVAR_HH