Nemiver  0.3
nmv-var.h
Go to the documentation of this file.
1 //Author: Dodji Seketeli
2 /*
3  *This file is part of the Nemiver project
4  *
5  *Nemiver is free software; you can redistribute
6  *it and/or modify it under the terms of
7  *the GNU General Public License as published by the
8  *Free Software Foundation; either version 2,
9  *or (at your option) any later version.
10  *
11  *Nemiver is distributed in the hope that it will
12  *be useful, but WITHOUT ANY WARRANTY;
13  *without even the implied warranty of
14  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *See the GNU General Public License for more details.
16  *
17  *You should have received a copy of the
18  *GNU General Public License along with Nemiver;
19  *see the file COPYING.
20  *If not, write to the Free Software Foundation,
21  *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  *See COPYRIGHT file copyright information.
24  */
25 #ifndef __NMV_VAR_H__
26 #define __NMV_VAR_H__
27 
28 #include "common/nmv-ustring.h"
29 
30 NEMIVER_BEGIN_NAMESPACE (nemiver)
31 
32 class Var;
34 class Var : public Object {
35  list<VarSafePtr> m_members;
36  UString m_name;
37  UString m_value;
38  UString m_type;
39  Var *m_parent;
40  //if this variable is a pointer,
41  //it can be dereferenced. The variable
42  //it points to is stored in m_dereferenced
43  VarSafePtr m_dereferenced;
44 
45 public:
46 
47  Var (const UString &a_name,
48  const UString &a_value,
49  const UString &a_type) :
50  m_name (a_name),
51  m_value (a_value),
52  m_type (a_type),
53  m_parent (0)
54 
55  {
56  }
57 
58  Var (const UString &a_name) :
59  m_name (a_name),
60  m_parent (0)
61  {}
62 
63  Var () :
64  m_parent (0)
65  {}
66 
67  const list<VarSafePtr>& members () const {return m_members;}
68 
69  void append (const VarSafePtr &a_var)
70  {
71  if (!a_var) {return;}
72  m_members.push_back (a_var);
73  a_var->parent (this);
74  }
75 
76  const UString& name () const {return m_name;}
77  void name (const UString &a_name) {m_name = a_name;}
78 
79  const UString& value () const {return m_value;}
80  void value (const UString &a_value) {m_value = a_value;}
81 
82  const UString& type () const {return m_type;}
83  void type (const UString &a_type) {m_type = a_type;}
84 
85  Var* parent () const {return m_parent;}
86  void parent (Var *a_parent)
87  {
88  m_parent = a_parent;
89  }
90 
91  void to_string (UString &a_str,
92  bool a_show_var_name = false,
93  const UString &a_indent_str="") const
94  {
95  if (a_show_var_name) {
96  if (name () != "") {
97  a_str += a_indent_str + name ();
98  }
99  }
100  if (value () != "") {
101  if (a_show_var_name) {
102  a_str += "=";
103  }
104  a_str += value ();
105  }
106  if (members ().empty ()) {
107  return;
108  }
109  UString indent_str = a_indent_str + " ";
110  a_str += "\n" + a_indent_str + "{";
111  list<VarSafePtr>::const_iterator it;
112  for (it = members ().begin (); it != members ().end () ; ++it) {
113  if (!(*it)) {continue;}
114  a_str += "\n";
115  (*it)->to_string (a_str, true, indent_str);
116  }
117  a_str += "\n" + a_indent_str + "}";
118  a_str.chomp ();
119  }
120 };//end class Var
121 
123 
124  UString m_name;
125  UString m_id;
126 
127 public:
128 
130  {
131  }
132 
133  VarFragment (const UString &a_id, const UString &a_name) :
134  m_name (a_name), m_id (a_id)
135  {
136  }
137 
138  const UString& get_id () const {return m_id;}
139  void set_id (const UString &a_id) {m_id = a_id;}
140 
141  const UString& get_name () const {return m_name;}
142  void set_name (const UString &a_name) {m_name = a_name;}
143 
144  bool operator= (const VarFragment &a_other)
145  {
146  return a_other.m_id == m_id;
147  }
148 };//end VarFragment
149 
150 NEMIVER_END_NAMESPACE (nemiver)
151 #endif //__NMV_VAR_H__
152 
nemiver::common::Object
Definition: nmv-object.h:43
nemiver::VarFragment::get_id
const UString & get_id() const
Definition: nmv-var.h:138
nemiver::VarFragment::set_name
void set_name(const UString &a_name)
Definition: nmv-var.h:142
nemiver
Definition: nmv-address.h:31
nemiver::common::ObjectRef
Definition: nmv-safe-ptr-utils.h:45
nemiver::VarFragment::get_name
const UString & get_name() const
Definition: nmv-var.h:141
nmv-ustring.h
NEMIVER_API
#define NEMIVER_API
Definition: nmv-api-macros.h:53
nemiver::Var::parent
Var * parent() const
Definition: nmv-var.h:85
nemiver::Var::type
const UString & type() const
Definition: nmv-var.h:82
nemiver::Var::name
void name(const UString &a_name)
Definition: nmv-var.h:77
nemiver::VarFragment::VarFragment
VarFragment(const UString &a_id, const UString &a_name)
Definition: nmv-var.h:133
nemiver::Var::Var
Var(const UString &a_name, const UString &a_value, const UString &a_type)
Definition: nmv-var.h:47
nemiver::common::UString
Definition: nmv-ustring.h:45
nemiver::Var::Var
Var()
Definition: nmv-var.h:63
nemiver::Var::name
const UString & name() const
Definition: nmv-var.h:76
nemiver::Var::type
void type(const UString &a_type)
Definition: nmv-var.h:83
nemiver::VarFragment::VarFragment
VarFragment()
Definition: nmv-var.h:129
nemiver::VarFragment::set_id
void set_id(const UString &a_id)
Definition: nmv-var.h:139
nemiver::Var::append
void append(const VarSafePtr &a_var)
Definition: nmv-var.h:69
nemiver::Var::value
const UString & value() const
Definition: nmv-var.h:79
nemiver::common::UString::chomp
void chomp()
nemiver::VarFragment
Definition: nmv-var.h:122
nemiver::common::ObjectUnref
Definition: nmv-safe-ptr-utils.h:55
nemiver::Var
Definition: nmv-var.h:34
nemiver::Var::value
void value(const UString &a_value)
Definition: nmv-var.h:80
nemiver::Var::Var
Var(const UString &a_name)
Definition: nmv-var.h:58
nemiver::Var::to_string
void to_string(UString &a_str, bool a_show_var_name=false, const UString &a_indent_str="") const
Definition: nmv-var.h:91
nemiver::common::SafePtr
Definition: nmv-safe-ptr.h:71
nemiver::Var::parent
void parent(Var *a_parent)
Definition: nmv-var.h:86
nemiver::Var::members
const list< VarSafePtr > & members() const
Definition: nmv-var.h:67