Scopira  20080306
prop.h
1 
2 /*
3  * Copyright (c) 2002 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED_SCOPIRA_TOOL_PROP_H__
15 #define __INCLUDED_SCOPIRA_TOOL_PROP_H__
16 
17 #include <list>
18 #include <map>
19 
20 #include <scopira/tool/object.h>
21 #include <scopira/tool/flow.h>
22 #include <scopira/tool/iterator.h>
23 
24 namespace scopira
25 {
26  namespace tool
27  {
28  class property;
29  class property_node;
30  }
31 }
32 
39 {
40  public:
43 
44  protected:
45  std::string dm_val;
46  count_ptr<object> dm_obj;
47 
48  public:
50  property(void);
52  property(const std::string &_val);
54  property(object *o);
56  virtual ~property();
57 
59  virtual oflow_i & print(oflow_i& o) const;
61  virtual bool load(iobjflow_i& in);
63  virtual void save(oobjflow_i& out) const;
64 
66  virtual bool is_node(void) const { return false; }
67 
70  virtual void add_end(const std::string& name, property* prop) { }
72  virtual iterator get(const std::string& name);
74  virtual property * get_first(const std::string& name) { return 0; }
75  // gets the size of a list, same cost as list<>::size
76  virtual size_t get_size(const std::string &name) const { return 0; }
78  virtual bool contains(const std::string& name) const { return false; }
80  virtual void remove(const std::string& name) { }
82  virtual key_iterator get_key_iterator(void);
84  virtual const std::string * get_string_value(const std::string &name) const { return 0; }
86  virtual object * get_object_value(const std::string &name) const { return 0; }
87 
89  void set_value(const std::string& val);
91  const std::string& get_value_as_string(void) const { return dm_val; }
93  void set_value(object *obj);
95  object * get_value_as_object(void) const { return dm_obj.get(); }
96 };
97 
104 {
105  public:
106  typedef std::list < scopira::tool::count_ptr< scopira::tool::property > > sproplist_t; typedef std::map < std::string, sproplist_t > propmap_t;
107 
108  protected:
109  propmap_t dm_propmap;
110 
111  public:
113  property_node(void);
115  virtual ~property_node();
116 
118  virtual oflow_i & print(oflow_i &o) const;
120  virtual bool load(iobjflow_i &in);
122  virtual void save(oobjflow_i &out) const;
123 
125  virtual bool is_node(void) const { return true; }
126 
132  virtual void add_end(const std::string& name, property* prop);
139  virtual iterator get(const std::string& name);
145  virtual property * get_first(const std::string& name);
151  virtual size_t get_size(const std::string &name) const;
157  virtual bool contains(const std::string& name) const;
163  virtual void remove(const std::string& name);
164 
171  virtual key_iterator get_key_iterator(void);
172 
178  virtual const std::string * get_string_value(const std::string &name) const;
184  virtual object * get_object_value(const std::string &name) const;
185 };
186 
187 #endif
188 
Definition: archiveflow.h:20
void set_value(const std::string &val)
sets the value string
Definition: flow.h:352
virtual const std::string * get_string_value(const std::string &name) const
convinience routine, will always work, might return null
Definition: prop.h:84
virtual bool load(iobjflow_i &in)
serialization loader
T * get(void) const
Definition: object.h:378
virtual void add_end(const std::string &name, property *prop)
Definition: prop.h:70
Definition: object.h:71
virtual ~property()
destructor
Definition: iterator.h:26
Definition: object.h:42
virtual key_iterator get_key_iterator(void)
returns an iterator of keys
const std::string & get_value_as_string(void) const
gets the value string
Definition: prop.h:91
object * get_value_as_object(void) const
gets the value, as a object
Definition: prop.h:95
Definition: prop.h:103
virtual property * get_first(const std::string &name)
gets the first entry. this will crash if the entry doesnt exist!
Definition: prop.h:74
Definition: prop.h:38
Definition: flow.h:421
property(void)
default constructor
virtual bool is_node(void) const
is this a record prop? (default, false)
Definition: prop.h:66
virtual object * get_object_value(const std::string &name) const
convinience routine, will always work, might return null
Definition: prop.h:86
virtual bool is_node(void) const
is this a record prop?
Definition: prop.h:125
virtual oflow_i & print(oflow_i &o) const
pretty ascii printer
virtual bool contains(const std::string &name) const
does the given key exist, at all
Definition: prop.h:78
virtual void save(oobjflow_i &out) const
serialization saver
Definition: flow.h:159