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