Visualization Library 2.0.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Value.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, 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 <vlX/Value.hpp>
33 
34 using namespace vl;
35 using namespace vlX;
36 
37 //-----------------------------------------------------------------------------
38 void VLXValue::release()
39 {
40  switch(mType)
41  {
42  case Structure:
43  if (mUnion.mStructure)
44  mUnion.mStructure->decReference();
45  break;
46 
47  case List:
48  if (mUnion.mList)
49  mUnion.mList->decReference();
50  break;
51 
52  case RawtextBlock:
53  if (mUnion.mRawtextBlock)
54  mUnion.mRawtextBlock->decReference();
55  break;
56 
57  /*
58  case ArrayString:
59  case ArrayID:
60  case ArrayIdentifier:
61  */
62  case ArrayInteger:
63  case ArrayReal:
64  if (mUnion.mArray)
65  mUnion.mArray->decReference();
66  break;
67 
68  case String:
69  case ID:
70  case Identifier:
71  VL_CHECK(mUnion.mString)
72  delete mUnion.mString;
73  mUnion.mString = NULL;
74  break;
75 
76  default:
77  break;
78  }
79 
80  mType = Integer;
81  mUnion.mInteger = 0;
82 }
83 //-----------------------------------------------------------------------------
84 VLXValue& VLXValue::operator=(const VLXValue& other)
85 {
86  mLineNumber = other.mLineNumber;
87 
88  // must be done first
89  switch(other.mType)
90  {
91  case Structure:
92  if (other.mUnion.mStructure)
93  other.mUnion.mStructure->incReference();
94  break;
95 
96  case List:
97  if (other.mUnion.mList)
98  other.mUnion.mList->incReference();
99  break;
100 
101  case RawtextBlock:
102  if (other.mUnion.mRawtextBlock)
103  other.mUnion.mRawtextBlock->incReference();
104  break;
105 
106  /*
107  case ArrayString:
108  case ArrayID:
109  case ArrayIdentifier:
110  */
111  case ArrayInteger:
112  case ArrayReal:
113  if (other.mUnion.mArray)
114  other.mUnion.mArray->incReference();
115  break;
116 
117  default:
118  break;
119  }
120 
121  // must be done after
122  release();
123 
124  mUnion = other.mUnion;
125  mType = other.mType;
126 
127  // make local copy of the string
128  if (mType == String || mType == Identifier || mType == ID)
129  mUnion.mString = new std::string(*mUnion.mString);
130 
131  return *this;
132 }
133 //-----------------------------------------------------------------------------
134 VLXStructure* VLXValue::setStructure(VLXStructure* obj)
135 {
136  release();
137  mType = Structure;
138  mUnion.mStructure = obj;
139  if (mUnion.mStructure)
140  mUnion.mStructure->incReference();
141  return obj;
142 }
143 //-----------------------------------------------------------------------------
144 VLXList* VLXValue::setList(VLXList* list)
145 {
146  VL_CHECK(list);
147 
148  release();
149  mType = List;
150  mUnion.mList = list;
151  if (mUnion.mList)
152  mUnion.mList->incReference();
153  return list;
154 }
155 //-----------------------------------------------------------------------------
156 VLXRawtextBlock* VLXValue::setRawtextBlock(VLXRawtextBlock* fblock)
157 {
158  VL_CHECK(fblock);
159 
160  release();
161  mType = RawtextBlock;
162  mUnion.mRawtextBlock = fblock;
163  if (mUnion.mRawtextBlock)
164  mUnion.mRawtextBlock->incReference();
165  return fblock;
166 }
167 //-----------------------------------------------------------------------------
168 VLXArrayInteger* VLXValue::setArrayInteger(VLXArrayInteger* arr)
169 {
170  VL_CHECK(arr);
171  release();
172  mType = ArrayInteger;
173  mUnion.mArray = arr;
174  if (mUnion.mArray)
175  mUnion.mArray->incReference();
176  return arr;
177 }
178 //-----------------------------------------------------------------------------
179 VLXArrayReal* VLXValue::setArrayReal(VLXArrayReal* arr)
180 {
181  VL_CHECK(arr);
182  release();
183  mType = ArrayReal;
184  mUnion.mArray = arr;
185  if (mUnion.mArray)
186  mUnion.mArray->incReference();
187  return arr;
188 }
189 //-----------------------------------------------------------------------------
190 /*
191 VLXArrayString* VLXValue::setArrayString(VLXArrayString* arr)
192 {
193  VL_CHECK(arr);
194  release();
195  mType = ArrayString;
196  mUnion.mArray = arr;
197  if (mUnion.mArray)
198  mUnion.mArray->incReference();
199  return arr;
200 }
201 //-----------------------------------------------------------------------------
202 VLXArrayIdentifier* VLXValue::setArrayIdentifier(VLXArrayIdentifier* arr)
203 {
204  VL_CHECK(arr);
205  release();
206  mType = ArrayIdentifier;
207  mUnion.mArray = arr;
208  if (mUnion.mArray)
209  mUnion.mArray->incReference();
210  return arr;
211 }
212 //-----------------------------------------------------------------------------
213 VLXArrayID* VLXValue::setArrayID(VLXArrayID* arr)
214 {
215  VL_CHECK(arr);
216  release();
217  mType = ArrayID;
218  mUnion.mArray = arr;
219  if (mUnion.mArray)
220  mUnion.mArray->incReference();
221  return arr;
222 }
223 */
224 //-----------------------------------------------------------------------------
225 VLXArray* VLXValue::setArray(VLXArray* arr)
226 {
227  if (arr->classType() == VLXArrayInteger::Type())
228  return setArrayInteger(arr->as<VLXArrayInteger>());
229  else
230  if (arr->classType() == VLXArrayReal::Type())
231  return setArrayReal(arr->as<VLXArrayReal>());
232  /*
233  else
234  if (arr->classType() == VLXArrayString::Type())
235  return setArrayString(arr->as<VLXArrayString>());
236  else
237  if (arr->classType() == VLXArrayIdentifier::Type())
238  return setArrayIdentifier(arr->as<VLXArrayIdentifier>());
239  else
240  if (arr->classType() == VLXArrayID::Type())
241  return setArrayID(arr->as<VLXArrayID>());
242  */
243  else
244  {
245  VL_TRAP();
246  return NULL;
247  }
248 }
249 //-----------------------------------------------------------------------------
Wrapper for all VLX value types.
Definition: Value.hpp:240
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
An array of 64 bits floating point numbers, can also have a tag.
Definition: Value.hpp:144
Visualization Library main namespace.
A list of key/VLXValue pairs, can also have a tag.
Definition: Value.hpp:541
#define VL_TRAP()
Definition: checks.hpp:70
A simple sequence of VLXValue objects, can also have a tag.
Definition: Value.hpp:634
T * as()
Casts an Object to the specified class.
Definition: Object.hpp:282
#define NULL
Definition: OpenGLDefs.hpp:81
An array of 64 bits integers, can also have a tag.
Definition: Value.hpp:133
A block of raw text.
Definition: Value.hpp:71
Base class for all arrays of VLX values.
Definition: Value.hpp:95
#define VL_CHECK(expr)
Definition: checks.hpp:73
void incReference() const
Increments the reference count of an object.
Definition: Object.hpp:241