| GL Studio C++ Runtime API

gls_metadata_attributes.h
Go to the documentation of this file.
1/*! \file
2 \brief Defines templated metadata classes for DisplayObjects and other uses.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38
39*/
40#ifndef INCLUDED_GLS_METADATA_ATTRIBUTES_H
41#define INCLUDED_GLS_METADATA_ATTRIBUTES_H
42
43#include "display.h"
44#include "disti_metadata.h"
45#include "dynamic_array.h"
46#include "gls_include.h"
47#include "list.h"
48#include "material.h"
49#include "util.h"
50#include "vertex.h"
51
52#include <cassert>
53#include <climits>
54#include <cstdarg>
55#include <cstdio>
56#include <cstdlib>
57#include <cstring>
58#include <locale>
59#include <sstream>
60#ifdef __VXWORKS__
61# include <ctype.h>
62#else
63# include <cctype>
64#endif
65
66#ifdef DISTI_HAS_CPP11
67# include <functional>
68#endif
69
70 namespace disti
71{
72 const DistiAttributeBase::CallbackID DISTI_INVALID_CALLBACK_ID = ~0u; ///< Value to represent that a given callback was not successfully created.
73
74/// Helper function used to remove converting int to bool performance warning on certain compilers.
75/// \param value The value to convert.
76/// \return The implictly converted value.
77 template<class T>
78T ConvertToIntOrBool( int value )
79{
80 return static_cast<T>( value );
81}
82
83/// Helper function used to remove converting int to bool performance warning on certain compilers.
84/// \param value The value to convert.
85/// \return The implictly converted value.
86 template<>
87 inline bool ConvertToIntOrBool( int value )
88{
89 return value != 0;
90}
91
92/// Helper function used to convert string TRUE/FALSE/1/0 value into an appropriate boolean.
93/// \param instr The stream to read a boolean string from.
94/// \return The converted string value as a boolean.
95 template<class T>
96T ReadValueAsIntOrBool( std::istream& instr )
97{
98 std::string value;
99 instr >> value;
100 T temp;
101 if( strcasecmp( value.c_str(), "TRUE" ) == 0 )
102 {
103 temp = true;
104 }
105 else if( strcasecmp( value.c_str(), "FALSE" ) == 0 )
106 {
107 temp = false;
108 }
109 else
110 {
111 // Check based on an integer value
112 temp = ConvertToIntOrBool<T>( atoi( value.c_str() ) );
113 }
114 return temp;
115}
116
117/// \cond INTERNAL
118// Force the attribute classes to be instantiated
119// so that they will be exported from the dll
120// NOTE: These are not necessary if the class is instantiated or specialized elsewhere - BB
121//template class DistiAttribute<unsigned char>;
122
123// DistiAttribute<bool> Specialization
124 template<>
125 inline long DistiAttribute<bool>::ValueInt() { return (long)*_attribPtr; }
126 template<>
127 inline void DistiAttribute<bool>::ValueInt( long val )
128{
129 *_attribPtr = ( val != 0 );
130 CallCallback();
131}
132
133 template<>
134 inline std::ostream& DistiAttribute<bool>::WriteValue( std::ostream& outstr )
135{
136 outstr << *_attribPtr;
137
138 return outstr;
139}
140
141 template<>
142 inline std::istream& DistiAttribute<bool>::ReadValue( std::istream& instr )
143{
144 *_attribPtr = ReadValueAsIntOrBool<bool>( instr );
145 CallCallback();
146 return instr;
147}
148
149// DistiAttribute<int> Specialization
150 template<>
151 inline long DistiAttribute<int>::ValueInt() { return (long)*_attribPtr; }
152 template<>
153 inline void DistiAttribute<int>::ValueInt( long val )
154{
155 *_attribPtr = (int)val;
156 CallCallback();
157}
158
159// DistiAttribute<short> Specialization
160 template<>
161 inline long DistiAttribute<short>::ValueInt() { return (long)*_attribPtr; }
162 template<>
163 inline void DistiAttribute<short>::ValueInt( long val )
164{
165 *_attribPtr = (short)val;
166 CallCallback();
167}
168
169// DistiAttribute<unsigned short> Specialization
170 template<>
171 inline long DistiAttribute<unsigned short>::ValueInt() { return (long)*_attribPtr; }
172 template<>
173 inline void DistiAttribute<unsigned short>::ValueInt( long val )
174{
175 *_attribPtr = (unsigned short)val;
176 CallCallback();
177}
178
179// DistiAttribute<unsigned char> Specialization
180 template<>
181 inline long DistiAttribute<unsigned char>::ValueInt() { return (long)*_attribPtr; }
182 template<>
183 inline void DistiAttribute<unsigned char>::ValueInt( long val )
184{
185 *_attribPtr = (unsigned char)val;
186 CallCallback();
187}
188
189 template<>
190 inline std::ostream& DistiAttribute<unsigned char>::WriteValue( std::ostream& outstr )
191{
192 // If we don't cast to int, an actual character will be written. We want a number.
193 outstr << (int)*_attribPtr;
194 return outstr;
195}
196
197 template<>
198 inline std::istream& DistiAttribute<unsigned char>::ReadValue( std::istream& instr )
199{
200 // If we don't cast to int, an actual character will be read. We want a number.
201 // Also, integer types should be able to read as TRUE or FALSE to preserve backwards compatibility for certain attributes (formerly handled by DistiAttributeUCharOrBool)
202 *_attribPtr = static_cast<unsigned char>( ReadValueAsIntOrBool<int>( instr ) );
203 CallCallback();
204 return instr;
205}
206
207 template<>
208 inline std::istream& DistiAttribute<int>::ReadValue( std::istream& instr )
209{
210 // integer types should be able to read as TRUE or FALSE to preserve backwards compatibility for certain attributes (formerly handled by DistiAttributeUCharOrBool)
211 *_attribPtr = ReadValueAsIntOrBool<int>( instr );
212 CallCallback();
213 return instr;
214}
215
216 template<>
217 inline std::istream& DistiAttribute<unsigned int>::ReadValue( std::istream& instr )
218{
219 // integer types should be able to read as TRUE or FALSE to preserve backwards compatibility for certain attributes (formerly handled by DistiAttributeUCharOrBool)
220 *_attribPtr = ReadValueAsIntOrBool<unsigned int>( instr );
221 CallCallback();
222 return instr;
223}
224
225// DistiAttribute<float> Specialization
226 template<>
227 inline long DistiAttribute<float>::ValueInt() { return (long)*_attribPtr; }
228
229 template<>
230 inline void DistiAttribute<float>::ValueInt( long val )
231{
232 *_attribPtr = (float)val;
233 CallCallback();
234}
235/// \endcond
236
237/** Special case for transitioning from a bool to an int
238 * Reads True or False, or integers.
239 * Writes only integers.
240 */
241 class DistiAttributeUCharOrBool : public DistiAttribute<unsigned char>
242{
243 public:
244 /// Constructor, uses existing storage.
245 /// \param callback The callback function pointer to call back.
246 /// \param name The name of this new attribute.
247 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
248 GLS_EXPORT DistiAttributeUCharOrBool( CallbackMethodCallerBase* callback, const AttributeName& name, unsigned char* attribPtr );
249
250 /// Constructor, creates local storage.
251 /// \param callback The callback function pointer to call back.
252 /// \param name The name of this new attribute.
253 /// \param value The initial value for this attribute.
254 GLS_EXPORT DistiAttributeUCharOrBool( CallbackMethodCallerBase* callback, const AttributeName& name, unsigned char value );
255
256 virtual GLS_EXPORT DistiAttributeBase& operator=( const DistiAttributeBase& oldClass ) DISTI_METHOD_OVERRIDE;
257
258 virtual GLS_EXPORT long ValueInt() DISTI_METHOD_OVERRIDE;
259 virtual GLS_EXPORT void ValueInt( long val ) DISTI_METHOD_OVERRIDE;
260
261 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
262 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
263};
264
265/** For fixed length float arrays
266 */
267class DistiAttributeFloatArray : public DistiAttributeBase
268{
269 float* _array; ///< An observing pointer to the underlying array storage.
270 int _length; ///< The length of the array in elements.
271
272 public:
273 /// Constructor, uses existing storage.
274 /// \param callback The callback function pointer to call back.
275 /// \param name The name of this new attribute.
276 /// \param floatArray The underlying storage for the array.
277 /// \param length The number of items in the array.
278 GLS_EXPORT DistiAttributeFloatArray( CallbackMethodCallerBase* callback, const AttributeName& name, float* floatArray, int length );
279
280 virtual GLS_EXPORT ~DistiAttributeFloatArray();
281
282 virtual GLS_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE;
283
284 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
285 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
286
287 GLS_EXPORT std::string Type() const DISTI_METHOD_OVERRIDE;
288};
289
290/** For fixed length double arrays
291 */
292class DistiAttributeDoubleArray : public DistiAttributeBase
293{
294 double* _array; ///< An observing pointer to the underlying array storage.
295 int _length; ///< The length of the array in elements.
296
297 public:
298 /// Constructor, uses existing storage.
299 /// \param callback The callback function pointer to call back.
300 /// \param name The name of this new attribute.
301 /// \param doubleArray The underlying storage for the array.
302 /// \param length The number of items in the array.
303 GLS_EXPORT DistiAttributeDoubleArray( CallbackMethodCallerBase* callback, const AttributeName& name, double* doubleArray, int length );
304
305 virtual GLS_EXPORT ~DistiAttributeDoubleArray();
306
307 virtual GLS_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE;
308
309 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
310 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
311
312 GLS_EXPORT std::string Type() const DISTI_METHOD_OVERRIDE;
313};
314
315/** An enumeration for Texture Mode */
316static DistiAttributeEnumDefList TextureModeEnumList(
317 (char*)"TEXTURE_MAP_MODULATE", TEXTURE_MAP_MODULATE,
318 (char*)"TEXTURE_MAP_DECAL", TEXTURE_MAP_DECAL,
319 (char*)"TEXTURE_MAP_BLEND", TEXTURE_MAP_BLEND,
320 (char*)"TEXTURE_MAP_REPLACE", TEXTURE_MAP_REPLACE,
321 NULL );
322
323/** Disti Attribute Texture Mode Enum */
324template<class containerClass>
325class DistiAttributeTextureModeEnum : public DistiAttributeEnum<containerClass, const int, int>
326{
327 public:
328 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
329 typedef DistiAttributeEnum<containerClass, const int, int> _BaseClass; ///< Deprecated typedef for the base class.
330 typedef DistiAttributeEnum<containerClass, const int, int> BaseClass; ///< Typedef for the base class.
331 using BaseClass::_pairList;
332
333 typedef void ( containerClass::*SetMethodType )( const int ); ///< Typedef for the set method function pointer.
334 typedef int ( containerClass::*GetMethodType )(); ///< Typedef for the get method function pointer.
335
336 /// Constructor
337 /// \param frame The object containing the set and get methods.
338 /// \param setMethod The set method function pointer.
339 /// \param getMethod The get method function pointer.
340 /// \param name The name of this new attribute.
341 DistiAttributeTextureModeEnum<containerClass>( containerClass* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name )
342 : DistiAttributeEnum<containerClass, const int, int>( frame, setMethod, getMethod, name )
343 {
344 _pairList = &TextureModeEnumList;
345 }
346
347 std::string Type() const DISTI_METHOD_OVERRIDE
348 {
349 return Demangle<TextureMap_e>();
350 }
351};
352
353/** An enumeration for Texture Filter */
354 static DistiAttributeEnumDefList TextureFilterEnumList(
355 (char*)"TEXTURE_FILTER_NEAREST", TEXTURE_FILTER_NEAREST,
356 (char*)"TEXTURE_FILTER_LINEAR", TEXTURE_FILTER_LINEAR,
357 (char*)"TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST", TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST,
358 (char*)"TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR", TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR,
359 (char*)"TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR", TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR,
360 (char*)"TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST", TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST,
361 NULL );
362
363/** Disti Attribute Texture Filter Enum */
364 template<class containerClass>
365 class DistiAttributeTextureFilterEnum : public DistiAttributeEnum<containerClass, const int, int>
366{
367 public:
368 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
369 typedef DistiAttributeEnum<containerClass, const int, int> _BaseClass; ///< Deprecated typedef for the base class.
370 typedef DistiAttributeEnum<containerClass, const int, int> BaseClass; ///< Typedef for the base class.
371 using BaseClass::_pairList;
372
373 typedef void ( containerClass::*SetMethodType )( const int ); ///< Typedef for the set method function pointer.
374 typedef int ( containerClass::*GetMethodType )(); ///< Typedef for the get method function pointer.
375
376 /// Constructor
377 /// \param frame The object containing the set and get methods.
378 /// \param setMethod The set method function pointer.
379 /// \param getMethod The get method function pointer.
380 /// \param name The name of this new attribute.
381 DistiAttributeTextureFilterEnum<containerClass>( containerClass* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name )
382 : DistiAttributeEnum<containerClass, const int, int>( frame, setMethod, getMethod, name )
383 {
384 _pairList = &TextureFilterEnumList;
385 }
386
387 std::string Type() const DISTI_METHOD_OVERRIDE
388 {
389 return Demangle<TextureFilter_e>();
390 }
391};
392
393/** An enumeration for Polygon Mode */
394 static DistiAttributeEnumDefList PolyModeEnumList(
395 (char*)"POLY_MODE_UNDEFINED", POLY_MODE_UNDEFINED,
396 (char*)"POLY_MODE_POINTS", POLY_MODE_POINTS,
397 (char*)"POLY_MODE_OUTLINE", POLY_MODE_OUTLINE,
398 (char*)"POLY_MODE_FILLED", POLY_MODE_FILLED,
399 (char*)"POLY_MODE_FILL_AND_OUTLINE", POLY_MODE_FILL_AND_OUTLINE,
400 NULL );
401
402/** Disti Attribute Poly Mode Enum */
403 template<class containerClass>
404 class DistiAttributePolyModeEnum : public DistiAttributeEnum<containerClass, const int, int>
405{
406 public:
407 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
408 typedef DistiAttributeEnum<containerClass, const int, int> _BaseClass; ///< Deprecated typedef for the base class.
409 typedef DistiAttributeEnum<containerClass, const int, int> BaseClass; ///< Typedef for the base class.
410 using BaseClass::_pairList;
411
412 typedef void ( containerClass::*SetMethodType )( const int ); ///< Typedef for the set method function pointer.
413 typedef int ( containerClass::*GetMethodType )(); ///< Typedef for the get method function pointer.
414
415 /// Constructor
416 /// \param frame The object containing the set and get methods.
417 /// \param setMethod The set method function pointer.
418 /// \param getMethod The get method function pointer.
419 /// \param name The name of this new attribute.
420 DistiAttributePolyModeEnum<containerClass>( containerClass* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name )
421 : DistiAttributeEnum<containerClass, const int, int>( frame, setMethod, getMethod, name )
422 {
423 _pairList = &PolyModeEnumList;
424 }
425
426 std::string Type() const DISTI_METHOD_OVERRIDE
427 {
428 return Demangle<PolygonMode_e>();
429 }
430};
431
432/** An enumeration for Polygon End Mode */
433 static DistiAttributeEnumDefList PolyEndEnumList(
434 (char*)"POLY_OPEN", POLY_OPEN,
435 (char*)"POLY_CLOSED", POLY_CLOSED,
436 NULL );
437
438/** Disti Attribute Poly End Enum */
439 template<class containerClass>
440 class DistiAttributePolyEndEnum : public DistiAttributeEnum<containerClass, int, int>
441{
442 public:
443 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
444 typedef DistiAttributeEnum<containerClass, int, int> _BaseClass; ///< Deprecated typedef for the base class.
445 typedef DistiAttributeEnum<containerClass, int, int> BaseClass; ///< Typedef for the base class.
446 using BaseClass::_pairList;
447
448 typedef void ( containerClass::*SetMethodType )( int ); ///< Typedef for the set method function pointer.
449 typedef int ( containerClass::*GetMethodType )(); ///< Typedef for the get method function pointer.
450
451 /// Constructor
452 /// \param frame The object containing the set and get methods.
453 /// \param setMethod The set method function pointer.
454 /// \param getMethod The get method function pointer.
455 /// \param name The name of this new attribute.
456 DistiAttributePolyEndEnum<containerClass>( containerClass* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name )
457 : DistiAttributeEnum<containerClass, int, int>( frame, setMethod, getMethod, name )
458 {
459 _pairList = &PolyEndEnumList;
460 }
461
462 std::string Type() const DISTI_METHOD_OVERRIDE
463 {
464 return Demangle<PolygonClose_e>();
465 }
466};
467
468/** An enumeration for Shading enum */
469 static DistiAttributeEnumDefList ShadingEnumList(
470 (char*)"FLAT", SHADING_FLAT,
471 (char*)"GOURAUD", SHADING_GOURAUD,
472 NULL );
473
474/** Disti Attribute Shading Enum */
475 template<class containerClass>
476 class DistiAttributeShadingEnum : public DistiAttributeEnum<containerClass, const int, int>
477{
478 public:
479 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
480 typedef DistiAttributeEnum<containerClass, const int, int> _BaseClass; ///< Deprecated typedef for the base class.
481 typedef DistiAttributeEnum<containerClass, const int, int> BaseClass; ///< Typedef for the base class.
482 using BaseClass::_pairList;
483
484 typedef void ( containerClass::*SetMethodType )( const int ); ///< Typedef for the set method function pointer.
485 typedef int ( containerClass::*GetMethodType )(); ///< Typedef for the get method function pointer.
486
487 /// Constructor
488 /// \param frame The object containing the set and get methods.
489 /// \param setMethod The set method function pointer.
490 /// \param getMethod The get method function pointer.
491 /// \param name The name of this new attribute.
492 DistiAttributeShadingEnum<containerClass>( containerClass* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name )
493 : DistiAttributeEnum<containerClass, const int, int>( frame, setMethod, getMethod, name )
494 {
495 _pairList = &ShadingEnumList;
496 }
497
498 std::string Type() const DISTI_METHOD_OVERRIDE
499 {
500 return Demangle<ShadingType_e>();
501 }
502};
503
504/** An enumeration for ColorMaterialMode enum */
505 template<class containerClass>
506 class DistiAttributeColorMaterialModeEnum : public DistiAttributeEnum<containerClass, const int, int>
507{
508 public:
509 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
510 typedef DistiAttributeEnum<containerClass, const int, int> _BaseClass; ///< Deprecated typedef for the base class.
511 typedef DistiAttributeEnum<containerClass, const int, int> BaseClass; ///< Typedef for the base class.
512 using BaseClass::_pairList;
513
514 typedef void ( containerClass::*SetMethodType )( const int ); ///< Typedef for the set method function pointer.
515 typedef int ( containerClass::*GetMethodType )(); ///< Typedef for the get method function pointer.
516
517 /// Constructor
518 /// \param frame The object containing the set and get methods.
519 /// \param setMethod The set method function pointer.
520 /// \param getMethod The get method function pointer.
521 /// \param name The name of this new attribute.
522 DistiAttributeColorMaterialModeEnum<containerClass>( containerClass* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name )
523 : DistiAttributeEnum<containerClass, const int, int>( frame, setMethod, getMethod, name )
524 {
525 static DistiAttributeEnumDefList ColorMaterialModeEnum(
526 (char*)"NO_COLOR_MATERIAL", NO_COLOR_MATERIAL,
527 (char*)"DIFFUSE_COLOR_MATERIAL", DIFFUSE_COLOR_MATERIAL,
528 (char*)"AMBIENT_COLOR_MATERIAL", AMBIENT_COLOR_MATERIAL,
529 (char*)"DIFFUSE_AND_AMBIENT_COLOR_MATERIAL", DIFFUSE_AND_AMBIENT_COLOR_MATERIAL,
530 (char*)"EMISSION_COLOR_MATERIAL", EMISSION_COLOR_MATERIAL,
531 (char*)"SPECULAR_COLOR_MATERIAL", SPECULAR_COLOR_MATERIAL,
532 NULL );
533
534 _pairList = &ColorMaterialModeEnum;
535 }
536
537 virtual GLS_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE { return false; }
538
539 std::string Type() const DISTI_METHOD_OVERRIDE
540 {
541 return Demangle<ColorMaterialMode_e>();
542 }
543};
544
545/** An enumeration for Protection */
546 template<class containerClass>
547 class DistiAttributeProtectionEnum : public DistiAttributeEnum<containerClass, const int, int>
548{
549 public:
550 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
551 typedef DistiAttributeEnum<containerClass, const int, int> _BaseClass; ///< Deprecated typedef for the base class.
552 typedef DistiAttributeEnum<containerClass, const int, int> BaseClass; ///< Typedef for the base class.
553 using BaseClass::_pairList;
554
555 typedef void ( containerClass::*SetMethodType )( const int ); ///< Typedef for the set method function pointer.
556 typedef int ( containerClass::*GetMethodType )(); ///< Typedef for the get method function pointer.
557
558 /// Constructor
559 /// \param frame The object containing the set and get methods.
560 /// \param setMethod The set method function pointer.
561 /// \param getMethod The get method function pointer.
562 /// \param name The name of this new attribute.
563 DistiAttributeProtectionEnum<containerClass>( containerClass* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name )
564 : DistiAttributeEnum<containerClass, const int, int>( frame, setMethod, getMethod, name )
565 {
566 static DistiAttributeEnumDefList ProtectionEnumList(
567 (char*)"PUBLIC", PUBLIC,
568 (char*)"PRIVATE", PRIVATE,
569 (char*)"PROTECTED", PROTECTED,
570 NULL );
571 _pairList = &ProtectionEnumList;
572 }
573
574 std::string Type() const DISTI_METHOD_OVERRIDE
575 {
576 return Demangle<MemberAccess_e>();
577 }
578};
579
580/** An enumeration for Alpha Mode */
581 static DistiAttributeEnumDefList AlphaModeEnumList(
582 (char*)"ALPHA_MODE_UNDEFINED", ALPHA_MODE_UNDEFINED,
583 (char*)"ALPHA_MODE_OPAQUE", ALPHA_MODE_OPAQUE,
584 (char*)"ALPHA_MODE_2_LEVEL", ALPHA_MODE_2_LEVEL,
585 (char*)"ALPHA_MODE_256_LEVEL", ALPHA_MODE_256_LEVEL,
586 NULL );
587
588/// \details The DistiAttributeAlphaModeEnum class.
589 template<class containerClass>
590 class DistiAttributeAlphaModeEnum : public DistiAttributeEnum<containerClass, const int, int>
591{
592 public:
593 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
594 typedef DistiAttributeEnum<containerClass, const int, int> _BaseClass; ///< Deprecated typedef for the base class.
595 typedef DistiAttributeEnum<containerClass, const int, int> BaseClass; ///< Typedef for the base class.
596 using BaseClass::_pairList;
597
598 typedef void ( containerClass::*SetMethodType )( const int ); ///< Typedef for the set method function pointer.
599 typedef int ( containerClass::*GetMethodType )(); ///< Typedef for the get method function pointer.
600
601 /// Constructor
602 /// \param frame Object containing the set and get methods.
603 /// \param setMethod The set method function pointer to call.
604 /// \param getMethod The get method function pointer to call.
605 /// \param name The name of this new attribute.
606 DistiAttributeAlphaModeEnum<containerClass>( containerClass* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name )
607 : DistiAttributeEnum<containerClass, const int, int>( frame, setMethod, getMethod, name )
608 {
609 _pairList = &AlphaModeEnumList;
610 }
611
612 std::string Type() const DISTI_METHOD_OVERRIDE
613 {
614 return Demangle<AlphaMode_e>();
615 }
616};
617
618/** An attribute for a char* string
619 */
620 class DistiAttributeString : public DistiAttributeBase
621{
622 char* _local; ///< The underlying string storage for this attribute.
623
624 protected:
625 char** _attribPtr; ///< A pointer to the pointer containing the underlying storage for this attribute.
626
627 public:
628 /// This constructor makes the bold assumption that it can modify the contents.
629 /// of the supplied char*, by realocating the memory.
630 /// \param callback The callback function pointer to call.
631 /// \param name The name of this new attribute.
632 /// \param attribPtr A pointer to the pointer containing the original string value.
633 GLS_EXPORT DistiAttributeString( CallbackMethodCallerBase* callback, const AttributeName& name, char** attribPtr );
634
635 /// Creates local storage, and will resize as needed.
636 /// \param callback The callback function pointer to call.
637 /// \param name The name of this new attribute.
638 /// \param initialValue The initial string value.
639 GLS_EXPORT DistiAttributeString( CallbackMethodCallerBase* callback, const AttributeName& name, char* initialValue );
640
641 virtual GLS_EXPORT ~DistiAttributeString();
642
643 /// \return The underlying string storage for this attribute.
644 /// \note Be careful with this.
645 GLS_EXPORT char* LocalStorageString();
646
647 virtual GLS_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE;
648
649 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
650 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
651
652 GLS_EXPORT std::string Type() const DISTI_METHOD_OVERRIDE;
653};
654
655/** Derived from DistiAttributeString, the only difference is that it
656 * reads and writes encoded strings instead of clear strings.
657 */
658class DistiAttributeEncodedString : public DistiAttributeString
659{
660 public:
661 /// Constructor, uses existing storage.
662 /// \param callback The callback function pointer to call back.
663 /// \param name The name of this new attribute.
664 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
665 GLS_EXPORT DistiAttributeEncodedString( CallbackMethodCallerBase* callback, const AttributeName& name, char** attribPtr );
666
667 /// Constructor, creates local storage, and will resize as needed.
668 /// \param callback The callback function pointer to call back.
669 /// \param name The name of this new attribute.
670 /// \param initialValue The initial string value for this attribute.
671 GLS_EXPORT DistiAttributeEncodedString( CallbackMethodCallerBase* callback, const AttributeName& name, char* initialValue );
672
673 // Normally ValueString just returns the value of WriteValue, but for encoded strings
674 // this is probably not what we want, so have ValueString work with the unencoded string
675 virtual GLS_EXPORT std::string ValueString() DISTI_METHOD_OVERRIDE;
676 virtual GLS_EXPORT void ValueString( const std::string& s ) DISTI_METHOD_OVERRIDE;
677
678 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
679 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
680};
681
682/** Derived from DistiAttributeStdString, the only difference is that it
683 * reads and writes encoded strings instead of clear strings.
684 */
685class DistiAttributeEncodedStdString : public DistiAttribute<std::string>
686{
687 public:
688 /// Constructor, uses existing storage.
689 /// \param callback The callback function pointer to call back.
690 /// \param name The name of this new attribute.
691 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
692 GLS_EXPORT DistiAttributeEncodedStdString( CallbackMethodCallerBase* callback, const AttributeName& name, std::string* attribPtr );
693
694 /// Constructor, creates local storage, and will resize as needed.
695 /// \param callback The callback function pointer to call back.
696 /// \param name The name of this new attribute.
697 /// \param initialValue The initial string value for this attribute.
698 GLS_EXPORT DistiAttributeEncodedStdString( CallbackMethodCallerBase* callback, const AttributeName& name, std::string initialValue );
699
700 GLS_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE;
701
702 // Normally ValueString just returns the value of WriteValue, but for encoded strings
703 // this is probably not what we want, so have ValueString work with the unencoded string
704 GLS_EXPORT std::string ValueString() DISTI_METHOD_OVERRIDE;
705 GLS_EXPORT void ValueString( const std::string& s ) DISTI_METHOD_OVERRIDE;
706
707 GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
708 GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
709};
710
711/** For fixed length char array */
712class DistiAttributeFixedString : public DistiAttributeBase
713{
714 char* _string; ///< Underlying storage for the string.
715 int _length; ///< Length of the underlying string storage in bytes.
716
717 public:
718 /// Constructor
719 /// \param callback The callback function pointer to call back.
720 /// \param name The name of this new attribute.
721 /// \param string The initial string value for this attribute.
722 /// \param length The length of the string in bytes.
723 GLS_EXPORT DistiAttributeFixedString( CallbackMethodCallerBase* callback, const AttributeName& name, char* string, int length );
724
725 virtual GLS_EXPORT ~DistiAttributeFixedString();
726
727 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
728 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
729};
730
731/** Attribute for std::string */
732 class DistiAttributeStdString : public DistiAttribute<std::string>
733{
734 std::string _localStorageString; ///< Underlying storage for the string.
735
736 public:
737 /// Constructor, uses existing storage.
738 /// \param callback The callback function pointer to call back.
739 /// \param name The name of this new attribute.
740 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
741 GLS_EXPORT DistiAttributeStdString( CallbackMethodCallerBase* callback, const AttributeName& name, std::string* attribPtr );
742
743 /// Constructor, creates local storage, and will resize as needed.
744 /// \param callback The callback function pointer to call back.
745 /// \param name The name of this new attribute.
746 /// \param initialValue The initial string value for this attribute.
747 GLS_EXPORT DistiAttributeStdString( CallbackMethodCallerBase* callback, const AttributeName& name, std::string initialValue );
748
749 virtual GLS_EXPORT ~DistiAttributeStdString();
750
751 /// \return A pointer to the underlying string storage.
752 /// \note Be careful with this.
753 GLS_EXPORT std::string* LocalStorageString();
754
755 virtual GLS_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE;
756
757 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
758 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
759};
760
761/** Attribute for Location */
762class DistiAttributeLocation : public DistiAttribute<Vertex>
763{
764 public:
765 /// Constructor, uses existing storage.
766 /// \param callback The callback function pointer to call back.
767 /// \param name The name of this new attribute.
768 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
769 GLS_EXPORT DistiAttributeLocation( CallbackMethodCallerBase* callback, const AttributeName& name, Vertex* attribPtr );
770
771 virtual GLS_EXPORT ~DistiAttributeLocation();
772
773 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
774 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
775};
776
777/** Attribute for a dictionary of attributes */
778 class DistiAttributeDictionaryAttribute : public DistiAttributeBase
779{
780 protected:
781 DistiAttribDict* _dict; ///< An observing pointer to a dictionary of attributes.
782
783 public:
784 /// Constructor
785 /// \param name The name of this new attribute.
786 /// \param dict The attribute dictionary this attribute will point to.
787 GLS_EXPORT DistiAttributeDictionaryAttribute( const AttributeName& name, DistiAttribDict* dict );
788
789 virtual GLS_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE;
790
791 /// Add a new attribute to this property's dictionary.
792 /// \param attr The attribute to add.
793 virtual void Add( DistiAttributeBase* attr ) { _dict->Add( attr ); }
794
795 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
796 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
797
798 GLS_EXPORT std::string Type() const DISTI_METHOD_OVERRIDE;
799};
800
801/** Attribute for a dictionary of attributes that cares for its siblings */
802class DistiAttributeDictionaryAttributeSibling : public DistiAttributeBase
803{
804 protected:
805 DistiAttribDict* _dict; ///< An observing pointer to a dictionary of attributes.
806 DistiAttributeBase* _sibling; ///< An observing pointer to this attribute's sibling.
807 bool _hasRead; ///< If true, ReadValue will be called on the sibling when ReadValue is called on this attribute.
808
809 public:
810 /// Constructor
811 /// \param name The name of this new attribute.
812 /// \param dict The attribute dictionary this attribute will point to.
813 /// \param sibling The sibling attribute for this attribute.
814 GLS_EXPORT DistiAttributeDictionaryAttributeSibling( const AttributeName& name, DistiAttribDict* dict, DistiAttributeBase* sibling );
815
816 virtual GLS_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE;
817
818 /// Add a new attribute to this property's dictionary.
819 /// \param attr The attribute to add.
820 virtual void Add( DistiAttributeBase* attr ) { _dict->Add( attr ); }
821
822 virtual GLS_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
823 virtual GLS_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
824
825 GLS_EXPORT std::string Type() const DISTI_METHOD_OVERRIDE;
826};
827
828//----------------------------------------------------------------------------
829//----------------------------------------------------------------------------
830/** \class DistiAttributeStdMap
831 * An attribute for a std::map
832 */
833template<class Map_t>
834class DistiAttributeStdMap : public DistiAttributeBase
835{
836 Map_t* _attribPtr; ///< Storage for the underlying std::map type.
837
838 public:
839 /// Constructor, from existing storage.
840 /// \param callback The callback method function pointer to call back.
841 /// \param name The name of this new attribute.
842 /// \param attribPtr A pointer to existing storage for this attribute.
843 DistiAttributeStdMap(
844 CallbackMethodCallerBase* callback, const AttributeName& name, Map_t* attribPtr )
845 : DistiAttributeBase( callback, name, false )
846 , _attribPtr( attribPtr )
847 {
848 }
849
850 /// Constructor, creates local storage, and will resize as needed.
851 /// \param callback The callback method function pointer to call back.
852 /// \param name The name of this new attribute.
853 DistiAttributeStdMap( CallbackMethodCallerBase* callback, const AttributeName& name )
854 : DistiAttributeBase( callback, name, true )
855 , _attribPtr( new Map_t() )
856 {
857 }
858
859 virtual ~DistiAttributeStdMap()
860 {
861 if( _localStorage )
862 delete _attribPtr;
863 _attribPtr = NULL;
864 }
865
866 virtual bool OkToWrite() const DISTI_METHOD_OVERRIDE
867 {
868 return _attribPtr != 0 && _attribPtr->size();
869 }
870
871 /// \return A special value that identifies this attribute as being empty.
872 static std::string GetEmptyValue() { return "$$DISTI_EMPTY$$"; }
873
874 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
875 {
876 outstr << "\n"
877 << DistiAttribDict::SpacingString() << "{\n";
878 DistiAttribDict::SpacingInc();
879
880 if( _attribPtr )
881 {
882 typename Map_t::iterator i;
883 for( i = _attribPtr->begin(); i != _attribPtr->end(); ++i )
884 {
885 std::ostringstream str;
886 str << i->second;
887 const std::string second = str.str();
888
889 outstr << DistiAttribDict::SpacingString() << i->first << " "
890 << ( second.empty() ? GetEmptyValue() : second ) << '\n';
891 }
892 }
893
894 DistiAttribDict::SpacingDec();
895 outstr << DistiAttribDict::SpacingString() << "}\n";
896
897 return outstr;
898 }
899
900#if defined( _MSC_VER )
901# pragma warning( push )
902# pragma warning( disable : 4701 ) // GLS-11071
903#endif
904 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
905 {
906 instr.ignore( INT_MAX, '{' );
907
908 if( instr.good() )
909 {
910 std::stringstream fontStream;
911 instr.get( *fontStream.rdbuf(), '}' );
912 if( instr.good() )
913 {
914 instr.ignore( 1 );
915 while( fontStream.good() )
916 {
917 // Get rid of all the leading white space before reading the key
918#ifdef _WIN32
919 std::stringstream::char_type c;
920#else
921 // std::stringstream::char_type c; causes a parse error before `;' on Linux
922 char c;
923#endif
924 do
925 {
926 fontStream.get( c );
927#ifdef _WIN32
928 } while( fontStream.good() && std::isspace( c ) );
929#else
930 } while( fontStream.good() && isspace( c ) );
931#endif
932
933 if( fontStream.good() )
934 {
935 fontStream.putback( c );
936
937 typename Map_t::key_type key;
938 typename Map_t::mapped_type value;
939
940 std::string strVal;
941 fontStream >> key;
942 std::getline( fontStream >> std::ws, strVal );
943
944 if( strVal != GetEmptyValue() )
945 {
946 std::istringstream str( strVal );
947 str >> value;
948 }
949
950 ( *_attribPtr )[ key ] = value;
951 }
952 }
953 }
954 }
955 return instr;
956 }
957
958 std::string Type() const DISTI_METHOD_OVERRIDE
959 {
960 return Demangle<Map_t>();
961 }
962
963#if defined( _MSC_VER )
964# pragma warning( pop )
965#endif
966}; // end DistiAttributeStdMap
967
968/** \class DistiAttributeVertexArray
969 * An attribute for either a Vector or Vertex
970 */
971 template<class T> // Either Vector or Vertex
972 class DistiAttributeVertexArray : public DistiAttributeBase
973{
974 protected:
975 T** _attribPtr; ///< Underlying storage for this attribute.
976 typedef T* Tptr; ///< Shorthand typedef for a pointer to the template type.
977 unsigned int* _numVertices; ///< The number of vertices in a variable length array.
978 unsigned int _numElements; ///< The number of vertices in a fixed length array.
979 bool _fixedArray; ///< If true, this array is not resizable.
980 bool _compatabilityMode; ///< If true, backward compatibility mode will be used, values will be read with scanf.
981
982 public:
983 /// Set the compatibility parsing mode for this attribute.
984 /// \param mode The new mode to set.
985 void SetCompatabilityMode( bool mode ) { _compatabilityMode = mode; }
986
987 /// Constructor, for variable length arrays.
988 /// \param callback The callback method function pointer to call back.
989 /// \param name The name of this new attribute.
990 /// \param attribPtr A pointer to existing storage for this attribute.
991 /// \param numVertices The number of elements in the existing storage.
992 DistiAttributeVertexArray( CallbackMethodCallerBase* callback, const AttributeName& name, T** attribPtr, unsigned int* numVertices )
993 : DistiAttributeBase( callback, name, false )
994 , _attribPtr( attribPtr )
995 , _numVertices( numVertices )
996 , _numElements( 0 )
997 , _fixedArray( false )
998 {
999 _compatabilityMode = true;
1000 }
1001
1002 /// Constructor, for fixed arrays.
1003 /// \param callback The callback method function pointer to call back.
1004 /// \param name The name of this new attribute.
1005 /// \param attribPtr A pointer to existing storage for this attribute.
1006 /// \param numElements The number of elements in the existing storage.
1007 DistiAttributeVertexArray( CallbackMethodCallerBase* callback, const AttributeName& name, T* attribPtr, unsigned int numElements )
1008 : DistiAttributeBase( callback, name, true )
1009 , _attribPtr( new Tptr( attribPtr ) )
1010 , _numVertices( NULL )
1011 , _numElements( numElements )
1012 , _fixedArray( true )
1013 {
1014 _compatabilityMode = true;
1015 }
1016
1017 virtual ~DistiAttributeVertexArray()
1018 {
1019 if( ( _fixedArray || _localStorage ) && _attribPtr )
1020 delete _attribPtr;
1021 _attribPtr = NULL;
1022 }
1023
1024 /// \return True if this object is ready to have its WriteValue() called.
1025 virtual bool OkToWrite() const DISTI_METHOD_OVERRIDE
1026 {
1027 return ( *_attribPtr != NULL );
1028 }
1029
1030 /// Write data from this attribute into the stream.
1031 /// \param outstr The stream to write to.
1032 /// \return The stream in its current state.
1033 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
1034 {
1035 if( *_attribPtr != NULL )
1036 {
1037 unsigned int numVerts = _numElements;
1038 if( !_fixedArray )
1039 {
1040 outstr << *_numVertices;
1041 numVerts = *_numVertices;
1042 }
1043 DistiAttribDict::SpacingInc();
1044 for( unsigned int i = 0; i < numVerts; i++ )
1045 {
1046 outstr << '\n';
1047 outstr << ( *_attribPtr )[ i ];
1048 }
1049 DistiAttribDict::SpacingDec();
1050 }
1051 return outstr;
1052 }
1053
1054 /// Read data from the stream into this attribute.
1055 /// \param instr Stream to read from.
1056 /// \return The stream in its current state.
1057 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
1058 {
1059 unsigned int numVerts = _numElements;
1060
1061 if( !_fixedArray )
1062 {
1063 instr >> numVerts;
1064 *_numVertices = numVerts;
1065
1066 // Remove old storage if any
1067 if( *_attribPtr != NULL )
1068 delete[] * _attribPtr;
1069
1070 // Create new storage
1071 if( numVerts > 0 )
1072 *_attribPtr = new T[ numVerts ];
1073 else
1074 *_attribPtr = NULL;
1075 }
1076
1077 if( !_compatabilityMode )
1078 {
1079 char buf[ 1024 ];
1080 // Get newline character
1081 instr.getline( buf, 1024 );
1082 }
1083
1084 for( unsigned int i = 0; i < numVerts; i++ )
1085 {
1086 if( !_compatabilityMode )
1087 {
1088 char buf[ 1024 ];
1089 instr.getline( buf, 1024 );
1090#ifdef GLS_DEBUG
1091 int count =
1092#endif
1093 std::sscanf( buf, "%f %f %f",
1094 &( ( *_attribPtr )[ i ].x ),
1095 &( ( *_attribPtr )[ i ].y ),
1096 &( ( *_attribPtr )[ i ].z ) );
1097#ifdef GLS_DEBUG
1098 assert( 3 == count );
1099#endif
1100 }
1101 else
1102 {
1103 instr >> ( *_attribPtr )[ i ];
1104 }
1105 }
1106 CallCallback();
1107 return instr;
1108 }
1109
1110 /// Equality operator
1111 /// \param rArg The object to compare to.
1112 /// \return Whether or not the objects are equal.
1113 virtual bool operator==( const DistiAttributeBase& rArg ) DISTI_METHOD_OVERRIDE
1114 {
1115 DistiAttributeVertexArray<T>* r = dynamic_cast<DistiAttributeVertexArray<T>*>( const_cast<DistiAttributeBase*>( &rArg ) );
1116 if( !r )
1117 {
1118 return DistiAttributeBase::operator==( rArg );
1119 }
1120
1121 if( !( _name == r->_name ) || _numElements != r->_numElements )
1122 return false;
1123
1124 for( unsigned int i = 0u; i < _numElements; ++i )
1125 {
1126 T leftVert = ( *_attribPtr )[ i ];
1127 T rightVert = ( *r->_attribPtr )[ i ];
1128 if( !disti::Equal( leftVert.x, rightVert.x ) || !disti::Equal( leftVert.y, rightVert.y ) || !disti::Equal( leftVert.z, rightVert.z ) )
1129 {
1130 return false;
1131 }
1132 }
1133
1134 return true;
1135 }
1136
1137 /// Demangles type Tptr.
1138 /// \return String containing new name for type Tptr.
1139 /// \pre none
1140 /// \post none
1141 std::string Type() const DISTI_METHOD_OVERRIDE
1142 {
1143 return Demangle<Tptr>();
1144 }
1145};
1146
1147/** An attribute for either a Vector or Vertex */
1148 template<>
1149 class DistiAttributeVertexArray<Vertex> : public DistiAttributeBase
1150{
1151 protected:
1152 Vertex** _attribPtr; ///< Underlying storage for this attribute.
1153 typedef Vertex* Tptr; ///< Shorthand typedef for a pointer to a vertex.
1154 unsigned int* _numVertices; ///< The number of vertices in a variable length array.
1155 unsigned int _numElements; ///< The number of vertices in a fixed length array.
1156 bool _fixedArray; ///< If true, this array is not resizable.
1157 bool _compatabilityMode; ///< If true, backward compatibility mode will be used, values will be read with scanf.
1158
1159 public:
1160 /// Set the compatibility parsing mode for this attribute.
1161 /// \param mode The new mode to set.
1162 void SetCompatabilityMode( bool mode ) { _compatabilityMode = mode; }
1163
1164 /// Constructor, for variable length arrays.
1165 /// \param callback The callback method function pointer to call back.
1166 /// \param name The name of this new attribute.
1167 /// \param attribPtr A pointer to existing storage for this attribute.
1168 /// \param numVertices The number of elements in the existing storage.
1169 DistiAttributeVertexArray( CallbackMethodCallerBase* callback, const AttributeName& name, Vertex** attribPtr, unsigned int* numVertices )
1170 : DistiAttributeBase( callback, name, false )
1171 , _attribPtr( attribPtr )
1172 , _numVertices( numVertices )
1173 , _numElements( 0 )
1174 , _fixedArray( false )
1175 {
1176 _compatabilityMode = true;
1177 }
1178
1179 /// Constructor, for fixed arrays.
1180 /// \param callback The callback method function pointer to call back.
1181 /// \param name The name of this new attribute.
1182 /// \param attribPtr A pointer to existing storage for this attribute.
1183 /// \param numElements The number of elements in the existing storage.
1184 DistiAttributeVertexArray( CallbackMethodCallerBase* callback, const AttributeName& name, Vertex* attribPtr, unsigned int numElements )
1185 : DistiAttributeBase( callback, name, true )
1186 , _attribPtr( new Tptr( attribPtr ) )
1187 , _numVertices( NULL )
1188 , _numElements( numElements )
1189 , _fixedArray( true )
1190 {
1191 _compatabilityMode = true;
1192 }
1193
1194 virtual ~DistiAttributeVertexArray()
1195 {
1196 if( ( _fixedArray || _localStorage ) && _attribPtr )
1197 delete _attribPtr;
1198 _attribPtr = NULL;
1199 }
1200
1201 virtual bool OkToWrite() const DISTI_METHOD_OVERRIDE
1202 {
1203 return ( *_attribPtr != NULL );
1204 }
1205
1206 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
1207 {
1208 if( *_attribPtr != NULL )
1209 {
1210 unsigned int numVerts = _numElements;
1211 if( !_fixedArray )
1212 {
1213 outstr << *_numVertices;
1214 numVerts = *_numVertices;
1215 }
1216 DistiAttribDict::SpacingInc();
1217 for( unsigned int i = 0; i < numVerts; i++ )
1218 {
1219 outstr << '\n';
1220 outstr << ( *_attribPtr )[ i ];
1221 }
1222 DistiAttribDict::SpacingDec();
1223 }
1224 return outstr;
1225 }
1226
1227 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
1228 {
1229 unsigned int numVerts = _numElements;
1230
1231 if( !_fixedArray )
1232 {
1233 instr >> numVerts;
1234 *_numVertices = numVerts;
1235
1236 // Remove old storage if any
1237 if( *_attribPtr != NULL )
1238 delete[] * _attribPtr;
1239
1240 // Create new storage
1241 *_attribPtr = new Vertex[ numVerts ];
1242 }
1243
1244 if( !_compatabilityMode )
1245 {
1246 char buf[ 1024 ];
1247 // Get newline character
1248 instr.getline( buf, 1024 );
1249 }
1250
1251 for( unsigned int i = 0; i < numVerts; i++ )
1252 {
1253 if( !_compatabilityMode )
1254 {
1255 char buf[ 1024 ];
1256 instr.getline( buf, 1024 );
1257 int r, g, b, a;
1258#ifdef GLS_DEBUG
1259 int count =
1260#endif
1261 std::sscanf( buf, "%f %f %f %d %d %d %d",
1262 &( ( *_attribPtr )[ i ].x ),
1263 &( ( *_attribPtr )[ i ].y ),
1264 &( ( *_attribPtr )[ i ].z ),
1265 &r, &g, &b, &a );
1266#ifdef GLS_DEBUG
1267 assert( 7 == count );
1268#endif
1269
1270 ( *_attribPtr )[ i ].color.RGBA( (unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a );
1271 }
1272 else
1273 {
1274 instr >> ( *_attribPtr )[ i ];
1275 }
1276 }
1277 CallCallback();
1278 return instr;
1279 }
1280
1281 virtual bool operator==( const DistiAttributeBase& rArg ) DISTI_METHOD_OVERRIDE
1282 {
1283 DistiAttributeVertexArray<Vertex>* r = dynamic_cast<DistiAttributeVertexArray<Vertex>*>( const_cast<DistiAttributeBase*>( &rArg ) );
1284 if( !r )
1285 {
1286 return DistiAttributeBase::operator==( rArg );
1287 }
1288
1289 if( !( _name == r->_name ) || _numElements != r->_numElements )
1290 return false;
1291
1292 for( unsigned int i = 0u; i < _numElements; ++i )
1293 {
1294 Vertex leftVert = ( *_attribPtr )[ i ];
1295 Vertex rightVert = ( *r->_attribPtr )[ i ];
1296 if( !disti::Equal( leftVert.x, rightVert.x ) || !disti::Equal( leftVert.y, rightVert.y ) || !disti::Equal( leftVert.z, rightVert.z ) || leftVert.color != rightVert.color )
1297 {
1298 return false;
1299 }
1300 }
1301
1302 return true;
1303 }
1304
1305 std::string Type() const DISTI_METHOD_OVERRIDE
1306 {
1307 return Demangle<Tptr>();
1308 }
1309};
1310
1311/** This is used specifically for changing from TexturePoints as Vertexs to TexturePoints as Vectors.
1312 * It uses file version information to decide when expect what.
1313 */
1314 class DistiAttributeTexturePointArray : public DistiAttributeVertexArray<Vector>
1315{
1316 public:
1317 /// Constructor, for fixed arrays.
1318 /// \param callback The callback method function pointer to call back.
1319 /// \param name The name of this new attribute.
1320 /// \param attribPtr A pointer to existing storage for this attribute.
1321 /// \param numElements The number of elements in the existing storage.
1322 DistiAttributeTexturePointArray( CallbackMethodCallerBase* callback, const AttributeName& name, Vector* attribPtr, unsigned int numElements )
1323 : DistiAttributeVertexArray<Vector>( callback, name, attribPtr, numElements )
1324 {
1325 }
1326
1327 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
1328 {
1329 unsigned int numVerts = _numElements;
1330
1331 for( unsigned int i = 0; i < numVerts; i++ )
1332 {
1333 outstr << '\n';
1334 outstr << ( *_attribPtr )[ i ];
1335 }
1336 return outstr;
1337 }
1338
1339 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
1340 {
1341 unsigned int numVerts = _numElements;
1342
1343 for( unsigned int i = 0; i < numVerts; i++ )
1344 {
1345 // Get the whole line and then stream it into the Vector.
1346 // Before version 3.0, GL Studio files had full Vertex data
1347 // including color information stored after the location.
1348 // Reading whole lines comsumes this color information which is
1349 // then discarded.
1350 std::string line;
1351 std::getline( instr, line );
1352 // There must have been a leading newline, so read the first line again
1353 if( i == 0 && line.length() == 0 )
1354 std::getline( instr, line );
1355
1356 std::stringstream strm( line );
1357 strm >> ( *_attribPtr )[ i ];
1358 }
1359 CallCallback();
1360 return instr;
1361 }
1362};
1363
1364/** \class DistiAttributeNeverWrite
1365 * Allows for the normal template to be used to load a value but never write it out
1366 * This is used for compatability mostly.
1367 */
1368 template<class T>
1369 class DistiAttributeNeverWrite : public DistiAttribute<T>
1370{
1371 public:
1372 /// Constructor, uses existing storage.
1373 /// \param callback The callback function pointer to call back.
1374 /// \param name The name of this new attribute.
1375 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
1376 DistiAttributeNeverWrite( CallbackMethodCallerBase* callback, const AttributeName& name, T* attribPtr )
1377 : DistiAttribute<T>( callback, name, attribPtr )
1378 {
1379 }
1380
1381 /// Constructor, creates local storage.
1382 /// \param callback The callback function pointer to call back.
1383 /// \param name The name of this new attribute.
1384 /// \param initialValue The initial value of the attribute.
1385 DistiAttributeNeverWrite( CallbackMethodCallerBase* callback, const AttributeName& name, const T& initialValue )
1386 : DistiAttribute<T>( callback, name, initialValue )
1387 {
1388 }
1389
1390 virtual bool OkToWrite() const DISTI_METHOD_OVERRIDE { return false; }
1391};
1392
1393/** \class DistiAttributeStdStringNeverWrite
1394 * Allows for the normal template to be used to load a value but never write it out
1395 * This is used for compatability mostly.
1396 */
1397 class DistiAttributeStdStringNeverWrite : public DistiAttributeStdString
1398{
1399 public:
1400 /// Constructor, uses existing storage.
1401 /// \param callback The callback function pointer to call back.
1402 /// \param name The name of this new attribute.
1403 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
1404 DistiAttributeStdStringNeverWrite( CallbackMethodCallerBase* callback, const AttributeName& name, std::string* attribPtr )
1405 : DistiAttributeStdString( callback, name, attribPtr )
1406 {
1407 }
1408
1409 /// Constructor, creates local storage
1410 /// \param callback The callback function pointer to call back.
1411 /// \param name The name of this new attribute.
1412 /// \param initialValue The initial value of the attribute.
1413 DistiAttributeStdStringNeverWrite( CallbackMethodCallerBase* callback, const AttributeName& name, const std::string& initialValue )
1414 : DistiAttributeStdString( callback, name, initialValue )
1415 {
1416 }
1417
1418 virtual bool OkToWrite() const DISTI_METHOD_OVERRIDE { return false; }
1419};
1420
1421/** \class DistiAttributeAlias
1422 * Give an alternate name to an existing attribute.
1423 * This is used for compatability mostly. i.e. GlsTextBox "String" as an alias of "Text".
1424 */
1425 class DistiAttributeAlias : public DistiAttributeBase
1426{
1427 public:
1428 /// Constructor
1429 /// \param callback The method function pointer to call back.
1430 /// \param name The name to be given to this alias.
1431 /// \param originalName The name of the original attribute to link to.
1432 /// \param dict The attribute dictionary containing the original attribute.
1433 DistiAttributeAlias( CallbackMethodCallerBase* callback, const AttributeName& name, const AttributeName& originalName, DistiAttribDict* dict )
1434 : DistiAttributeBase( callback, name, false )
1435 , _originalAttribName( originalName )
1436 , _dictionary( dict )
1437 {
1438 }
1439
1440 virtual DISTI_EXPORT bool OkToWrite() const DISTI_METHOD_OVERRIDE;
1441 virtual DISTI_EXPORT bool ValueChanged() DISTI_METHOD_OVERRIDE;
1442 virtual DISTI_EXPORT void ResetValueChanged() DISTI_METHOD_OVERRIDE;
1443 virtual DISTI_EXPORT std::string ValueString() DISTI_METHOD_OVERRIDE;
1444 virtual DISTI_EXPORT void ValueString( const std::string& s ) DISTI_METHOD_OVERRIDE;
1445 virtual DISTI_EXPORT long ValueInt() DISTI_METHOD_OVERRIDE;
1446 virtual DISTI_EXPORT void ValueInt( long val ) DISTI_METHOD_OVERRIDE;
1447 virtual DISTI_EXPORT double ValueFloat() DISTI_METHOD_OVERRIDE;
1448 virtual DISTI_EXPORT void ValueFloat( double val ) DISTI_METHOD_OVERRIDE;
1449 virtual DISTI_EXPORT std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE;
1450 virtual DISTI_EXPORT std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE;
1451 DISTI_EXPORT std::string Type() const DISTI_METHOD_OVERRIDE;
1452 virtual DISTI_EXPORT bool operator==( const DistiAttributeBase& r ) DISTI_METHOD_OVERRIDE;
1453 virtual DISTI_EXPORT CallbackID RegisterObserver( AttributeObserver* callback ) DISTI_METHOD_OVERRIDE;
1454 virtual DISTI_EXPORT void UnregisterObserver( CallbackID id ) DISTI_METHOD_OVERRIDE;
1455 virtual DISTI_EXPORT void NotifyObservers() DISTI_METHOD_OVERRIDE;
1456
1457protected:
1458 AttributeName _originalAttribName; ///< Name of the original attribute that this alias points to.
1459 DistiAttribDict* _dictionary; ///< The dictionary containing the original attribute.
1460};
1461
1462/** \class DistiAttributeDynamicArray
1463 * An attribute for a dynamic array
1464 * T must be related to DynamicArray
1465 */
1466template<class T, bool showIndex /* In the output */>
1467class DistiAttributeDynamicArray : public DistiAttributeBase
1468{
1469 T* _attribPtr; ///< The underlying storage for this attribute.
1470
1471 public:
1472 /// Constructor, uses existing storage.
1473 /// \param callback The callback function pointer to call back.
1474 /// \param name The name of this new attribute.
1475 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
1476 DistiAttributeDynamicArray( CallbackMethodCallerBase* callback, const AttributeName& name, T* attribPtr )
1477 : DistiAttributeBase( callback, name, false )
1478 , _attribPtr( attribPtr )
1479 {
1480 }
1481
1482 /// Constructor, creates local storage.
1483 /// \param callback The callback function pointer to call back.
1484 /// \param name The name of this new attribute.
1485 DistiAttributeDynamicArray( CallbackMethodCallerBase* callback, const AttributeName& name )
1486 : DistiAttributeBase( callback, name, true )
1487 , _attribPtr( new T() )
1488 {
1489 }
1490
1491 ~DistiAttributeDynamicArray()
1492 {
1493 if( _localStorage )
1494 delete _attribPtr;
1495 _attribPtr = NULL;
1496 }
1497
1498 bool OkToWrite() const DISTI_METHOD_OVERRIDE
1499 {
1500 return ( _attribPtr != NULL && _attribPtr->Capacity() );
1501 }
1502
1503 std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
1504 {
1505 if( _attribPtr != NULL )
1506 {
1507 unsigned numEntries = _attribPtr->Count();
1508 outstr << numEntries;
1509
1510 DistiAttribDict::SpacingInc();
1511
1512 for( unsigned i = 0; i < numEntries; i++ )
1513 {
1514 outstr << '\n';
1515
1516 if( showIndex )
1517 {
1518 outstr << DistiAttribDict::SpacingString() << i << " ";
1519 }
1520 outstr.width( 1 );
1521 outstr << DistiAttribDict::SpacingString() << ( *_attribPtr )[ i ] << " ";
1522 }
1523 DistiAttribDict::SpacingDec();
1524 }
1525 return outstr;
1526 }
1527
1528 std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
1529 {
1530 unsigned numEntries = 0;
1531 instr >> numEntries;
1532
1533 _attribPtr->Count( numEntries ); // Set count of objects in
1534 for( unsigned i = 0; i < numEntries; i++ )
1535 {
1536 // We read the entry number, which may differ from the index if values are skipped.
1537 unsigned entry = i;
1538 if( showIndex )
1539 {
1540 instr >> entry;
1541 }
1542 instr >> ( *_attribPtr )[ entry ];
1543 }
1544 CallCallback();
1545 return instr;
1546 }
1547
1548 std::string Type() const DISTI_METHOD_OVERRIDE
1549 {
1550 return Demangle<T>();
1551 }
1552};
1553
1554/** \class DistiAttributeStdVector
1555 * An attribute for a std::vector
1556 * T must be related to std::vector
1557 */
1558 template<class T, bool showIndex /* In the output */>
1559 class DistiAttributeStdVector : public DistiAttributeBase
1560{
1561 private:
1562 T* _attribPtr; ///< The underlying storage for this attribute.
1563
1564 DistiAttributeStdVector( const DistiAttributeStdVector& other );
1565
1566 public:
1567 /// Constructor, uses existing storage.
1568 /// \param callback The callback function pointer to call back.
1569 /// \param name The name of this new attribute.
1570 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
1571 DistiAttributeStdVector( CallbackMethodCallerBase* callback, const AttributeName& name, T* attribPtr )
1572 : DistiAttributeBase( callback, name, false )
1573 , _attribPtr( attribPtr )
1574 {
1575 }
1576
1577 /// Constructor, creates local storage.
1578 /// \param callback The callback function pointer to call back.
1579 /// \param name The name of this new attribute.
1580 DistiAttributeStdVector( CallbackMethodCallerBase* callback, const AttributeName& name )
1581 : DistiAttributeBase( callback, name, true )
1582 , _attribPtr( new T() )
1583 {
1584 }
1585
1586 virtual ~DistiAttributeStdVector()
1587 {
1588 if( _localStorage )
1589 {
1590 delete _attribPtr;
1591 }
1592 _attribPtr = NULL;
1593 }
1594
1595 virtual bool OkToWrite() const DISTI_METHOD_OVERRIDE
1596 {
1597 return ( _attribPtr != NULL && _attribPtr->size() );
1598 }
1599
1600 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
1601 {
1602 if( _attribPtr != NULL )
1603 {
1604 const std::size_t numEntries = _attribPtr->size();
1605 outstr << numEntries;
1606
1607 DistiAttribDict::SpacingInc();
1608
1609 for( std::size_t i = 0; i < numEntries; i++ )
1610 {
1611 outstr << '\n';
1612
1613 if( showIndex )
1614 {
1615 outstr << DistiAttribDict::SpacingString() << i << " ";
1616 }
1617 outstr.width( 1 );
1618 outstr << DistiAttribDict::SpacingString() << ( *_attribPtr )[ i ] << " ";
1619 }
1620 DistiAttribDict::SpacingDec();
1621 }
1622 return outstr;
1623 }
1624
1625 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
1626 {
1627 if( _attribPtr != NULL )
1628 {
1629 int numEntries;
1630 instr >> numEntries;
1631
1632 _attribPtr->resize( numEntries ); // Set count of objects in
1633 int entry;
1634 for( int i = 0; i < numEntries; i++ )
1635 {
1636 entry = i;
1637 if( showIndex )
1638 {
1639 instr >> entry;
1640 }
1641 instr >> ( *_attribPtr )[ entry ];
1642 }
1643 CallCallback();
1644 }
1645
1646 return instr;
1647 }
1648
1649 std::string Type() const DISTI_METHOD_OVERRIDE
1650 {
1651 return Demangle<T>();
1652 }
1653};
1654
1655/** An attribute for a DynamicArray of homogeneous items
1656 * T must have ReadValue and WriteValue methods
1657 * Replacement for DistiAttributeHomogeneousAttributeArray
1658 */
1659 template<class T>
1660 class DistiAttributeHomogeneousItemArray : public DistiAttributeBase
1661{
1662 public:
1663 typedef T* ( *CreateItemCb )(); ///< Typedef for a function pointer used to create new items for the list.
1664
1665 protected:
1666 DynamicArray<T*>* _array; ///< Underlying storage for this attribute.
1667 CreateItemCb _createCb; ///< Function pointer called to create new items in the list.
1668
1669 public:
1670 /// Constructor requires a dynamic array of T*.
1671 /// Uses existing storage.
1672 /// \param name The name for this new attribute.
1673 /// \param array The underlying storage for this property.
1674 /// \param createCb The function pointer called to generate new objects of T for the list.
1675 DistiAttributeHomogeneousItemArray( const AttributeName& name, DynamicArray<T*>* array, CreateItemCb createCb )
1676 : DistiAttributeBase( NULL, name, false )
1677 , _array( array )
1678 , _createCb( createCb )
1679 {
1680 }
1681
1682 virtual ~DistiAttributeHomogeneousItemArray() {}
1683
1684 virtual bool OkToWrite() const DISTI_METHOD_OVERRIDE { return _array && _array->Count(); }
1685
1686 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
1687 {
1688 outstr << "\n"
1689 << DistiAttribDict::SpacingString() << "{\n";
1690 DistiAttribDict::SpacingInc();
1691 for( unsigned int i = 0; i < _array->Count(); i++ )
1692 {
1693 if( ( *_array )[ i ] )
1694 {
1695 outstr << DistiAttribDict::SpacingString();
1696 outstr << "Item: "; // Everything in the list is called Item
1697 ( ( *_array )[ i ] )->WriteValue( outstr );
1698 outstr << "\n";
1699 }
1700 }
1701 DistiAttribDict::SpacingDec();
1702 outstr << DistiAttribDict::SpacingString() << "}\n";
1703 return outstr;
1704 }
1705
1706 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
1707 {
1708 // Scan through the token including the ':'
1709 std::string buf;
1710
1711 while( DistiAttribDict::ScanToken( instr, buf ) )
1712 {
1713 if( !buf.length() )
1714 continue;
1715
1716 if( buf == "Item" )
1717 {
1718 // Eat the space between the : and the data
1719 instr.get();
1720 // Dynamically create it, and add it to the end of the list
1721 if( T* const createdItem = dynamic_cast<T*>( _createCb() ) )
1722 {
1723 _array->PushBack( createdItem );
1724 _array->Back()->ReadValue( instr );
1725 }
1726 }
1727 }
1728 return instr;
1729 }
1730
1731 std::string Type() const DISTI_METHOD_OVERRIDE
1732 {
1733 // clang-format off
1734 return Demangle< DynamicArray<T*> >();
1735 // clang-format on
1736 }
1737};
1738/** The attribute used in generated code for accessing class properties
1739 * It can have a get method, set method, and an attribute pointer, or almost
1740 * any combination of the three.
1741 * T must have a default constructor, even if it doesn't initialize.
1742 * SetArgT is the argument type for the SetMethodType.
1743 * Specify this if the argument for the Set call is not "const &T".
1744 * GetReturnT is the return type for the GetMethodType.
1745 * Specify this if the return type for the Get call is not T
1746 * The get and set methods are called when the attribute interface is used for access.
1747 * If the methods are not provided, the attribute stream operators are used instead.
1748 * If the property does not have a method or attribute pointer, it will not be able to read/write its value.
1749 */
1750 template<class containerT, class T, class SetArgT = const T&, class GetReturnT = T>
1751 class DistiAttributeProperty : public DistiAttribute<T>
1752{
1753 public:
1754 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
1755 typedef DistiAttribute<T> _BaseClass; ///< Deprecated typedef for the base class.
1756 typedef DistiAttribute<T> BaseClass; ///< Typedef for the base class.
1757 typedef void ( containerT::*SetMethodType )( SetArgT ); ///< Typedef for the set method function pointer.
1758 typedef GetReturnT ( containerT::*GetMethodType )(); ///< Typedef for the get method function pointer.
1759 typedef GetReturnT ( containerT::*GetMethodConstType )() const; ///< Typedef for the get method const function pointer.
1760
1761 float _precision; ///< Number of digits of floating point precision.
1762 containerT* _container; ///< Object that contains the set and get methods.
1763 SetMethodType _setMethod; ///< The set method function pointer.
1764 GetMethodType _getMethod; ///< The get method function pointer.
1765
1766 /// Constructor
1767 /// \param name The name of the new attribute.
1768 /// \param frame The object containing the set and get methods.
1769 /// \param attribPtr The pointer to the underlying storage for this attribute.
1770 /// \param setMethod The set method function pointer.
1771 /// \param getMethod The get method function pointer.
1772 DistiAttributeProperty( const AttributeName& name, containerT* frame, T* attribPtr, SetMethodType setMethod, GetMethodType getMethod )
1773 : BaseClass( NULL, name, attribPtr )
1774 , _precision( 0 )
1775 , _container( frame )
1776 , _setMethod( setMethod )
1777 , _getMethod( getMethod )
1778 {
1779 // Automatically use some precision for floats
1780 if( typeid( T ) == typeid( float ) || typeid( T ) == typeid( double ) || typeid( T ) == typeid( long double ) )
1781 {
1782 _precision = 10;
1783 }
1784 }
1785
1786 virtual bool OkToWrite() const DISTI_METHOD_OVERRIDE
1787 {
1788 return ( this->_attribPtr || _getMethod );
1789 }
1790
1791 // The DistiAttribute<> classes override the DistiAttributeBase implementation for these methods. Here, we revert back to the DistiAttributeBase implementation
1792 virtual std::string ValueString() DISTI_METHOD_OVERRIDE { return DistiAttributeBase::ValueString(); }
1793 virtual void ValueString( const std::string& s ) DISTI_METHOD_OVERRIDE { DistiAttributeBase::ValueString( s ); }
1794
1795 virtual long ValueInt() DISTI_METHOD_OVERRIDE { return DistiAttributeBase::ValueInt(); }
1796 virtual void ValueInt( long val ) DISTI_METHOD_OVERRIDE { DistiAttributeBase::ValueInt( val ); }
1797
1798 virtual double ValueFloat() DISTI_METHOD_OVERRIDE { return DistiAttributeBase::ValueFloat(); }
1799 virtual void ValueFloat( double val ) DISTI_METHOD_OVERRIDE { DistiAttributeBase::ValueFloat( val ); }
1800
1801 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
1802 {
1803 if( _precision > 0 )
1804 outstr.precision( int( _precision ) );
1805
1806 if( _getMethod && _container )
1807 {
1808 // Save the current _attribPtr
1809 T* tempAttribPtr = this->_attribPtr;
1810
1811 // Get the value from the method.
1812 T temp( ( _container->*_getMethod )() );
1813
1814 // Temporarily change the _attribPtr
1815 this->_attribPtr = &temp;
1816
1817 // Call the base class to format the _attribPtr
1818 BaseClass::WriteValue( outstr );
1819
1820 // Put the _attribPtr back to where it belongs
1821 this->_attribPtr = tempAttribPtr;
1822 }
1823 else if( this->_attribPtr )
1824 {
1825 BaseClass::WriteValue( outstr );
1826 }
1827
1828 return outstr;
1829 }
1830
1831 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
1832 {
1833 if( _setMethod && _container )
1834 {
1835 // Save the current _attribPtr
1836 T* tempAttribPtr = this->_attribPtr;
1837 T temp;
1838
1839 // Set _attribPtr to the temp variable;
1840 this->_attribPtr = &temp;
1841
1842 // Call the base class to format the input
1843 BaseClass::ReadValue( instr );
1844
1845 // Call the method
1846 ( _container->*_setMethod )( static_cast<SetArgT>( temp ) );
1847
1848 this->_attribPtr = tempAttribPtr;
1849 }
1850 else if( this->_attribPtr )
1851 {
1852 BaseClass::ReadValue( instr );
1853 }
1854
1855 return instr;
1856 }
1857
1858 std::string Type() const DISTI_METHOD_OVERRIDE
1859 {
1860 return Demangle<T>();
1861 }
1862
1863 virtual T Value() DISTI_METHOD_OVERRIDE
1864 {
1865 if( _getMethod && _container )
1866 {
1867 // Get the value from the method
1868 return ( _container->*_getMethod )();
1869 }
1870 else if( this->_attribPtr )
1871 {
1872 return BaseClass::Value();
1873 }
1874 else
1875 {
1876 return T();
1877 }
1878 }
1879
1880 virtual void Value( const T& val ) DISTI_METHOD_OVERRIDE // this has to match the base class's prototype so we override it, ie can't use SetArgT here
1881 {
1882 if( _setMethod && _container )
1883 {
1884 ( _container->*_setMethod )( static_cast<SetArgT>( val ) );
1885 }
1886 else if( this->_attribPtr )
1887 {
1888 BaseClass::Value( val );
1889 }
1890 }
1891};
1892
1893/// Overloaded helper function to create a DistiAttributeProperty where the setter param is of type Type and the getter is non-const. (See other variants below.)
1894/// \tparam Type The type of the property (int, float, GlsColor, etc.)
1895/// \tparam Class The class of the object that owns this parameter (typically a subclass of DisplayObject)
1896/// \param attrName The attribute name for this property.
1897/// \param obj The display object instance associated with this property.
1898/// \param setMethod The setter method for the property (can be NULL)
1899/// \param getMethod The getter method for the property (can be NULL)
1900/// \return The DistiAttributeProperty instance, which is owned by the caller.
1901/// \code
1902/// Attributes().Add( CreateDistiAttributeProperty<int>( MetaTextureIndex, this, &DisplayObject::TextureIndex, &DisplayObject::TextureIndex ) );
1903/// \endcode
1904 template<typename Type, class Class>
1905 DistiAttributeProperty<Class, Type, Type>* CreateDistiAttributeProperty(
1906 const AttributeName& attrName,
1907 Class* const obj,
1908 const typename DistiAttributeProperty<Class, Type, Type>::SetMethodType setMethod,
1909 const typename DistiAttributeProperty<Class, Type, Type>::GetMethodType getMethod = NULL )
1910{
1911 return new DistiAttributeProperty<Class, Type, Type>( attrName, obj, NULL, setMethod, getMethod );
1912}
1913
1914/// Overloaded helper function to create a DistiAttributeProperty where the getter is const.
1915/// \tparam Type The type of the property (int, float, GlsColor, etc.)
1916/// \tparam Class The class of the object that owns this parameter (typically a subclass of DisplayObject)
1917/// \param attrName The attribute name for this property.
1918/// \param obj The display object instance associated with this property.
1919/// \param setMethod The setter method for the property (can be NULL).
1920/// \param getMethod The getter method for the property (can be NULL).
1921/// \return The DistiAttributeProperty instance, which is owned by the caller.
1922 template<typename Type, class Class>
1923 DistiAttributeProperty<Class, Type, Type>* CreateDistiAttributeProperty(
1924 const AttributeName& attrName,
1925 Class* const obj,
1926 const typename DistiAttributeProperty<Class, Type, Type>::SetMethodType setMethod,
1927 const typename DistiAttributeProperty<Class, Type, Type>::GetMethodConstType getMethod )
1928{
1929 return new DistiAttributeProperty<Class, Type, Type>( attrName, obj, NULL, setMethod,
1930 reinterpret_cast<typename DistiAttributeProperty<Class, Type>::GetMethodType>( getMethod ) );
1931}
1932
1933/// Overloaded helper function to create a DistiAttributeProperty where there is no setter method and the getter is const.
1934/// \tparam Type The type of the property (int, float, GlsColor, etc.)
1935/// \tparam Class The class of the object that owns this parameter (typically a subclass of DisplayObject)
1936/// \param attrName The attribute name for this property.
1937/// \param obj The display object instance associated with this property.
1938/// \param getMethod The getter method for the property (can be NULL).
1939/// \return The DistiAttributeProperty instance, which is owned by the caller.
1940 template<typename Type, class Class>
1941 DistiAttributeProperty<Class, Type>* CreateDistiAttributeProperty(
1942 const AttributeName& attrName,
1943 Class* const obj,
1944 const typename DistiAttributeProperty<Class, Type>::GetMethodConstType getMethod )
1945{
1946 return new DistiAttributeProperty<Class, Type>( attrName, obj, NULL, NULL,
1947 reinterpret_cast<typename DistiAttributeProperty<Class, Type>::GetMethodType>( getMethod ) );
1948}
1949
1950/// Overloaded helper function to create a DistiAttributeProperty where there is no setter method and the getter is non-const.
1951/// \tparam Type The type of the property (int, float, GlsColor, etc.)
1952/// \tparam Class The class of the object that owns this parameter (typically a subclass of DisplayObject)
1953/// \param attrName The attribute name for this property.
1954/// \param obj The display object instance associated with this property.
1955/// \param getMethod The getter method for the property (can be NULL).
1956/// \return The DistiAttributeProperty instance, which is owned by the caller.
1957 template<typename Type, class Class>
1958 DistiAttributeProperty<Class, Type>* CreateDistiAttributeProperty(
1959 const AttributeName& attrName,
1960 Class* const obj,
1961 const typename DistiAttributeProperty<Class, Type>::GetMethodType getMethod )
1962{
1963 return new DistiAttributeProperty<Class, Type>( attrName, obj, NULL, NULL, getMethod );
1964}
1965
1966/// Overloaded helper function to create a DistiAttributeProperty where the setter param is of type const Type& and the getter is non-const.
1967/// \tparam Type The type of the property (int, float, GlsColor, etc.)
1968/// \tparam Class The class of the object that owns this parameter (typically a subclass of DisplayObject)
1969/// \param attrName The attribute name for this property.
1970/// \param obj The display object instance associated with this property.
1971/// \param setMethod The setter method for the property (can be NULL).
1972/// \param getMethod The getter method for the property (can be NULL).
1973/// \return The DistiAttributeProperty instance, which is owned by the caller.
1974 template<typename Type, class Class>
1975 DistiAttributeProperty<Class, Type, const Type&>* CreateDistiAttributeProperty(
1976 const AttributeName& attrName,
1977 Class* const obj,
1978 const typename DistiAttributeProperty<Class, Type, const Type&>::SetMethodType setMethod,
1979 const typename DistiAttributeProperty<Class, Type, const Type&>::GetMethodType getMethod = NULL )
1980{
1981 return new DistiAttributeProperty<Class, Type, const Type&>( attrName, obj, NULL, setMethod, getMethod );
1982}
1983
1984/// Overloaded helper function to create a DistiAttributeProperty where the setter param is of type const Type& and the getter is const.
1985/// \tparam Type The type of the property (int, float, GlsColor, etc.)
1986/// \tparam Class The class of the object that owns this parameter (typically a subclass of DisplayObject)
1987/// \param attrName The attribute name for this property.
1988/// \param obj The display object instance associated with this property.
1989/// \param setMethod The setter method for the property (can be NULL).
1990/// \param getMethod The getter method for the property (can be NULL).
1991/// \return The DistiAttributeProperty instance, which is owned by the caller.
1992 template<typename Type, class Class>
1993 DistiAttributeProperty<Class, Type, const Type&>* CreateDistiAttributeProperty(
1994 const AttributeName& attrName,
1995 Class* const obj,
1996 const typename DistiAttributeProperty<Class, Type, const Type&>::SetMethodType setMethod,
1997 const typename DistiAttributeProperty<Class, Type, const Type&>::GetMethodConstType getMethod )
1998{
1999 return new DistiAttributeProperty<Class, Type, const Type&>( attrName, obj, NULL, setMethod,
2000 reinterpret_cast<typename DistiAttributeProperty<Class, Type, const Type&>::GetMethodType>( getMethod ) );
2001}
2002
2003/// Overloaded helper function to create a DistiAttributeProperty where the getter and setter are different base types (e.g. int vs bool).
2004/// \tparam Type The type of the property (int, float, GlsColor, etc.)
2005/// \tparam Class The class of the object that owns this parameter (typically a subclass of DisplayObject)
2006/// \param attrName The attribute name for this property.
2007/// \param obj The display object instance associated with this property.
2008/// \param setMethod The setter method for the property (can be NULL).
2009/// \param getMethod The getter method for the property (can be NULL).
2010/// \return The DistiAttributeProperty instance, which is owned by the caller.
2011 template<typename GetReturnT, typename SetArgT, class Class>
2012 DistiAttributeProperty<Class, GetReturnT, SetArgT>* CreateDistiAttributeProperty(
2013 const AttributeName& attrName,
2014 Class* const obj,
2015 const typename DistiAttributeProperty<Class, GetReturnT, SetArgT>::SetMethodType setMethod,
2016 const typename DistiAttributeProperty<Class, GetReturnT, SetArgT>::GetMethodType getMethod )
2017{
2018 return new DistiAttributeProperty<Class, GetReturnT, SetArgT>( attrName, obj, NULL, setMethod, getMethod );
2019}
2020
2021/// Overloaded helper function for properties that formerly used DistiAttributeLocation, which wraps properties that are stored in c++ as a Vertex but used in the Resources as a Vector.
2022/// \tparam Type The type of the property (int, float, GlsColor, etc.)
2023/// \tparam Class The class of the object that owns this parameter (typically a subclass of DisplayObject)
2024/// \param attrName The attribute name for this property.
2025/// \param obj The display object instance associated with this property.
2026/// \param setMethod The setter method for the property (can be NULL).
2027/// \param getMethod The getter method for the property (can be NULL).
2028/// \return The DistiAttributeProperty instance, which is owned by the caller.
2029 template<class Class>
2030 DistiAttributeProperty<Class, Vector, const Vertex&, const Vertex&>* CreateDistiAttributePropertyVertexToVector(
2031 const AttributeName& attrName,
2032 Class* const obj,
2033 const typename DistiAttributeProperty<Class, Vector, const Vertex&, const Vertex&>::SetMethodType setMethod,
2034 const typename DistiAttributeProperty<Class, Vector, const Vertex&, const Vertex&>::GetMethodConstType getMethod )
2035{
2036 return new DistiAttributeProperty<Class, Vector, const Vertex&, const Vertex&>( attrName, obj, NULL, setMethod,
2037 reinterpret_cast<typename DistiAttributeProperty<Class, Vector, const Vertex&, const Vertex&>::GetMethodType>( getMethod ) );
2038}
2039
2040/** An empty attribute used where a reference to an attribute
2041 * must be returned, but needs to be blank
2042 */
2043 class DistiEmptyAttribute : public DistiAttributeBase
2044{
2045 public:
2046 DistiEmptyAttribute()
2047 : DistiAttributeBase( NULL, AttributeName( "EmptyAttribute" ), false )
2048 {
2049 }
2050
2051 // Write nothing
2052 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
2053 {
2054 return outstr;
2055 }
2056
2057 // Read nothing
2058 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
2059 {
2060 return instr;
2061 }
2062};
2063
2064/** \class DistiAttributeEnumDirect
2065 * A Disti Attribute which reads and writes enumerations directly, bypassing method calls.
2066 */
2067 template<class enumType>
2068 class DistiAttributeEnumDirect : public DistiAttributeBase
2069{
2070 protected:
2071 enumType* _attribPtr; ///< Underlying storage for this attribute.
2072
2073 public:
2074 DistiAttributeEnumDefList* _pairList; ///< Observing pointer to the enum string to integer conversion data.
2075
2076 /// Constructor, uses existing storage.
2077 /// \param callback The callback function pointer to call back.
2078 /// \param name The name of this new attribute.
2079 /// \param attribPtr A pointer to a pointer to existing storage for this attribute.
2080 /// \param pairList The enum string to integer data to use for this attribute.
2081 DistiAttributeEnumDirect( CallbackMethodCallerBase* callback, const AttributeName& name, enumType* attribPtr, DistiAttributeEnumDefList* pairList )
2082 : DistiAttributeBase( callback, name, false )
2083 , _attribPtr( attribPtr )
2084 , _pairList( pairList )
2085 {
2086 }
2087
2088 /// Constructor, creates local storage
2089 /// \param callback The callback function pointer to call back.
2090 /// \param name The name of this new attribute.
2091 /// \param value The initial value for this attribute.
2092 /// \param pairList The enum string to integer data to use for this attribute.
2093 DistiAttributeEnumDirect( CallbackMethodCallerBase* callback, const AttributeName& name, const enumType& value, DistiAttributeEnumDefList* pairList )
2094 : DistiAttributeBase( callback, name, true )
2095 , _attribPtr( new enumType( value ) )
2096 , _pairList( pairList )
2097 {
2098 }
2099
2100 virtual ~DistiAttributeEnumDirect()
2101 {
2102 if( _localStorage && _attribPtr )
2103 delete _attribPtr;
2104 }
2105
2106 /// \return The attribute value as an integer.
2107 virtual long ValueInt() DISTI_METHOD_OVERRIDE { return (long)*_attribPtr; };
2108
2109 /// Set the attribute value as an integer.
2110 /// \param val The new value to set.
2111 virtual void ValueInt( long val ) DISTI_METHOD_OVERRIDE { *_attribPtr = (enumType)val; };
2112
2113 /// Assignment operator
2114 /// \param oldClass The object to copy from.
2115 /// \return The resulting object (this).
2116 virtual DistiAttributeBase& operator=( const DistiAttributeBase& oldClass ) DISTI_METHOD_OVERRIDE
2117 {
2118 DistiAttributeEnumDirect* ptr = dynamic_cast<DistiAttributeEnumDirect*>( const_cast<DistiAttributeBase*>( &oldClass ) );
2119 if( ptr )
2120 {
2121 *_attribPtr = ( enumType ) * ( ptr->_attribPtr );
2122 CallCallback();
2123 }
2124 else
2125 {
2126 return DistiAttributeBase::operator=( oldClass );
2127 }
2128 return *this;
2129 }
2130
2131 /// Write data from this attribute into the stream.
2132 /// \param outstr The stream to write to.
2133 /// \return The stream in its current state.
2134 virtual std::ostream& WriteValue( std::ostream& outstr ) DISTI_METHOD_OVERRIDE
2135 {
2136 bool foundIt = false;
2137#ifndef __VXWORKS__
2138 typename DistiAttributeEnumDefList::iterator item = _pairList->begin();
2139 while( item != _pairList->end() )
2140 {
2141 if( ( *item )->_enum == *_attribPtr )
2142 {
2143 outstr << ( *item )->_string;
2144 foundIt = true;
2145 break;
2146 }
2147 ++item;
2148 }
2149 if( !foundIt )
2150 {
2151 //Didn't find it so just write the number
2152 outstr << (int)*_attribPtr;
2153 }
2154#endif
2155
2156 return outstr;
2157 }
2158
2159 /// Read data from the stream into this attribute.
2160 /// \param instr The stream to read from.
2161 /// \return The stream in its current state.
2162 virtual std::istream& ReadValue( std::istream& instr ) DISTI_METHOD_OVERRIDE
2163 {
2164#ifndef __VXWORKS__
2165 char value[ 64 ];
2166 instr >> value;
2167
2168 bool foundIt = false;
2169 typename DistiAttributeEnumDefList::iterator item = _pairList->begin();
2170
2171 // First look by enumeration
2172 while( item != _pairList->end() )
2173 {
2174 if( strcmp( ( *item )->_string, value ) == 0 )
2175 {
2176 *_attribPtr = (enumType)( *item )->_enum;
2177 CallCallback();
2178
2179 foundIt = true;
2180 break;
2181 }
2182 ++item;
2183 }
2184
2185 // If not found, assume that the numerical value is specified.
2186 if( !foundIt )
2187 {
2188 *_attribPtr = (enumType)atoi( value );
2189 CallCallback();
2190 }
2191#endif
2192
2193 return instr;
2194 }
2195
2196 /// Demangles type enumType.
2197 /// \return String containing new name for type enumType.
2198 /// \pre none
2199 /// \post none
2200 std::string Type() const DISTI_METHOD_OVERRIDE
2201 {
2202 return Demangle<enumType>();
2203 }
2204};
2205
2206////////////////////////////////////////////////////////////////////////////////
2207/// A macro for boilerplate code to setup a DisplayObject callback.
2208/// \param instance The DisplayObject instance.
2209/// \param Class The current class name, derived from DisplayObject.
2210/// \param Method The class's method name for the callback.
2211/// \code{.cpp}
2212/// // Given a class ScrollList that inherits from DisplayObject...
2213/// ScrollList::ScrollList()
2214/// {
2215/// DISTI_REGISTER_METHOD_CALLBACK( this, &ScrollList::EventCallback );
2216/// }
2217///
2218/// int ScrollList::EventCallback( Group* self, DisplayEvent* ev )
2219/// {
2220/// // ... event handler code ...
2221/// }
2222/// \endcode
2223////////////////////////////////////////////////////////////////////////////////
2224#define DISTI_REGISTER_METHOD_CALLBACK( instance, Class, Method ) \
2225 { \
2226 typedef CallbackMethodCallerTemplate<Class, Class> Caller; \
2227 typedef typename Caller::MethodType1 MethodType; \
2228 const MethodType callback = reinterpret_cast<MethodType>( Method ); \
2229 ThisClass::CallbackCaller( new Caller( callback, instance ) ); \
2230 }
2231
2232////////////////////////////////////////////////////////////////////////////////
2233/// A macro for boilerplate code to setup a DisplayObject method caller for
2234/// MethodType 1.
2235/// \param object The DisplayObject instance.
2236/// \param method The method that should be called.
2237/// \param parent The parent to the object
2238////////////////////////////////////////////////////////////////////////////////
2239#define DISTI_SET_OBJECT_CALLBACK1( object, method, parent ) \
2240 ( object )->CallbackCaller( \
2241 new CallbackMethodCallerTemplate<DisplayObject, DisplayObject>( \
2242 (disti::CallbackMethodCallerTemplate<DisplayObject, DisplayObject>::MethodType1)( method ), ( parent ) ) );
2243
2244////////////////////////////////////////////////////////////////////////////////
2245/// A macro for boilerplate code to setup a DisplayObject attribute.
2246/// \param Type The type of the attribute.
2247/// \param name The unique string name identifying the attribute.
2248/// \param memberVarAddr A pointer to the member variable of type \a Type.
2249/// Can be NULL if no member variable is desired.
2250/// \sa DISTI_ADD_ATTRIBUTE_CALLBACK
2251/// \sa DISTI_ADD_ATTRIBUTE_SET_GET
2252////////////////////////////////////////////////////////////////////////////////
2253#define DISTI_ADD_ATTRIBUTE( Type, name, memberVarAddr ) \
2254 { \
2255 static const AttributeName attr( name ); \
2256 CallbackAttributeNotifier<ThisClass> cb( this, attr ); \
2257 this->Attributes().Add( new DistiAttribute<Type>( &cb, ( attr ), ( memberVarAddr ) ) ); \
2258 }
2259
2260////////////////////////////////////////////////////////////////////////////////
2261/// A macro for boilerplate code to setup a DisplayObject attribute that has a
2262/// callback function.
2263/// \param Type The type of the attribute.
2264/// \param name The unique string name identifying the attribute.
2265/// \param memberVarAddr A pointer to the member variable of type \a Type.
2266/// Can be NULL if no member variable is desired.
2267/// \param callbackFunction A member function pointer to the function called when this
2268/// attribute is changed.
2269/// \sa DISTI_ADD_ATTRIBUTE
2270/// \sa DISTI_ADD_ATTRIBUTE_SET_GET
2271////////////////////////////////////////////////////////////////////////////////
2272#define DISTI_ADD_ATTRIBUTE_CALLBACK( Type, name, memberVarAddr, callbackFunction ) \
2273 { \
2274 typedef void ( ThisClass::*Method )(); /* Member function pointer */ \
2275 static const AttributeName attr( name ); \
2276 CallbackAttributeNotifier<ThisClass> cb( this, attr, reinterpret_cast<Method>( callbackFunction ) ); \
2277 this->Attributes().Add( new DistiAttribute<Type>( &cb, ( attr ), ( memberVarAddr ) ) ); \
2278 }
2279
2280////////////////////////////////////////////////////////////////////////////////
2281/// A macro for boilerplate code to setup a DisplayObject attribute that has a
2282/// setter and a getter function.
2283/// \param Type The type of the attribute.
2284/// \param name The unique string name identifying the attribute.
2285/// \param setter A member function pointer to the setter function (can be NULL)
2286/// \param getter A member function pointer to the getter function (can be NULL)
2287/// \sa DISTI_ADD_ATTRIBUTE
2288/// \sa DISTI_ADD_ATTRIBUTE_CALLBACK
2289////////////////////////////////////////////////////////////////////////////////
2290#define DISTI_ADD_ATTRIBUTE_SET_GET( Type, name, setter, getter ) \
2291 { \
2292 static const AttributeName attr( name ); \
2293 this->Attributes().Add( CreateDistiAttributeProperty<Type>( attr, this, setter, getter ) ); \
2294 }
2295
2296////////////////////////////////////////////////////////////////////////////////
2297/// A macro for boilerplate code to setup a string as a DisplayObject attribute.
2298/// \param name The unique string name identifying the attribute.
2299/// \param memberVarAddr A pointer to the member variable of type std::string.
2300/// Can be NULL if no member variable is desired.
2301/// \sa DISTI_ADD_ATTRIBUTE_STRING_CALLBACK
2302////////////////////////////////////////////////////////////////////////////////
2303#define DISTI_ADD_ATTRIBUTE_STRING( name, memberVarAddr ) \
2304 { \
2305 static const AttributeName attr( name ); \
2306 CallbackAttributeNotifier<ThisClass> cb( this, attr ); \
2307 this->Attributes().Add( new DistiAttributeEncodedStdString( &cb, attr, memberVarAddr ) ); \
2308 }
2309
2310////////////////////////////////////////////////////////////////////////////////
2311/// A macro for boilerplate code to setup a string as a DisplayObject attribute
2312/// with a callback
2313/// \param name The unique string name identifying the attribute.
2314/// \param memberVarAddr A pointer to the member variable of type std::string.
2315/// Can be NULL if no member variable is desired.
2316/// \param callbackFunction The function that gets called when the attribute changes.
2317/// \sa DISTI_ADD_ATTRIBUTE_STRING
2318////////////////////////////////////////////////////////////////////////////////
2319#define DISTI_ADD_ATTRIBUTE_STRING_CALLBACK( name, memberVarAddr, callbackFunction ) \
2320 { \
2321 typedef void ( ThisClass::*Method )(); /* Member function pointer */ \
2322 static const AttributeName attr( name ); \
2323 CallbackAttributeNotifier<ThisClass> cb( this, attr, reinterpret_cast<Method>( callbackFunction ) ); \
2324 this->Attributes().Add( new DistiAttributeEncodedStdString( &cb, attr, memberVarAddr ) ); \
2325 }
2326
2327////////////////////////////////////////////////////////////////////////////////
2328/// A macro for boilerplate code to setup an alias to an existing DisplayObject attribute.
2329/// \param aliasName The unique string name identifying the attribute.
2330/// \param origName The unique string idenfifying the attribute to create the alias from.
2331/// \param obj The object containing the origName attribute.
2332/// \sa DISTI_ADD_ATTRIBUTE
2333////////////////////////////////////////////////////////////////////////////////
2334#define DISTI_ADD_ATTRIBUTE_ALIAS( aliasName, origName, obj ) \
2335 { \
2336 static const AttributeName aliasAttr( aliasName ); \
2337 static const AttributeName origAttr( origName ); \
2338 DistiAttribDict& attributes = ( obj )->Attributes(); \
2339 this->Attributes().Add( new DistiAttributeAlias( NULL, aliasAttr, origAttr, &attributes ) ); \
2340 }
2341
2342#ifdef DISTI_HAS_CPP11
2343
2344/// \details The AttributeFnCallback class. An implementation of the AttributeObserver interface.
2345 class AttributeFnCallback : public AttributeObserver
2346{
2347 public:
2348 /// Constructor
2349 /// \note Should not be called directly, call Connect().
2350 /// \param object The object associated with this callback.
2351 /// \param func The callback function pointer to call.
2352 AttributeFnCallback( WeakReferenceable* object, std::function<void()> func )
2353 : _func( std::move( func ) )
2354 , _object( object )
2355 {
2356 GLS_VERIFY( NULL != object );
2357 }
2358
2359 void Call( DistiAttributeBase& ev ) DISTI_METHOD_OVERRIDE
2360 {
2361 if( IsValid() )
2362 {
2363 _func();
2364 }
2365 }
2366
2367 virtual bool IsValid() const DISTI_METHOD_OVERRIDE
2368 {
2369 return !_object.IsNull() && _func;
2370 }
2371
2372 protected:
2373 std::function<void()> _func; ///< The callback function pointer to call.
2374 WeakRef<WeakReferenceable> _object; ///< The object associated with this callback, callback will only be called if this object is valid.
2375};
2376
2377/// Helper function to create a new AttributeFnCallback object.
2378/// \note Should not be called directly, call Connect().
2379/// \param obj The object associated with this callback.
2380/// \param func The callback function pointer to call.
2381/// \return A new AttributeFnCallback object.
2382 inline AttributeObserver* CreateAttributeFnCallback(
2383 WeakReferenceable* const obj,
2384 const std::function<void()>& func )
2385{
2386 return new AttributeFnCallback( obj, func );
2387}
2388
2389/// Helper function to link an object, attribute, and callback via a AttributeFnCallback object.
2390/// \param obj The object containing the resource to track.
2391/// \param resource The name of the resource to track.
2392/// \param funcOwner The owner of the callback (often the same as obj).
2393/// \param func The callback function pointer to call.
2394/// \return A valid CallbackID if successful, otherwise DISTI_INVALID_CALLBACK_ID.
2395 inline DistiAttributeBase::CallbackID Connect( DisplayObject* obj, const std::string& resource, WeakReferenceable* funcOwner, std::function<void()> func )
2396{
2397 auto& res = obj->Resource( resource.c_str() );
2398 if( dynamic_cast<disti::DistiEmptyAttribute*>( &res ) )
2399 {
2400 std::cout << "Unknown attribute name: " << resource << std::endl;
2401 return DISTI_INVALID_CALLBACK_ID;
2402 }
2403
2404 return res.RegisterObserver( CreateAttributeFnCallback( funcOwner, std::move( func ) ) );
2405}
2406#endif
2407
2408/// Helper function to link an object, attribute, and callback via a CreateAttributeMethodCallback object.
2409/// \tparam Class the class of the object containing the callback.
2410/// \param obj The object containing the resource to track.
2411/// \param resource The name of the resource to track.
2412/// \param methodInstance The owner of the callback.
2413/// \param method The callback function pointer to call.
2414/// \return A valid CallbackID if successful, otherwise DISTI_INVALID_CALLBACK_ID
2415 template<class Class>
2416 DistiAttributeBase::CallbackID Connect( DisplayObject* obj, const std::string& resource, Class* const methodInstance, const typename AttributeMethodCallback<Class>::Callback method )
2417{
2418 DistiAttributeBase& res = obj->Resource( resource.c_str() );
2419 if( dynamic_cast<disti::DistiEmptyAttribute*>( &res ) )
2420 {
2421 std::cout << "Unknown attribute name: " << resource << std::endl;
2422 return DISTI_INVALID_CALLBACK_ID;
2423 }
2424 return res.RegisterObserver( CreateAttributeMethodCallback( methodInstance, method ) );
2425}
2426
2427/// Unregisters an observer by deleting the underlying callback object.
2428/// \note Does nothing if a valid observer is not found.
2429/// \param obj The object containing the resource.
2430/// \param resource The name of the resource.
2431/// \param id The CallbackID returned from a Connect() function identifying the callback to disconnect.
2432 inline void Disconnect( DisplayObject* obj, const std::string& resource, DistiAttributeBase::CallbackID id )
2433{
2434 DistiAttributeBase& res = obj->Resource( resource.c_str() );
2435 if( !dynamic_cast<disti::DistiEmptyAttribute*>( &res ) && id != DISTI_INVALID_CALLBACK_ID )
2436 {
2437 res.UnregisterObserver( id );
2438 }
2439}
2440
2441} // namespace disti
2442
2443#endif
disti::AttributeFnCallback
Definition: gls_metadata_attributes.h:2346
disti::AttributeFnCallback::AttributeFnCallback
AttributeFnCallback(WeakReferenceable *object, std::function< void()> func)
Definition: gls_metadata_attributes.h:2352
disti::AttributeFnCallback::IsValid
virtual bool IsValid() const override
Definition: gls_metadata_attributes.h:2367
disti::AttributeFnCallback::_func
std::function< void()> _func
The callback function pointer to call.
Definition: gls_metadata_attributes.h:2373
disti::AttributeFnCallback::_object
WeakRef< WeakReferenceable > _object
The object associated with this callback, callback will only be called if this object is valid.
Definition: gls_metadata_attributes.h:2374
disti::AttributeFnCallback::Call
void Call(DistiAttributeBase &ev) override
Definition: gls_metadata_attributes.h:2359
disti::AttributeMethodCallback
Definition: disti_metadata.h:424
disti::AttributeName
Definition: disti_metadata.h:87
disti::AttributeObserver
Definition: disti_metadata.h:201
disti::CallbackMethodCallerBase
Definition: callback_caller_base.h:56
disti::DisplayObject
Definition: display.h:96
disti::DisplayObject::Resource
virtual DistiAttributeBase & Resource(const char *name)
disti::DistiAttribDict
Definition: disti_metadata.h:750
disti::DistiAttribDict::Add
void Add(DistiAttributeBase *attr)
disti::DistiAttributeAlias
Definition: gls_metadata_attributes.h:1426
disti::DistiAttributeAlias::DistiAttributeAlias
DistiAttributeAlias(CallbackMethodCallerBase *callback, const AttributeName &name, const AttributeName &originalName, DistiAttribDict *dict)
Definition: gls_metadata_attributes.h:1433
disti::DistiAttributeAlphaModeEnum
Definition: gls_metadata_attributes.h:591
disti::DistiAttributeAlphaModeEnum::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:612
disti::DistiAttributeBase
Definition: disti_metadata.h:220
disti::DistiAttributeBase::RegisterObserver
virtual CallbackID RegisterObserver(AttributeObserver *observer)
disti::DistiAttributeBase::UnregisterObserver
virtual void UnregisterObserver(CallbackID id)
disti::DistiAttributeBase::_name
AttributeName _name
Definition: disti_metadata.h:226
disti::DistiAttributeBase::CallbackID
unsigned int CallbackID
Type for unique identifiers.
Definition: disti_metadata.h:401
disti::DistiAttributeColorMaterialModeEnum
Definition: gls_metadata_attributes.h:507
disti::DistiAttributeColorMaterialModeEnum::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:539
disti::DistiAttributeColorMaterialModeEnum::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_metadata_attributes.h:537
disti::DistiAttributeDictionaryAttributeSibling
Definition: gls_metadata_attributes.h:803
disti::DistiAttributeDictionaryAttributeSibling::_hasRead
bool _hasRead
If true, ReadValue will be called on the sibling when ReadValue is called on this attribute.
Definition: gls_metadata_attributes.h:807
disti::DistiAttributeDictionaryAttributeSibling::Type
std::string Type() const override
disti::DistiAttributeDictionaryAttributeSibling::DistiAttributeDictionaryAttributeSibling
DistiAttributeDictionaryAttributeSibling(const AttributeName &name, DistiAttribDict *dict, DistiAttributeBase *sibling)
disti::DistiAttributeDictionaryAttributeSibling::_dict
DistiAttribDict * _dict
An observing pointer to a dictionary of attributes.
Definition: gls_metadata_attributes.h:805
disti::DistiAttributeDictionaryAttributeSibling::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
disti::DistiAttributeDictionaryAttributeSibling::OkToWrite
virtual bool OkToWrite() const override
disti::DistiAttributeDictionaryAttributeSibling::_sibling
DistiAttributeBase * _sibling
An observing pointer to this attribute's sibling.
Definition: gls_metadata_attributes.h:806
disti::DistiAttributeDictionaryAttributeSibling::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
disti::DistiAttributeDictionaryAttribute
Definition: gls_metadata_attributes.h:779
disti::DistiAttributeDictionaryAttribute::Type
std::string Type() const override
disti::DistiAttributeDictionaryAttribute::_dict
DistiAttribDict * _dict
An observing pointer to a dictionary of attributes.
Definition: gls_metadata_attributes.h:781
disti::DistiAttributeDictionaryAttribute::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
disti::DistiAttributeDictionaryAttribute::DistiAttributeDictionaryAttribute
DistiAttributeDictionaryAttribute(const AttributeName &name, DistiAttribDict *dict)
disti::DistiAttributeDictionaryAttribute::OkToWrite
virtual bool OkToWrite() const override
disti::DistiAttributeDictionaryAttribute::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
disti::DistiAttributeDoubleArray
Definition: gls_metadata_attributes.h:293
disti::DistiAttributeDoubleArray::DistiAttributeDoubleArray
DistiAttributeDoubleArray(CallbackMethodCallerBase *callback, const AttributeName &name, double *doubleArray, int length)
disti::DistiAttributeDoubleArray::OkToWrite
virtual bool OkToWrite() const override
disti::DistiAttributeDynamicArray
Definition: gls_metadata_attributes.h:1468
disti::DistiAttributeDynamicArray::OkToWrite
bool OkToWrite() const override
Definition: gls_metadata_attributes.h:1498
disti::DistiAttributeDynamicArray::ReadValue
std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:1528
disti::DistiAttributeDynamicArray::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:1548
disti::DistiAttributeDynamicArray::DistiAttributeDynamicArray
DistiAttributeDynamicArray(CallbackMethodCallerBase *callback, const AttributeName &name)
Definition: gls_metadata_attributes.h:1485
disti::DistiAttributeDynamicArray::WriteValue
std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:1503
disti::DistiAttributeDynamicArray::DistiAttributeDynamicArray
DistiAttributeDynamicArray(CallbackMethodCallerBase *callback, const AttributeName &name, T *attribPtr)
Definition: gls_metadata_attributes.h:1476
disti::DistiAttributeEncodedStdString
Definition: gls_metadata_attributes.h:686
disti::DistiAttributeEncodedStdString::DistiAttributeEncodedStdString
DistiAttributeEncodedStdString(CallbackMethodCallerBase *callback, const AttributeName &name, std::string initialValue)
disti::DistiAttributeEncodedStdString::OkToWrite
bool OkToWrite() const override
disti::DistiAttributeEncodedStdString::DistiAttributeEncodedStdString
DistiAttributeEncodedStdString(CallbackMethodCallerBase *callback, const AttributeName &name, std::string *attribPtr)
disti::DistiAttributeEncodedString
Definition: gls_metadata_attributes.h:659
disti::DistiAttributeEncodedString::DistiAttributeEncodedString
DistiAttributeEncodedString(CallbackMethodCallerBase *callback, const AttributeName &name, char **attribPtr)
disti::DistiAttributeEncodedString::DistiAttributeEncodedString
DistiAttributeEncodedString(CallbackMethodCallerBase *callback, const AttributeName &name, char *initialValue)
disti::DistiAttributeEncodedString::ValueString
virtual std::string ValueString() override
disti::DistiAttributeEnumDefList
Definition: disti_metadata.h:1002
disti::DistiAttributeEnumDirect
Definition: gls_metadata_attributes.h:2069
disti::DistiAttributeEnumDirect::ValueInt
virtual void ValueInt(long val) override
Definition: gls_metadata_attributes.h:2111
disti::DistiAttributeEnumDirect::_attribPtr
enumType * _attribPtr
Underlying storage for this attribute.
Definition: gls_metadata_attributes.h:2071
disti::DistiAttributeEnumDirect::_pairList
DistiAttributeEnumDefList * _pairList
Observing pointer to the enum string to integer conversion data.
Definition: gls_metadata_attributes.h:2074
disti::DistiAttributeEnumDirect::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:2200
disti::DistiAttributeEnumDirect::DistiAttributeEnumDirect
DistiAttributeEnumDirect(CallbackMethodCallerBase *callback, const AttributeName &name, enumType *attribPtr, DistiAttributeEnumDefList *pairList)
Definition: gls_metadata_attributes.h:2081
disti::DistiAttributeEnumDirect::DistiAttributeEnumDirect
DistiAttributeEnumDirect(CallbackMethodCallerBase *callback, const AttributeName &name, const enumType &value, DistiAttributeEnumDefList *pairList)
Definition: gls_metadata_attributes.h:2093
disti::DistiAttributeEnumDirect::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:2162
disti::DistiAttributeEnumDirect::ValueInt
virtual long ValueInt() override
Definition: gls_metadata_attributes.h:2107
disti::DistiAttributeEnumDirect::operator=
virtual DistiAttributeBase & operator=(const DistiAttributeBase &oldClass) override
Definition: gls_metadata_attributes.h:2116
disti::DistiAttributeEnumDirect::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:2134
disti::DistiAttributeEnum
Definition: disti_metadata.h:1021
disti::DistiAttributeFixedString
Definition: gls_metadata_attributes.h:713
disti::DistiAttributeFixedString::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
disti::DistiAttributeFixedString::DistiAttributeFixedString
DistiAttributeFixedString(CallbackMethodCallerBase *callback, const AttributeName &name, char *string, int length)
disti::DistiAttributeFixedString::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
disti::DistiAttributeFloatArray
Definition: gls_metadata_attributes.h:268
disti::DistiAttributeFloatArray::DistiAttributeFloatArray
DistiAttributeFloatArray(CallbackMethodCallerBase *callback, const AttributeName &name, float *floatArray, int length)
disti::DistiAttributeFloatArray::OkToWrite
virtual bool OkToWrite() const override
disti::DistiAttributeHomogeneousItemArray
Definition: gls_metadata_attributes.h:1661
disti::DistiAttributeHomogeneousItemArray::DistiAttributeHomogeneousItemArray
DistiAttributeHomogeneousItemArray(const AttributeName &name, DynamicArray< T * > *array, CreateItemCb createCb)
Definition: gls_metadata_attributes.h:1675
disti::DistiAttributeHomogeneousItemArray::_createCb
CreateItemCb _createCb
Function pointer called to create new items in the list.
Definition: gls_metadata_attributes.h:1667
disti::DistiAttributeHomogeneousItemArray::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:1731
disti::DistiAttributeHomogeneousItemArray::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:1706
disti::DistiAttributeHomogeneousItemArray::_array
DynamicArray< T * > * _array
Underlying storage for this attribute.
Definition: gls_metadata_attributes.h:1666
disti::DistiAttributeHomogeneousItemArray::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_metadata_attributes.h:1684
disti::DistiAttributeHomogeneousItemArray::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:1686
disti::DistiAttributeLocation
Definition: gls_metadata_attributes.h:763
disti::DistiAttributeLocation::DistiAttributeLocation
DistiAttributeLocation(CallbackMethodCallerBase *callback, const AttributeName &name, Vertex *attribPtr)
disti::DistiAttributeLocation::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
disti::DistiAttributeLocation::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
disti::DistiAttributeNeverWrite
Definition: gls_metadata_attributes.h:1370
disti::DistiAttributeNeverWrite::DistiAttributeNeverWrite
DistiAttributeNeverWrite(CallbackMethodCallerBase *callback, const AttributeName &name, const T &initialValue)
Definition: gls_metadata_attributes.h:1385
disti::DistiAttributeNeverWrite::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_metadata_attributes.h:1390
disti::DistiAttributeNeverWrite::DistiAttributeNeverWrite
DistiAttributeNeverWrite(CallbackMethodCallerBase *callback, const AttributeName &name, T *attribPtr)
Definition: gls_metadata_attributes.h:1376
disti::DistiAttributePolyEndEnum
Definition: gls_metadata_attributes.h:441
disti::DistiAttributePolyEndEnum::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:462
disti::DistiAttributePolyModeEnum
Definition: gls_metadata_attributes.h:405
disti::DistiAttributePolyModeEnum::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:426
disti::DistiAttributeProperty
Definition: gls_metadata_attributes.h:1752
disti::DistiAttributeProperty::ValueInt
virtual void ValueInt(long val) override
Definition: gls_metadata_attributes.h:1796
disti::DistiAttributeProperty::ValueFloat
virtual double ValueFloat() override
Definition: gls_metadata_attributes.h:1798
disti::DistiAttributeProperty::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:1858
disti::DistiAttributeProperty::Value
virtual T Value() override
Definition: gls_metadata_attributes.h:1863
disti::DistiAttributeProperty::ValueString
virtual std::string ValueString() override
Definition: gls_metadata_attributes.h:1792
disti::DistiAttributeProperty::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:1831
disti::DistiAttributeProperty::ValueString
virtual void ValueString(const std::string &s) override
Definition: gls_metadata_attributes.h:1793
disti::DistiAttributeProperty::Value
virtual void Value(const T &val) override
Definition: gls_metadata_attributes.h:1880
disti::DistiAttributeProperty::ValueFloat
virtual void ValueFloat(double val) override
Definition: gls_metadata_attributes.h:1799
disti::DistiAttributeProperty::ValueInt
virtual long ValueInt() override
Definition: gls_metadata_attributes.h:1795
disti::DistiAttributeProperty::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_metadata_attributes.h:1786
disti::DistiAttributeProperty::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:1801
disti::DistiAttributeProtectionEnum
Definition: gls_metadata_attributes.h:548
disti::DistiAttributeProtectionEnum::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:574
disti::DistiAttributeShadingEnum
Definition: gls_metadata_attributes.h:477
disti::DistiAttributeShadingEnum::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:498
disti::DistiAttributeStdMap
Definition: gls_metadata_attributes.h:835
disti::DistiAttributeStdMap::DistiAttributeStdMap
DistiAttributeStdMap(CallbackMethodCallerBase *callback, const AttributeName &name, Map_t *attribPtr)
Definition: gls_metadata_attributes.h:843
disti::DistiAttributeStdMap::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:958
disti::DistiAttributeStdMap::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:904
disti::DistiAttributeStdMap::DistiAttributeStdMap
DistiAttributeStdMap(CallbackMethodCallerBase *callback, const AttributeName &name)
Definition: gls_metadata_attributes.h:853
disti::DistiAttributeStdMap::GetEmptyValue
static std::string GetEmptyValue()
Definition: gls_metadata_attributes.h:872
disti::DistiAttributeStdMap::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_metadata_attributes.h:866
disti::DistiAttributeStdMap::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:874
disti::DistiAttributeStdStringNeverWrite
Definition: gls_metadata_attributes.h:1398
disti::DistiAttributeStdStringNeverWrite::DistiAttributeStdStringNeverWrite
DistiAttributeStdStringNeverWrite(CallbackMethodCallerBase *callback, const AttributeName &name, const std::string &initialValue)
Definition: gls_metadata_attributes.h:1413
disti::DistiAttributeStdStringNeverWrite::DistiAttributeStdStringNeverWrite
DistiAttributeStdStringNeverWrite(CallbackMethodCallerBase *callback, const AttributeName &name, std::string *attribPtr)
Definition: gls_metadata_attributes.h:1404
disti::DistiAttributeStdStringNeverWrite::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_metadata_attributes.h:1418
disti::DistiAttributeStdString
Definition: gls_metadata_attributes.h:733
disti::DistiAttributeStdString::DistiAttributeStdString
DistiAttributeStdString(CallbackMethodCallerBase *callback, const AttributeName &name, std::string *attribPtr)
disti::DistiAttributeStdString::DistiAttributeStdString
DistiAttributeStdString(CallbackMethodCallerBase *callback, const AttributeName &name, std::string initialValue)
disti::DistiAttributeStdString::OkToWrite
virtual bool OkToWrite() const override
disti::DistiAttributeStdString::LocalStorageString
std::string * LocalStorageString()
disti::DistiAttributeStdVector
Definition: gls_metadata_attributes.h:1560
disti::DistiAttributeStdVector::DistiAttributeStdVector
DistiAttributeStdVector(CallbackMethodCallerBase *callback, const AttributeName &name)
Definition: gls_metadata_attributes.h:1580
disti::DistiAttributeStdVector::DistiAttributeStdVector
DistiAttributeStdVector(CallbackMethodCallerBase *callback, const AttributeName &name, T *attribPtr)
Definition: gls_metadata_attributes.h:1571
disti::DistiAttributeStdVector::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:1649
disti::DistiAttributeStdVector::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:1625
disti::DistiAttributeStdVector::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_metadata_attributes.h:1595
disti::DistiAttributeStdVector::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:1600
disti::DistiAttributeString
Definition: gls_metadata_attributes.h:621
disti::DistiAttributeString::DistiAttributeString
DistiAttributeString(CallbackMethodCallerBase *callback, const AttributeName &name, char **attribPtr)
disti::DistiAttributeString::LocalStorageString
char * LocalStorageString()
disti::DistiAttributeString::DistiAttributeString
DistiAttributeString(CallbackMethodCallerBase *callback, const AttributeName &name, char *initialValue)
disti::DistiAttributeString::_attribPtr
char ** _attribPtr
A pointer to the pointer containing the underlying storage for this attribute.
Definition: gls_metadata_attributes.h:625
disti::DistiAttributeString::OkToWrite
virtual bool OkToWrite() const override
disti::DistiAttributeTextureFilterEnum
Definition: gls_metadata_attributes.h:366
disti::DistiAttributeTextureFilterEnum::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:387
disti::DistiAttributeTextureModeEnum
Definition: gls_metadata_attributes.h:326
disti::DistiAttributeTextureModeEnum::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:347
disti::DistiAttributeTexturePointArray
Definition: gls_metadata_attributes.h:1315
disti::DistiAttributeTexturePointArray::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:1339
disti::DistiAttributeTexturePointArray::DistiAttributeTexturePointArray
DistiAttributeTexturePointArray(CallbackMethodCallerBase *callback, const AttributeName &name, Vector *attribPtr, unsigned int numElements)
Definition: gls_metadata_attributes.h:1322
disti::DistiAttributeTexturePointArray::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:1327
disti::DistiAttributeUCharOrBool
Definition: gls_metadata_attributes.h:242
disti::DistiAttributeUCharOrBool::DistiAttributeUCharOrBool
DistiAttributeUCharOrBool(CallbackMethodCallerBase *callback, const AttributeName &name, unsigned char *attribPtr)
disti::DistiAttributeUCharOrBool::ValueInt
virtual long ValueInt() override
disti::DistiAttributeUCharOrBool::operator=
virtual DistiAttributeBase & operator=(const DistiAttributeBase &oldClass) override
disti::DistiAttributeUCharOrBool::DistiAttributeUCharOrBool
DistiAttributeUCharOrBool(CallbackMethodCallerBase *callback, const AttributeName &name, unsigned char value)
disti::DistiAttributeVertexArray< Vertex >
Definition: gls_metadata_attributes.h:1150
disti::DistiAttributeVertexArray< Vertex >::Tptr
Vertex * Tptr
Shorthand typedef for a pointer to a vertex.
Definition: gls_metadata_attributes.h:1153
disti::DistiAttributeVertexArray< Vertex >::SetCompatabilityMode
void SetCompatabilityMode(bool mode)
Definition: gls_metadata_attributes.h:1162
disti::DistiAttributeVertexArray< Vertex >::_numVertices
unsigned int * _numVertices
The number of vertices in a variable length array.
Definition: gls_metadata_attributes.h:1154
disti::DistiAttributeVertexArray< Vertex >::DistiAttributeVertexArray
DistiAttributeVertexArray(CallbackMethodCallerBase *callback, const AttributeName &name, Vertex *attribPtr, unsigned int numElements)
Definition: gls_metadata_attributes.h:1184
disti::DistiAttributeVertexArray< Vertex >::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:1305
disti::DistiAttributeVertexArray< Vertex >::_fixedArray
bool _fixedArray
If true, this array is not resizable.
Definition: gls_metadata_attributes.h:1156
disti::DistiAttributeVertexArray< Vertex >::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:1227
disti::DistiAttributeVertexArray< Vertex >::_attribPtr
Vertex ** _attribPtr
Underlying storage for this attribute.
Definition: gls_metadata_attributes.h:1152
disti::DistiAttributeVertexArray< Vertex >::_numElements
unsigned int _numElements
The number of vertices in a fixed length array.
Definition: gls_metadata_attributes.h:1155
disti::DistiAttributeVertexArray< Vertex >::operator==
virtual bool operator==(const DistiAttributeBase &rArg) override
Definition: gls_metadata_attributes.h:1281
disti::DistiAttributeVertexArray< Vertex >::_compatabilityMode
bool _compatabilityMode
If true, backward compatibility mode will be used, values will be read with scanf.
Definition: gls_metadata_attributes.h:1157
disti::DistiAttributeVertexArray< Vertex >::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_metadata_attributes.h:1201
disti::DistiAttributeVertexArray< Vertex >::DistiAttributeVertexArray
DistiAttributeVertexArray(CallbackMethodCallerBase *callback, const AttributeName &name, Vertex **attribPtr, unsigned int *numVertices)
Definition: gls_metadata_attributes.h:1169
disti::DistiAttributeVertexArray< Vertex >::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:1206
disti::DistiAttributeVertexArray
Definition: gls_metadata_attributes.h:973
disti::DistiAttributeVertexArray::SetCompatabilityMode
void SetCompatabilityMode(bool mode)
Definition: gls_metadata_attributes.h:985
disti::DistiAttributeVertexArray::_attribPtr
T ** _attribPtr
Underlying storage for this attribute.
Definition: gls_metadata_attributes.h:975
disti::DistiAttributeVertexArray::_numVertices
unsigned int * _numVertices
The number of vertices in a variable length array.
Definition: gls_metadata_attributes.h:977
disti::DistiAttributeVertexArray::Type
std::string Type() const override
Definition: gls_metadata_attributes.h:1141
disti::DistiAttributeVertexArray::DistiAttributeVertexArray
DistiAttributeVertexArray(CallbackMethodCallerBase *callback, const AttributeName &name, T **attribPtr, unsigned int *numVertices)
Definition: gls_metadata_attributes.h:992
disti::DistiAttributeVertexArray::DistiAttributeVertexArray
DistiAttributeVertexArray(CallbackMethodCallerBase *callback, const AttributeName &name, T *attribPtr, unsigned int numElements)
Definition: gls_metadata_attributes.h:1007
disti::DistiAttributeVertexArray::Tptr
T * Tptr
Shorthand typedef for a pointer to the template type.
Definition: gls_metadata_attributes.h:976
disti::DistiAttributeVertexArray::_fixedArray
bool _fixedArray
If true, this array is not resizable.
Definition: gls_metadata_attributes.h:979
disti::DistiAttributeVertexArray::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:1057
disti::DistiAttributeVertexArray::_numElements
unsigned int _numElements
The number of vertices in a fixed length array.
Definition: gls_metadata_attributes.h:978
disti::DistiAttributeVertexArray::operator==
virtual bool operator==(const DistiAttributeBase &rArg) override
Definition: gls_metadata_attributes.h:1113
disti::DistiAttributeVertexArray::_compatabilityMode
bool _compatabilityMode
If true, backward compatibility mode will be used, values will be read with scanf.
Definition: gls_metadata_attributes.h:980
disti::DistiAttributeVertexArray::OkToWrite
virtual bool OkToWrite() const override
Definition: gls_metadata_attributes.h:1025
disti::DistiAttributeVertexArray::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:1033
disti::DistiAttribute
Definition: disti_metadata.h:554
disti::DistiAttribute::ReadValue
std::istream & ReadValue(std::istream &instr) override
Definition: disti_metadata.h:654
disti::DistiAttribute::WriteValue
std::ostream & WriteValue(std::ostream &outstr) override
Definition: disti_metadata.h:641
disti::DistiAttribute::ValueInt
long ValueInt() override
Definition: disti_metadata.h:594
disti::DistiEmptyAttribute
Definition: gls_metadata_attributes.h:2044
disti::DistiEmptyAttribute::ReadValue
virtual std::istream & ReadValue(std::istream &instr) override
Definition: gls_metadata_attributes.h:2058
disti::DistiEmptyAttribute::WriteValue
virtual std::ostream & WriteValue(std::ostream &outstr) override
Definition: gls_metadata_attributes.h:2052
disti::DynamicArray< T * >
disti::DynamicArray::Count
unsigned Count() const
Definition: dynamic_array.h:218
disti::DynamicArray::Back
T & Back()
Definition: dynamic_array.h:357
disti::DynamicArray::PushBack
unsigned PushBack(const T &object)
Definition: dynamic_array.h:340
disti::VertexNoColor
Definition: vertex.h:85
disti::VertexNoColor::y
float y
The Y component.
Definition: vertex.h:88
disti::VertexNoColor::x
float x
The X component.
Definition: vertex.h:87
disti::VertexNoColor::z
float z
The Z component.
Definition: vertex.h:89
disti::Vertex
Definition: vertex.h:420
disti::Vertex::color
GlsColor color
The RGBA color component.
Definition: vertex.h:422
disti::WeakRef
Definition: weak_reference.h:92
disti::WeakReferenceable
Definition: weak_reference.h:65
display.h
The disti::DisplayObject class and global enumerations.
GLS_VERIFY
#define GLS_VERIFY(exp)
Definition: disti_assert.h:170
disti_metadata.h
The disti metadata.
dynamic_array.h
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
DISTI_DEPRECATED
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:488
DISTI_METHOD_OVERRIDE
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:222
gls_include.h
A file for all GL Studio files to include.
GLS_EXPORT
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
list.h
The List_c class. Generic linked list.
material.h
The disti::Material class.
disti
Definition: bmpimage.h:47
disti::CreateDistiAttributeProperty
DistiAttributeProperty< Class, GetReturnT, SetArgT > * CreateDistiAttributeProperty(const AttributeName &attrName, Class *const obj, const typename DistiAttributeProperty< Class, GetReturnT, SetArgT >::SetMethodType setMethod, const typename DistiAttributeProperty< Class, GetReturnT, SetArgT >::GetMethodType getMethod)
Definition: gls_metadata_attributes.h:2012
disti::Equal
bool Equal(T1 x, T2 y, float precision=0.001f)
Definition: util.h:495
disti::TEXTURE_MAP_BLEND
@ TEXTURE_MAP_BLEND
Definition: display_types.h:56
disti::TEXTURE_MAP_DECAL
@ TEXTURE_MAP_DECAL
Definition: display_types.h:55
disti::TEXTURE_MAP_MODULATE
@ TEXTURE_MAP_MODULATE
Definition: display_types.h:54
disti::TEXTURE_MAP_REPLACE
@ TEXTURE_MAP_REPLACE
Definition: display_types.h:57
disti::TEXTURE_FILTER_NEAREST
@ TEXTURE_FILTER_NEAREST
Definition: display_types.h:63
disti::TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR
@ TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR
Definition: display_types.h:66
disti::TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST
@ TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST
Definition: display_types.h:65
disti::TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST
@ TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST
Definition: display_types.h:68
disti::TEXTURE_FILTER_LINEAR
@ TEXTURE_FILTER_LINEAR
Definition: display_types.h:64
disti::TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR
@ TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR
Definition: display_types.h:67
disti::POLY_MODE_FILLED
@ POLY_MODE_FILLED
Definition: display_types.h:86
disti::POLY_MODE_POINTS
@ POLY_MODE_POINTS
Definition: display_types.h:84
disti::POLY_MODE_OUTLINE
@ POLY_MODE_OUTLINE
Definition: display_types.h:85
disti::POLY_MODE_UNDEFINED
@ POLY_MODE_UNDEFINED
Definition: display_types.h:83
disti::POLY_MODE_FILL_AND_OUTLINE
@ POLY_MODE_FILL_AND_OUTLINE
Definition: display_types.h:87
disti::CreateAttributeFnCallback
AttributeObserver * CreateAttributeFnCallback(WeakReferenceable *const obj, const std::function< void()> &func)
Definition: gls_metadata_attributes.h:2382
disti::ALPHA_MODE_256_LEVEL
@ ALPHA_MODE_256_LEVEL
Definition: display_types.h:96
disti::ALPHA_MODE_UNDEFINED
@ ALPHA_MODE_UNDEFINED
Definition: display_types.h:93
disti::ALPHA_MODE_2_LEVEL
@ ALPHA_MODE_2_LEVEL
Definition: display_types.h:95
disti::ALPHA_MODE_OPAQUE
@ ALPHA_MODE_OPAQUE
Definition: display_types.h:94
disti::Disconnect
void Disconnect(DisplayObject *obj, const std::string &resource, DistiAttributeBase::CallbackID id)
Definition: gls_metadata_attributes.h:2432
disti::EMISSION_COLOR_MATERIAL
@ EMISSION_COLOR_MATERIAL
Definition: display_types.h:146
disti::NO_COLOR_MATERIAL
@ NO_COLOR_MATERIAL
Definition: display_types.h:142
disti::DIFFUSE_COLOR_MATERIAL
@ DIFFUSE_COLOR_MATERIAL
Definition: display_types.h:143
disti::SPECULAR_COLOR_MATERIAL
@ SPECULAR_COLOR_MATERIAL
Definition: display_types.h:147
disti::DIFFUSE_AND_AMBIENT_COLOR_MATERIAL
@ DIFFUSE_AND_AMBIENT_COLOR_MATERIAL
Definition: display_types.h:145
disti::AMBIENT_COLOR_MATERIAL
@ AMBIENT_COLOR_MATERIAL
Definition: display_types.h:144
disti::CreateDistiAttributePropertyVertexToVector
DistiAttributeProperty< Class, Vector, const Vertex &, const Vertex & > * CreateDistiAttributePropertyVertexToVector(const AttributeName &attrName, Class *const obj, const typename DistiAttributeProperty< Class, Vector, const Vertex &, const Vertex & >::SetMethodType setMethod, const typename DistiAttributeProperty< Class, Vector, const Vertex &, const Vertex & >::GetMethodConstType getMethod)
Definition: gls_metadata_attributes.h:2030
disti::CreateAttributeMethodCallback
AttributeObserver * CreateAttributeMethodCallback(Class *const obj, const typename AttributeMethodCallback< Class >::Callback method)
Definition: disti_metadata.h:462
disti::DISTI_INVALID_CALLBACK_ID
const DistiAttributeBase::CallbackID DISTI_INVALID_CALLBACK_ID
Value to represent that a given callback was not successfully created.
Definition: gls_metadata_attributes.h:72
disti::operator==
bool operator==(const AttributeName &attr1, const AttributeName &attr2)
Definition: disti_metadata.h:154
disti::ReadValueAsIntOrBool
T ReadValueAsIntOrBool(std::istream &instr)
Definition: gls_metadata_attributes.h:96
disti::PRIVATE
@ PRIVATE
Definition: display_types.h:117
disti::PROTECTED
@ PROTECTED
Definition: display_types.h:118
disti::PUBLIC
@ PUBLIC
Definition: display_types.h:116
disti::SHADING_FLAT
@ SHADING_FLAT
Definition: display_types.h:109
disti::SHADING_GOURAUD
@ SHADING_GOURAUD
Definition: display_types.h:110
disti::Connect
DistiAttributeBase::CallbackID Connect(DisplayObject *obj, const std::string &resource, Class *const methodInstance, const typename AttributeMethodCallback< Class >::Callback method)
Definition: gls_metadata_attributes.h:2416
disti::POLY_OPEN
@ POLY_OPEN
Definition: display_types.h:102
disti::POLY_CLOSED
@ POLY_CLOSED
Definition: display_types.h:103
disti::ConvertToIntOrBool
T ConvertToIntOrBool(int value)
Definition: gls_metadata_attributes.h:78
util.h
Generally useful defines, macros, enumerations and function prototypes.
vertex.h
The disti::Vertex class. A class for manipulating 3D vertices.