interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/vos/basiclocalproperty.hh

Go to the documentation of this file.
00001 #ifndef _BASICLOCALPROPERTY_HH_
00002 #define _BASICLOCALPROPERTY_HH_
00003 
00004 #include <vos/vos/localproperty.hh>
00005 #include <vos/vos/propertylistener.hh>
00006 
00007 
00008 namespace VOS {
00009 
00010 /** @class BasicLocalProperty basiclocalproperty.hh vos/metaobjects/property/basiclocalproperty.hh
00011     Base class for local properties.  Simply stores data and listeners.
00012     @ingroup libmetaobject_property
00013   */
00014     class VOS_API BasicLocalProperty : public LocalProperty, public PersistBlockListener
00015 {
00016 private:
00017     boost::recursive_mutex data_mutex;
00018 
00019     std::string data;
00020     std::string datatype;
00021 
00022     VUtil::ListenerBase<PropertyListener, PropertyEvent> propertyListeners;
00023 
00024 protected:
00025     BasicLocalProperty(VobjectBase* superobject);
00026 
00027 public:
00028 
00029     static MetaObject* new_BasicLocalProperty(VobjectBase* superobject, const std::string& calledtype);
00030 
00031     /** Get length (bytes) of decoded data. */
00032     virtual int getLength();
00033 
00034     /** Read decoded data into target, possibly performing decode if necesary
00035      * @see read(std::string, int, int)
00036      */
00037     virtual void read(std::string& target);
00038 
00039     /** Read a substring of decoded data into target, possibly performing decode if necesary
00040      * @param target    Place data in this string
00041      * @param start     Byte offset to start reading
00042      * @param length    Number of bytes to read. If this parameter is -1, read
00043      *                  until the end of the data.
00044      */
00045     virtual void read(std::string& target, int start, int length);
00046 
00047     /** Return decoded data, possibly performing decode if necesary
00048      * @see read(std::string, int int)
00049      */
00050     virtual std::string read();
00051 
00052     /** Return substring of decoded data, possibly performing decode if necesary
00053         @see read(std::string, int int)
00054      */
00055     virtual std::string read(int start, int length);
00056 
00057     virtual void write(int start, const std::string& newdata)
00058         { write(0, start, newdata); }
00059 
00060     virtual void replace(const std::string& newdata, const std::string& newtype = "?")
00061         { replace(0, newdata, newtype); }
00062 
00063     /** Write newdata into property value, starting at byte position start */
00064     virtual void write(Vobject* initiator, int start, const std::string& newdata);
00065 
00066     /** Completely change the value and type of data stored in this property.
00067         @param initiator Object requesting replacement, for access control check.
00068         @param newdata New data.
00069         @param newtype The type of the new datatype. If no type identifier was supplied, the previous one is kept.
00070     */
00071     virtual void replace(Vobject* initiator, const std::string& newdata, const std::string& newtype = "?");
00072 
00073     /** Return type of decoded data (usually a MIME type) */
00074     virtual const std::string getDataType();
00075 
00076     /** Set a subproperty on an object, returning relation between object and property.
00077      *  @param on   Object to set a subproperty on
00078      *  @param propname Name of the property to set
00079      *  @param propval  New value of the property
00080      *  @param valtype  Datatype of the new value
00081      *  @param pac  Property access control to add to the object it it had to be created (If property exists, this argument is ignored)
00082      *  @param letErrorThrough If given, determines whether exceptions will be
00083      *  caught in this method (false), or thrown out to the caller (true).
00084      *  @return object expressing relation between the object and the property
00085      */
00086     static VUtil::vRef<ParentChildRelation> setProperty(Vobject& on,
00087                                                  const std::string& propname,
00088                                                  const std::string& propval,
00089                                                  const std::string& valtype,
00090                                                  const std::string& pac,
00091                                                  bool letErrorThrough = false);
00092 
00093     /** Add a new property listener to this property. This listener's methods
00094      * will be called when the property is modified.
00095      * @see PropertyListener
00096      * @param pl    The new property listener. If it is also a RefCounted
00097      * object, references will be acquired correctly.
00098      * @param refresh If given, determines whether the new property listener
00099      * will be immediately notified of the current property contents.
00100      */
00101     virtual void addPropertyListener(PropertyListener* pl, bool refresh = true);
00102 
00103     /** Remove the property listener 'pl' from this property.
00104      * @param pl    Listener to remove. If it is also a RefCounted object,
00105      * references will be released correctly.
00106      */
00107     virtual void removePropertyListener(PropertyListener* pl);
00108 
00109     /** Return MetaObject type, "property" */
00110     virtual const std::string getVOSType();
00111 
00112     /** @see VUtil::ListenernBase::getAsynchronousEvents() */
00113     virtual bool getAsynchronousEvents() {
00114         return propertyListeners.getAsynchronousEvents();
00115     }
00116     /** @see VUtil::ListenernBase::setAsynchronousEvents() */
00117     virtual void setAsynchronousEvents(bool b) {
00118         propertyListeners.setAsynchronousEvents(b);
00119     }
00120 
00121     virtual void notifyBlockChanging(const std::string& key, const std::string& data);
00122     virtual void notifyBlockChanged(const std::string& key, const std::string& data);
00123 };
00124 
00125 }
00126 
00127 #endif