1 /*
2 * ****************************************************************************
3 * This file is part of libNUML.  Please visit http://code.google.com/p/numl/for more
4 * information about NUML, and the latest version of libNUML.
5 * Copyright (c) 2013 The University of Manchester.
6 *
7 * This library is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation.  A copy of the license agreement is
10 * provided in the file named "LICENSE.txt" included with this software
11 * distribution and also available online as http://www.gnu.org/licenses/lgpl.html
12 *
13 * Contributors:
14 * Joseph O. Dada, The University of Manchester - initial API and implementation
15 * ****************************************************************************
16 **/
17 
18 /**
19  * @class AtomicValue
20  * @brief This class stores the atomic values
21  */
22 
23 
24 #ifndef ATOMICVALUE_H_
25 #define ATOMICVALUE_H_
26 
27 #include <numl/common/extern.h>
28 #include <numl/common/numlfwd.h>
29 
30 
31 #include <numl/Dimension.h>
32 #include <numl/NUMLList.h>
33 #include <numl/NUMLTypes.h>
34 #include <string>
35 #include <sstream>
36 
37 #ifdef __cplusplus
38 LIBNUML_CPP_NAMESPACE_BEGIN
39 
40 class LIBNUML_EXTERN AtomicValue : public Dimension {
41 
42 public:
43 
44 	/**
45 	* Creates an new AtomicValue using the given NUML @p level and @p version
46 	* values.
47 	*
48 	* @param level an unsigned int, the NUML Level to assign to this AtomicValue
49 	*
50 	* @param version an unsigned int, the NUML Version to assign to this
51 	*AtomicValue
52 	*
53 	* @note Once an AtomicValue has been added to an NUMLDocument, the @p level,
54 	* @p version for the document @em override those used
55 	* to create the AtomicValue.  Despite this, the ability to supply the values
56 	* at creation time is an important aid to creating valid NUML.  Knowledge of
57 	* the intented NUML Level and Version determine whether it is valid to
58 	* assign a particular value to an attribute, or whether it is valid to add
59 	* an object to an existing NUMLDocument.
60 	*/
61 	AtomicValue (unsigned int level, unsigned int version);
62 
63 
64 	/**
65 	* Creates a new AtomicValue using the given NUMLNamespaces object
66 	* @p numlns.
67 	*
68 	* The NUMLNamespaces object encapsulates NUML Level/Version/namespaces
69 	* information.  It is used to communicate the NUML Level, Version, and
70 	* (in Level&nbsp;3) packages used in addition to NUML Level&nbsp; Core.
71 	* A common approach to using this class constructor is to create an
72 	* NUMLNamespaces object somewhere in a program, once, then pass it to
73 	* object constructors such as this one when needed.
74 	*
75 	* It is worth emphasizing that although this constructor does not take
76 	* an identifier argument, in NUML Level&nbsp;2 and beyond, the "id"
77 	* (identifier) attribute of an AtomicValue is required to have a value.
78 	* Thus, callers are cautioned to assign a value after calling this
79 	* constructor.  Setting the identifier can be accomplished using the
80 	* method @if clike SBase::setId() @endif@if java SBase::setId(String id) @endif.
81 	*
82 	* @param numlns an NUMLNamespaces object.
83 	*
84 	* @note Once an AtomicValue has been added to an NUMLDocument, the @p level,
85 	* @p version and @p xmlns namespaces for the document @em override those used
86 	* to create the AtomicValue.  Despite this, the ability to supply the values
87 	* at creation time is an important aid to creating valid NUML.  Knowledge of
88 	* the intented NUML Level and Version determine whether it is valid to
89 	* assign a particular value to an attribute, or whether it is valid to add
90 	* an object to an existing NUMLDocument.
91 	*/
92 	AtomicValue (NUMLNamespaces* numlns);
93 
94 	/**
95 	* Accepts the given NUMLVisitor for this instance of AtomicValue.
96 	*
97 	* @param v the NUMLVisitor instance to be used.
98 	*
99 	* @return the result of calling <code>v.visit()</code>.
100 	*/
101 	virtual bool accept (NUMLVisitor& v) const;
102 
103 
104 	/**
105 	* Returns the libNUML type code for this %NUML object.
106 	*
107 	* @if clike LibNUML attaches an identifying code to every
108 	* kind of NUML object.  These are known as <em>NUML type codes</em>.
109 	* The set of possible type codes is defined in the enumeration
110 	* #NUMLTypeCode_t.  The names of the type codes all begin with the
111 	* characters @c NUML_. @endif@if java LibNUML attaches an
112 	* identifying code to every kind of NUML object.  These are known as
113 	* <em>NUML type codes</em>.  In other languages, the set of type codes
114 	* is stored in an enumeration; in the Java language interface for
115 	* libNUML, the type codes are defined as static integer constants in
116 	* interface class {@link libnumlConstants}.  The names of the type codes
117 	* all begin with the characters @c NUML_. @endif
118 	*
119 	* @return the NUML type code for this object, or @c NUML_UNKNOWN (default).
120 	*
121 	* @see getElementName()
122 	*/
123 	virtual NUMLTypeCode_t getTypeCode () const;
124 
125 	/**
126 	* Returns the XML element name of this object, which for AtomicValue, is
127 	* always @c "atomicValue".
128 	*
129 	* @return the name of this element, i.e., @c "atomicValue".
130 	*/
131 	virtual const std::string& getElementName () const;
132 
133 	/**
134 	* Returns the character value in this object.
135 	*
136 	* @return the string value".
137 	*/
138 	virtual const std::string& getValue () const;
139 
140 	/**
141 	* Returns the double value of the character value in this object.
142 	*
143 	* @return the double value of the character value".
144 	*/
145 	virtual double getDoubleValue ();
146 
147 
148 	/**
149 	* Sets the value of the "value" attribute of this NUML object.
150 	*
151 	* The string in @p value is copied.
152 	*
153 	* @param value the new value for the object
154 	*
155 	* @return integer value indicating success/failure of the
156 	* function.
157 	*/
158 	int setValue (const std::string& value);
159 
160 	/**
161 	* Creates and returns a deep copy of this AtomicValue.
162 	*
163 	* @return a (deep) copy of this AtomicValue.
164 	*/
165 
166 	/**
167 	 * Writes (serializes) this NUML object character value by writing it to XMLOutputStream.
168 	 */
169   void writeChars(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream& stream) const;
170 
171 	/**
172 	 * Subclasses should override this method to write out their contained
173 	 * NUML objects as XML elements.  Be sure to call your parents
174 	 * implementation of this method as well.  For example:
175 	 *
176 	 */
177 	//virtual void write(XMLOutputStream& stream) const;
178 
179 //	virtual void write(XMLOutputStream& stream) const;
180 
181 	virtual AtomicValue* clone () const;
182 	AtomicValue();
183 	virtual ~AtomicValue();
184 
185 protected:
186 
187 	/* this is a constructor that takes no arguments and
188 	 * only exists because the validator code needs it
189 	 */
190 	// AtomicValue ();
191 
192 	/**
193 	* Subclasses should override this method to create, store, and then
194 	* return an NUML object corresponding to the next XMLToken in the
195 	* XMLInputStream.
196 	*
197 	* @return the NUML object corresponding to next XMLToken in the
198 	* XMLInputStream or NULL if the token was not recognized.
199 	*/
200 	//virtual NMBase* createObject (XMLInputStream& stream);
201   virtual void readAttributes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes & attributes);
202   virtual void writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const;
203 
204 
205 	std::string  mValue;
206 	//double  mDoubleValue;
207 };
208 
209 LIBNUML_CPP_NAMESPACE_END
210 
211 #endif  /* __cplusplus */
212 #endif /* ATOMICVALUE_H_ */
213