Scopira 20080306

prop.h

00001 
00002 /*
00003  *  Copyright (c) 2002    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED_SCOPIRA_TOOL_PROP_H__
00015 #define __INCLUDED_SCOPIRA_TOOL_PROP_H__
00016 
00017 #include <list>
00018 #include <map>
00019  
00020 #include <scopira/tool/object.h>
00021 #include <scopira/tool/flow.h>
00022 #include <scopira/tool/iterator.h>
00023 
00024 namespace scopira
00025 {
00026   namespace tool
00027   {
00028     class property;
00029     class property_node;
00030   }
00031 }
00032 
00038 class scopira::tool::property : public virtual scopira::tool::object
00039 {
00040   public:
00041     typedef scopira::tool::iterator_g<scopira::tool::property*> iterator;
00042     typedef scopira::tool::iterator_g<const std::string *> key_iterator;
00043 
00044   protected:
00045     std::string dm_val;
00046     count_ptr<object> dm_obj;
00047 
00048   public:
00050     property(void);
00052     property(const std::string &_val);
00054     property(object *o);
00056     virtual ~property();
00057 
00059     virtual oflow_i & print(oflow_i& o) const;
00061     virtual bool load(iobjflow_i& in);
00063     virtual void save(oobjflow_i& out) const;
00064 
00066     virtual bool is_node(void) const { return false; }
00067 
00070     virtual void add_end(const std::string& name, property* prop) { }
00072     virtual iterator get(const std::string& name);
00074     virtual property * get_first(const std::string& name) { return 0; }
00075     // gets the size of a list, same cost as list<>::size
00076     virtual size_t get_size(const std::string &name) const { return 0; }
00078     virtual bool contains(const std::string& name) const { return false; }
00080     virtual void remove(const std::string& name) { }
00082     virtual key_iterator get_key_iterator(void);
00084     virtual const std::string * get_string_value(const std::string &name) const { return 0; }
00086     virtual object * get_object_value(const std::string &name) const { return 0; }
00087 
00089     void set_value(const std::string& val);
00091     const std::string& get_value_as_string(void) const { return dm_val; }
00093     void set_value(object *obj);
00095     object * get_value_as_object(void) const { return dm_obj.get(); }
00096 };
00097 
00103 class scopira::tool::property_node : public scopira::tool::property
00104 {
00105   public:
00106     typedef std::list < scopira::tool::count_ptr< scopira::tool::property > > sproplist_t; typedef std::map < std::string, sproplist_t > propmap_t;
00107 
00108   protected:
00109     propmap_t dm_propmap;
00110 
00111   public:
00113     property_node(void);
00115     virtual ~property_node();
00116 
00118     virtual oflow_i & print(oflow_i &o) const;
00120     virtual bool load(iobjflow_i &in);
00122     virtual void save(oobjflow_i &out) const;
00123 
00125     virtual bool is_node(void) const { return true; }
00126 
00132     virtual void add_end(const std::string& name, property* prop);
00139     virtual iterator get(const std::string& name);
00145     virtual property * get_first(const std::string& name);
00151     virtual size_t get_size(const std::string &name) const;
00157     virtual bool contains(const std::string& name) const;
00163     virtual void remove(const std::string& name);
00164 
00171     virtual key_iterator get_key_iterator(void);
00172 
00178     virtual const std::string * get_string_value(const std::string &name) const;
00184     virtual object * get_object_value(const std::string &name) const;
00185 };
00186 
00187 #endif
00188