RegistryBase.h

Go to the documentation of this file.
00001 #ifndef __REGISTRYBASE_H__
00002 #define __REGISTRYBASE_H__
00003 
00004 /*
00005 
00006 $Header$
00007 
00008 */
00009 
00010 #include "NamedObject.h"
00011 #include "String.h"
00012 
00013 // Messages.
00014 static const char *const MSG_REGISTRY_EMPTY_NAME = "Empty registry name.";
00015 static const char *const MSG_REGISTRY_NOT_FOUND  = "Registry '%s' not found.";
00016 
00017 using namespace std;
00018 
00019 static const unsigned char REG_PERSISTENCY_SHIFT = 16;
00020 static const unsigned char REG_ACCESS_MODE_SHIFT = 8;
00021 static const unsigned char REG_VISIBILITY_SHIFT  = 0;
00022 
00023 typedef enum
00024 {
00025   REG_PERSISTENCY_YES = 'Y' << REG_PERSISTENCY_SHIFT,
00026   REG_PERSISTENCY_NO  = 'N' << REG_PERSISTENCY_SHIFT
00027 } RegistryPersistency;
00028 
00029 typedef enum
00030 {
00031   REG_ACCESS_READ_ONLY  = 'R' << REG_ACCESS_MODE_SHIFT,
00032   REG_ACCESS_WRITE_ONLY = 'W' << REG_ACCESS_MODE_SHIFT,
00033   REG_ACCESS_FULL       = 'F' << REG_ACCESS_MODE_SHIFT
00034 } RegistryAccessMode;
00035 
00036 typedef enum
00037 {
00038   REG_VISIBILITY_PRIVATE    = 'p' << REG_VISIBILITY_SHIFT,
00039   REG_VISIBILITY_PROTECTED  = 'P' << REG_VISIBILITY_SHIFT,
00040   REG_VISIBILITY_PUBLIC     = 'a' << REG_VISIBILITY_SHIFT,
00041   REG_VISIBILITY_PUBLISHED  = 'A' << REG_VISIBILITY_SHIFT
00042 } RegistryVisibility;
00043 
00044 typedef unsigned int RegistryFlags;
00045 
00046 static const RegistryFlags REG_FLAGS_DEFAULT = REG_PERSISTENCY_YES | REG_ACCESS_FULL | REG_VISIBILITY_PUBLISHED;
00047 
00048 class RegistryBase : public NamedObject
00049 {
00050 
00051   PYLON_OBJECT
00052 
00053 public:
00054 
00055   RegistryBase(const String &name, const String& manual = "", const RegistryFlags flags = REG_FLAGS_DEFAULT);
00056   virtual ~RegistryBase();
00057 
00058   virtual bool hasGetter() const = 0;
00059   virtual bool hasSetter() const = 0;
00060 
00061   RegistryAccessMode accessMode() const;
00062   RegistryVisibility visibility() const;
00063   RegistryPersistency persistency() const;
00064 
00065   virtual int toString(String &str) = 0;
00066   virtual int fromString(const String &str) = 0;
00067 
00068   static int setStr(const String &name, const String &value, Object *owner = NULL);
00069   static int setStr(const String &name, const String &value, const ObjectId ownerId);
00070   static int getStr(const String &name, String &value, Object *owner = NULL);
00071   static int getStr(const String &name, String &value, const ObjectId ownerId);
00072 
00073   int bind(Object *owner = NULL);
00074   bool binded() const;
00075 
00076 protected:
00077 
00078   static int get(const String &name, RegistryBase **reg, Object *owner = NULL);
00079 
00080   inline Object *owner() const;
00081 
00082 private:
00083 
00084   inline static String ajustName(const String &name);
00085 
00086   RegistryAccessMode _accessMode;
00087   RegistryVisibility _visibility;
00088   RegistryPersistency _persistency;
00089   bool _isBinded;
00090   Object *_owner;
00091 };
00092 
00093 inline Object *RegistryBase::owner() const
00094 {
00095   return _owner;
00096 }
00097 
00098 inline String RegistryBase::ajustName(const String &name)
00099 {
00100   return String::toLower(name).replaceSubStr("__", ".");
00101 }
00102 
00103 #define REGISTRY_SET_STR(name, value, ...) RegistryBase::setStr(name, value, ##__VA_ARGS__)
00104 #define REGISTRY_GET_STR(name, value, ...) RegistryBase::getStr(name, value, ##__VA_ARGS__)
00105 
00106 #endif

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1