util/Prop.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      Prop.h
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   Holding data for a property
00006 Version:   $Id: Prop.h 12937 2004-11-24 20:15:11Z ruff $
00007 ------------------------------------------------------------------------------*/
00008 
00018 #ifndef _UTIL_PROP_H
00019 #define _UTIL_PROP_H
00020 
00021 #include <util/Property.h>
00022 
00023 
00024 
00025 namespace org { namespace xmlBlaster { namespace util {
00026 
00027 enum prop_enum {
00028    CREATED_BY_DEFAULT,
00029    CREATED_BY_JVMENV,
00030    CREATED_BY_PROPFILE,
00031    CREATED_BY_CMDLINE,
00032    CREATED_BY_SETTER
00033 };
00034 
00035 typedef enum prop_enum PropEnum;
00036 
00037 template <class T> class Dll_Export Prop
00038 {
00039 private:
00040    T        value_;
00041    PropEnum origin_;
00042 
00043 public:
00044    
00045    Prop(const T& value=T(), PropEnum origin=CREATED_BY_DEFAULT)
00046    {
00047       value_  = value;
00048       origin_ = origin;
00049    }
00050 
00051    Prop(const Prop& prop) 
00052    {
00053       value_ = prop.value_;
00054       origin_ = prop.origin_;
00055    }
00056 
00057    Prop& operator =(const Prop& prop) 
00058    {
00059       value_ = prop.value_;
00060       origin_ = prop.origin_;
00061       return *this;
00062    }
00063 
00064    bool setValue(Property& prop, const std::string& propName)
00065    {
00066       if (origin_ >= CREATED_BY_SETTER) return false;
00067       if (prop.getTypedProperty(propName, value_, false)) {
00068          origin_ = CREATED_BY_CMDLINE;
00069          return true;
00070       }
00071       if (origin_ > CREATED_BY_JVMENV) return false;
00072       if (prop.getTypedProperty(propName, value_, true)) return true;
00073       return false;
00074    }
00075 
00076    bool setValue(const T& value, PropEnum origin=CREATED_BY_DEFAULT)
00077    {
00078       if (origin < origin_) return false;
00079       origin_ = origin;
00080       value_ = value;
00081       return true;
00082    }
00083 
00084    PropEnum getOrigin() const
00085    {
00086       return origin_;
00087    }
00088   
00089    T getValue() const 
00090    {
00091       return value_;
00092    }
00093 
00097    const bool isModified() const
00098    {
00099       return origin_ != CREATED_BY_DEFAULT;
00100    }
00101 
00107 /*
00108    toXml(const std::string&  name, const std::string& offset="", bool forceWrite=false)
00109    {
00110       if (origin_ > CREATED_BY_DEFAULT || forceWrite) {
00111          return "<" + name + ">" +  .... (not finished yet);
00112       }
00113    }
00114 */   
00115 };
00116 
00117 }}} // namespaces
00118 
00119 #endif