Visualization Library 2.0.0-b3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
VLXValue.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2017, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #include <vlCore/VLXValue.hpp>
33 
34 using namespace vl;
35 
36 //-----------------------------------------------------------------------------
37 void VLXValue::release()
38 {
39  switch(mType)
40  {
41  case Structure:
42  if (mUnion.mStructure)
43  mUnion.mStructure->decReference();
44  break;
45 
46  case List:
47  if (mUnion.mList)
48  mUnion.mList->decReference();
49  break;
50 
51  case RawtextBlock:
52  if (mUnion.mRawtextBlock)
53  mUnion.mRawtextBlock->decReference();
54  break;
55 
56  /*
57  case ArrayString:
58  case ArrayID:
59  case ArrayIdentifier:
60  */
61  case ArrayInteger:
62  case ArrayReal:
63  if (mUnion.mArray)
64  mUnion.mArray->decReference();
65  break;
66 
67  case String:
68  case ID:
69  case Identifier:
70  VL_CHECK(mUnion.mString)
71  delete mUnion.mString;
72  mUnion.mString = NULL;
73  break;
74 
75  default:
76  break;
77  }
78 
79  mType = Integer;
80  mUnion.mInteger = 0;
81 }
82 //-----------------------------------------------------------------------------
83 VLXValue& VLXValue::operator=(const VLXValue& other)
84 {
85  mLineNumber = other.mLineNumber;
86 
87  // must be done first
88  switch(other.mType)
89  {
90  case Structure:
91  if (other.mUnion.mStructure)
92  other.mUnion.mStructure->incReference();
93  break;
94 
95  case List:
96  if (other.mUnion.mList)
97  other.mUnion.mList->incReference();
98  break;
99 
100  case RawtextBlock:
101  if (other.mUnion.mRawtextBlock)
102  other.mUnion.mRawtextBlock->incReference();
103  break;
104 
105  /*
106  case ArrayString:
107  case ArrayID:
108  case ArrayIdentifier:
109  */
110  case ArrayInteger:
111  case ArrayReal:
112  if (other.mUnion.mArray)
113  other.mUnion.mArray->incReference();
114  break;
115 
116  default:
117  break;
118  }
119 
120  // must be done after
121  release();
122 
123  mUnion = other.mUnion;
124  mType = other.mType;
125 
126  // make local copy of the string
127  if (mType == String || mType == Identifier || mType == ID)
128  mUnion.mString = new std::string(*mUnion.mString);
129 
130  return *this;
131 }
132 //-----------------------------------------------------------------------------
134 {
135  release();
136  mType = Structure;
137  mUnion.mStructure = obj;
138  if (mUnion.mStructure)
139  mUnion.mStructure->incReference();
140  return obj;
141 }
142 //-----------------------------------------------------------------------------
144 {
145  VL_CHECK(list);
146 
147  release();
148  mType = List;
149  mUnion.mList = list;
150  if (mUnion.mList)
151  mUnion.mList->incReference();
152  return list;
153 }
154 //-----------------------------------------------------------------------------
156 {
157  VL_CHECK(fblock);
158 
159  release();
160  mType = RawtextBlock;
161  mUnion.mRawtextBlock = fblock;
162  if (mUnion.mRawtextBlock)
163  mUnion.mRawtextBlock->incReference();
164  return fblock;
165 }
166 //-----------------------------------------------------------------------------
168 {
169  VL_CHECK(arr);
170  release();
171  mType = ArrayInteger;
172  mUnion.mArray = arr;
173  if (mUnion.mArray)
174  mUnion.mArray->incReference();
175  return arr;
176 }
177 //-----------------------------------------------------------------------------
179 {
180  VL_CHECK(arr);
181  release();
182  mType = ArrayReal;
183  mUnion.mArray = arr;
184  if (mUnion.mArray)
185  mUnion.mArray->incReference();
186  return arr;
187 }
188 //-----------------------------------------------------------------------------
189 /*
190 VLXArrayString* VLXValue::setArrayString(VLXArrayString* arr)
191 {
192  VL_CHECK(arr);
193  release();
194  mType = ArrayString;
195  mUnion.mArray = arr;
196  if (mUnion.mArray)
197  mUnion.mArray->incReference();
198  return arr;
199 }
200 //-----------------------------------------------------------------------------
201 VLXArrayIdentifier* VLXValue::setArrayIdentifier(VLXArrayIdentifier* arr)
202 {
203  VL_CHECK(arr);
204  release();
205  mType = ArrayIdentifier;
206  mUnion.mArray = arr;
207  if (mUnion.mArray)
208  mUnion.mArray->incReference();
209  return arr;
210 }
211 //-----------------------------------------------------------------------------
212 VLXArrayID* VLXValue::setArrayID(VLXArrayID* arr)
213 {
214  VL_CHECK(arr);
215  release();
216  mType = ArrayID;
217  mUnion.mArray = arr;
218  if (mUnion.mArray)
219  mUnion.mArray->incReference();
220  return arr;
221 }
222 */
223 //-----------------------------------------------------------------------------
225 {
226  if (arr->classType() == VLXArrayInteger::Type())
227  return setArrayInteger(arr->as<VLXArrayInteger>());
228  else
229  if (arr->classType() == VLXArrayReal::Type())
230  return setArrayReal(arr->as<VLXArrayReal>());
231  /*
232  else
233  if (arr->classType() == VLXArrayString::Type())
234  return setArrayString(arr->as<VLXArrayString>());
235  else
236  if (arr->classType() == VLXArrayIdentifier::Type())
237  return setArrayIdentifier(arr->as<VLXArrayIdentifier>());
238  else
239  if (arr->classType() == VLXArrayID::Type())
240  return setArrayID(arr->as<VLXArrayID>());
241  */
242  else
243  {
244  VL_TRAP();
245  return NULL;
246  }
247 }
248 //-----------------------------------------------------------------------------
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
VLCORE_EXPORT VLXStructure * setStructure(VLXStructure *)
Definition: VLXValue.cpp:133
VLCORE_EXPORT VLXList * setList(VLXList *)
Definition: VLXValue.cpp:143
Base class for all arrays of VLX values.
Definition: VLXValue.hpp:94
An array of 64 bits floating point numbers, can also have a tag.
Definition: VLXValue.hpp:143
Visualization Library main namespace.
A block of raw text.
Definition: VLXValue.hpp:70
VLCORE_EXPORT VLXArray * setArray(VLXArray *)
Definition: VLXValue.cpp:224
std::string * mString
Definition: VLXValue.hpp:528
VLCORE_EXPORT VLXArrayReal * setArrayReal(VLXArrayReal *)
Definition: VLXValue.cpp:178
#define VL_TRAP()
Definition: checks.hpp:70
Wrapper for all VLX value types.
Definition: VLXValue.hpp:239
An array of 64 bits integers, can also have a tag.
Definition: VLXValue.hpp:132
T * as()
Casts an Object to the specified class.
Definition: Object.hpp:282
#define NULL
Definition: OpenGLDefs.hpp:81
VLCORE_EXPORT VLXArrayInteger * setArrayInteger(VLXArrayInteger *)
Definition: VLXValue.cpp:167
A simple sequence of VLXValue objects, can also have a tag.
Definition: VLXValue.hpp:633
VLCORE_EXPORT VLXRawtextBlock * setRawtextBlock(VLXRawtextBlock *)
Definition: VLXValue.cpp:155
A list of key/VLXValue pairs, can also have a tag.
Definition: VLXValue.hpp:540
#define VL_CHECK(expr)
Definition: checks.hpp:73
long long mInteger
Definition: VLXValue.hpp:526