HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_AttributeRef.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __PDG_ATTRIBUTE_REF_H__
10 #define __PDG_ATTRIBUTE_REF_H__
11 
12 #include "PDG_API.h"
13 
15 #include "PDG_AttributeFile.h"
16 #include "PDG_AttributeGeometry.h"
17 #include "PDG_AttributeHolder.h"
18 #include "PDG_AttributePrimitive.h"
19 #include "PDG_AttributePyObject.h"
20 #include "PDG_AttributeQuery.h"
21 #include "PDG_AttributeTypes.h"
22 
23 #include <UT/UT_Options.h>
24 #include <UT/UT_StringHolder.h>
25 #include <UT/UT_WorkBuffer.h>
26 
27 class PDG_AttributeOwner;
28 class PDG_Node;
29 
30 /**
31  * Base class for attribute references
32  */
34 {
35 public:
37  const PDG_AttributeOwner* owner,
40  : myName(name)
41  , myOwner(owner)
42  , myError(error)
43  {
44  }
45 
46  /// Returns true if the handle is valid
47  inline operator bool() const
48  { return isValid(); }
49 
50  /// Returns true if the handle is valid
51  inline bool isValid() const
52  { return (myError == PDG_AttributeError::eNone);}
53 
54  /// Returns the error state of the handle
55  inline PDG_AttributeError error() const
56  { return myError; }
57 
58  /// Returns the name of the attribute referenced by this attrib ref
59  inline const UT_StringHolder&
60  name() const
61  { return myName; }
62 
63  /// Returns the PDG_AttributeOwner that owns the underlying attribute
64  const PDG_AttributeOwner* owner() const
65  { return myOwner; }
66 
67  /// Returns false and Writes an attribute error message into the buffer if
68  /// an error exists, or returns trues and does not modify the buffer if no
69  /// error has been recorded.
70  bool validate(UT_WorkBuffer& buffer) const;
71 
72  /// Same as above, except the attribute error is reported on the specified
73  /// node instead of returned as a buffer, if an error has occured. The
74  /// method still returns true if no error has occured, and false if one
75  /// has.
76  ///
77  /// The report_errors argument is provided as a convenience, to make it
78  /// possible to parametrically skip error reporting
79  bool validate(
80  const PDG_Node* node,
81  bool report_errors=true,
82  bool as_warning=false) const;
83 
84  /// Writes an attribute error format message to the buffer, based on the
85  /// supply error, attrib name and optional work item. Returns True if no
86  /// error is detected, or false if an error occured.
87  static bool attributeError(
90  const UT_StringHolder& attrib_name,
91  const PDG_AttributeOwner* owner=nullptr);
92 
93  /// Emits events when the attribute is modified
94  static void attributeModified(
95  const PDG_AttributeOwner* owner,
96  PDG_AttributeType attrib_type,
97  const UT_StringHolder& attrib_name);
98 
99 protected:
103 };
104 
105 /**
106  * Base class for templated attribute references
107  */
108 template <typename Attribute, typename Holder>
110 {
111 public:
113 
114 public:
115  explicit PDG_AttributeRefT(Holder* holder,
116  const UT_StringHolder& name,
117  const PDG_AttributeOwner* owner,
120  : PDG_AttributeRef(name, owner, error)
121  , myHolder(holder)
122  {
123  }
124 
125  /// Returns the underlying attribute holder
126  inline Holder* holder() const
127  {
128  return myHolder;
129  }
130 
131  /// Returns a const pointer to the underlying attribute instance
132  inline const Attribute* attribute() const
133  {
134  return myHolder->template attribute<const Attribute>();
135  }
136 
137  /// Returns a const pointer to the underlying attribute instance,
138  /// casted to the specified type
139  template <typename T> const T* attributeT() const
140  {
141  return myHolder->template attribute<const T>();
142  }
143 
144  /// Returns a const pointer to the underlying attribute instance
145  inline const Attribute* operator->() const
146  {
147  return attribute();
148  }
149 
150  /// Returns true if the contained attribute has any data
151  inline bool hasData() const
152  {
153  return myHolder->template hasData<Attribute>();
154  }
155 
156  /// Returns true if the contained attribute holder owns its data
157  inline bool isOwner() const
158  {
159  return myHolder->isOwner();
160  }
161 
162  /// Returns the type of the contained attribute
163  inline PDG_AttributeType type() const
164  {
165  return myHolder->type();
166  }
167 
168  /// Returns the flags on the contained holder
169  inline uint16 flags() const
170  {
171  return myHolder->flags();
172  }
173 
174  /// Returns true if the contained holder has any flags set
175  inline bool hasAnyFlags() const
176  {
177  return myHolder->hasAnyFlags();
178  }
179 
180  /// Returns true if the contained holder has the specified flag set
181  inline bool hasFlag(PDG_AttributeFlag flag) const
182  {
183  return myHolder->hasFlag(flag);
184  }
185 
186  /// Returns true if the contained holder has all of the specified flags set
187  inline bool hasFlags(uint16 flags) const
188  {
189  return myHolder->hasFlags(flags);
190  }
191 
192  /// Returns true if the contained holder has any of the specified flags set
193  inline bool hasAnyFlags(uint16 flags) const
194  {
195  return myHolder->hasAnyFlags(flags);
196  }
197 
198  /// Returns true if the attribute is numeric
199  inline bool isNumeric() const
200  {
201  return (myHolder->type() == PDG_AttributeType::eIntegerArray) ||
202  (myHolder->type() == PDG_AttributeType::eFloatArray);
203  }
204 
205  /// Returns true if the attribute is an array
206  inline bool isArray() const
207  {
208  return (myHolder->type() == PDG_AttributeType::eIntegerArray) ||
209  (myHolder->type() == PDG_AttributeType::eFloatArray) ||
210  (myHolder->type() == PDG_AttributeType::eStringArray) ||
211  (myHolder->type() == PDG_AttributeType::eFileArray) ||
212  (myHolder->type() == PDG_AttributeType::eDictArray);
213  }
214 
215  /// Casts the value contained in the attribute at the particular index to a
216  /// numeric value, by looking up the value with the query string. Falls
217  /// a regular cast if query strings aren't supported
219  const PDG_AttributeQuery& query,
220  int index,
221  bool has_component) const
222  {
223  if (myHolder->type() == PDG_AttributeType::ePythonObject)
224  {
225  if (!has_component)
226  index = -1;
227  return myHolder->template attribute<PDG_AttributePyObject>()->query(
228  number, query, index);
229  }
230  else if (myHolder->type() == PDG_AttributeType::eDictArray)
231  {
232  if (!has_component)
233  index = 0;
234  return myHolder->template attribute<PDG_AttributeDictionary>()->query(
235  number, query, index);
236  }
237 
238  return asNumber(number, index);
239  }
240 
241  /// Casts the value contained in the attribute at the particular index to a
242  /// numeric value, if possible.
243  inline PDG_AttributeCast asNumber(fpreal& number, int index) const
244  {
245  if (myHolder->type() == PDG_AttributeType::eIntegerArray)
246  {
248  if (myHolder->template attribute<PDG_AttributeInteger>()->value(
249  temp, index))
250  {
251  number = temp;
253  }
254 
256  }
257  else if (myHolder->type() == PDG_AttributeType::eFloatArray)
258  {
259  if (myHolder->template attribute<PDG_AttributeFloat>()->value(
260  number, index))
261  {
263  }
264 
266  }
267 
269  }
270 
271  /// Casts the value contained in the attribute to a PDG_File object. Only
272  /// valid for string, file and PyObject attribute types
274  PDG_File& file,
275  int index,
276  const UT_StringHolder& tag =
278  PDG_File::Hash hash = 0,
279  bool own = false) const
280  {
281  UT_StringHolder file_path;
282  UT_StringHolder file_tag = tag;
283  PDG_File::Hash file_hash = hash;
284 
285  switch (myHolder->type())
286  {
288  {
289  if (!myHolder->template attribute<PDG_AttributePyObject>()->str(
290  file_path))
291  {
293  }
294 
295  break;
296  }
297 
299  {
300  if (!myHolder->template attribute<PDG_AttributeString>()->value(
301  file_path, index))
302  {
304  }
305 
306  break;
307  }
308 
310  {
312  if (myHolder->template attribute<PDG_AttributeFile>()->value(
313  temp, index))
314  {
315  file_path = temp.data();
316 
317  if (file_tag.isEmpty())
318  file_tag = temp.tag();
319 
320  if (!file_hash)
321  file_hash = temp.hash();
322 
323  break;
324  }
325 
327  }
328 
329  default:
331  }
332 
333  file = PDG_File(file_path, file_tag, file_hash, own);
335  }
336 
337  /// Casts the value contained in the attribute at the particular index to a
338  /// string value, by looking up the value with the query string. Falls
339  /// a regular cast if query strings aren't supported
341  const PDG_AttributeQuery& query,
342  int index,
343  int pad,
344  bool has_component) const
345  {
346  if (myHolder->type() == PDG_AttributeType::ePythonObject)
347  {
348  if (!has_component)
349  index = -1;
350  return myHolder->template attribute<PDG_AttributePyObject>()->query(
351  buffer, query, index);
352  }
353  else if (myHolder->type() == PDG_AttributeType::eDictArray)
354  {
355  if (!has_component)
356  index = 0;
357  return myHolder->template attribute<PDG_AttributeDictionary>()->query(
358  buffer, query, index);
359  }
360 
361  return asString(buffer, index, pad);
362  }
363 
364  /// Casts the value contained in the attribute at the particular index to a
365  /// string value, if possible.
367  int index,
368  int pad=0) const
369  {
370  switch (myHolder->type())
371  {
373  {
375  if (myHolder->template attribute<PDG_AttributeInteger>()->value(
376  temp, index))
377  {
378  buffer.sprintf("%0*" SYS_PRId64, pad, temp);
380  }
382  }
383 
385  {
387  if (myHolder->template attribute<PDG_AttributeFloat>()->value(
388  temp, index))
389  {
390  // If a padding was specified, round to the nearest int and
391  // pad the integer value. This is the same behavior as the
392  // padzero() HScript function. Otherwise, format the value
393  // as-is.
394  if (pad > 0)
395  buffer.sprintf("%0*d", pad, (int)SYSrint(temp));
396  else
397  buffer.sprintf("%g", temp);
399  }
401  }
402 
404  {
406  if (myHolder->template attribute<PDG_AttributeString>()->value(
407  temp, index))
408  {
409  buffer.sprintf("%s", temp.c_str());
411  }
413  }
414 
416  {
418  if (myHolder->template attribute<PDG_AttributeFile>()->value(
419  temp, index))
420  {
421  buffer.sprintf("%s", temp.data().c_str());
423  }
425  }
426 
428  {
429  if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
430  buffer, index))
431  {
433  }
434 
436  }
437 
439  {
440  UT_StringHolder temp;
441  if (myHolder->template attribute<PDG_AttributePyObject>()->str(
442  temp))
443  {
444  buffer.sprintf("%s", temp.c_str());
446  }
448  }
449 
450  default:
452  }
453  }
454 
455  /// Prints the values contained in the attribute to space-separated string
457  int pad=0) const
458  {
459  switch (myHolder->type())
460  {
462  {
463  auto&& values = myHolder->template
464  attribute<PDG_AttributeInteger>()->values();
465  for (auto&& value : values)
466  buffer.appendSprintf("%0*" SYS_PRId64 " ", pad, value);
467  buffer.removeTrailingSpace();
469  }
470 
472  {
473  auto&& values = myHolder->template
474  attribute<PDG_AttributeFloat>()->values();
475  for (auto&& value : values)
476  {
477  // If a padding was specified, round to the nearest int and
478  // pad the integer value. This is the same behavior as the
479  // padzero() HScript function. Otherwise, format the value
480  // as-is.
481  if (pad > 0)
482  buffer.appendSprintf("%0*d ", pad, (int)SYSrint(value));
483  else
484  buffer.appendSprintf("%g ", value);
485  }
486 
487  buffer.removeTrailingSpace();
489  }
490 
492  {
493  auto&& values = myHolder->template
494  attribute<PDG_AttributeString>()->values();
495  for (auto&& value : values)
496  {
497  UT_String wrap(value);
498  wrap.protectString();
499  buffer.appendSprintf("%s ", wrap.buffer());
500  }
501 
502  buffer.removeTrailingSpace();
504  }
505 
507  {
508  auto&& values = myHolder->template
509  attribute<PDG_AttributeFile>()->values();
510  for (auto&& value : values)
511  {
512  UT_String wrap(value.data());
513  wrap.protectString();
514  buffer.appendSprintf("%s ", wrap.buffer());
515  }
516 
517  buffer.removeTrailingSpace();
519  }
520 
522  {
523  if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
524  buffer))
525  {
527  }
529  }
530 
532  {
534  if (myHolder->template attribute<PDG_AttributePyObject>()->str(
535  value))
536  {
537  UT_String wrap(value);
538  wrap.protectString();
539  buffer.appendSprintf("%s", wrap.buffer());
541  }
543  }
544 
545  default:
547  }
548  }
549 
550  /// Imports the attribute data in the ref into a UT_Options instance
551  /// using the name of this attribute as the key string
553  UT_Options& options,
554  PDG_AttributeOverwrite overwrite) const
555  {
556  return asOptions(options, myName, overwrite);
557  }
558 
559  /// Imports the attribute data in the ref into an UT_Options instance
560  /// using the specified key string
562  UT_Options& options,
563  const UT_StringHolder& key,
564  PDG_AttributeOverwrite overwrite) const
565  {
566  UT_OptionType existing_type = options.getOptionType(key);
567  if ((existing_type != UT_OPTION_INVALID) &&
568  (overwrite == PDG_AttributeOverwrite::eNever))
569  {
571  }
572 
573  switch (myHolder->type())
574  {
576  {
577  if (overwrite == PDG_AttributeOverwrite::eAlways ||
578  existing_type == UT_OPTION_INVALID ||
579  existing_type == UT_OPTION_INT ||
580  existing_type == UT_OPTION_INTARRAY)
581  {
582  auto&& attr =
583  myHolder->template attribute<PDG_AttributeInteger>();
584  if (attr->size() == 1)
585  options.setOptionI(key, attr->value(0));
586  else
587  options.setOptionIArray(key, attr->values());
588  }
589 
591  }
592 
594  {
595  if (overwrite == PDG_AttributeOverwrite::eAlways ||
596  existing_type == UT_OPTION_INVALID ||
597  existing_type == UT_OPTION_FPREAL ||
598  existing_type == UT_OPTION_FPREALARRAY ||
599  existing_type == UT_OPTION_VECTOR2 ||
600  existing_type == UT_OPTION_VECTOR3 ||
601  existing_type == UT_OPTION_VECTOR4 ||
602  existing_type == UT_OPTION_QUATERNION ||
603  existing_type == UT_OPTION_MATRIX3 ||
604  existing_type == UT_OPTION_MATRIX4 ||
605  existing_type == UT_OPTION_UV ||
606  existing_type == UT_OPTION_UVW)
607  {
608  auto&& attr =
609  myHolder->template attribute<PDG_AttributeFloat>();
610  if (attr->size() == 1)
611  options.setOptionF(key, attr->value(0));
612  else
613  {
614  options.setOptionFArray(
615  key, attr->values().data(), attr->size());
616  }
617  }
618 
620  }
621 
623  {
624  if (overwrite == PDG_AttributeOverwrite::eAlways ||
625  existing_type == UT_OPTION_INVALID ||
626  existing_type == UT_OPTION_STRING ||
627  existing_type == UT_OPTION_STRINGARRAY)
628  {
629  auto&& attr =
630  myHolder->template attribute<PDG_AttributeString>();
631  if (attr->size() == 1)
632  options.setOptionS(key, attr->value(0));
633  else
634  options.setOptionSArray(key, attr->values());
635  }
636 
638  }
639 
641  {
642  if (overwrite == PDG_AttributeOverwrite::eAlways ||
643  existing_type == UT_OPTION_INVALID ||
644  existing_type == UT_OPTION_STRING ||
645  existing_type == UT_OPTION_STRINGARRAY)
646  {
647  auto&& attr =
648  myHolder->template attribute<PDG_AttributeFile>();
649  if (attr->size() == 1)
650  options.setOptionS(key, attr->value(0).data());
651  else
652  {
653  UT_StringArray values(attr->size());
654  for (auto&& value : attr->values())
655  values.append(value.data());
656  options.setOptionSArray(key, values);
657  }
658  }
659 
661  }
662 
664  {
665  if (overwrite == PDG_AttributeOverwrite::eAlways ||
666  existing_type == UT_OPTION_INVALID ||
667  existing_type == UT_OPTION_DICT ||
668  existing_type == UT_OPTION_DICTARRAY)
669  {
670  auto&& attr =
671  myHolder->template attribute<PDG_AttributeDictionary>();
672  if (attr->size() == 1)
673  options.setOptionDict(key, attr->value(0));
674  else
675  options.setOptionDictArray(key, attr->values());
676  }
677 
679  }
680 
681  default:
683  }
684  }
685 
686  /// Returns the size of the data stored in the attribute
687  inline int size() const
688  {
689  switch (myHolder->type())
690  {
692  {
693  return myHolder->template attribute<
695  }
696 
698  {
699  return myHolder->template attribute<
700  PDG_AttributeFloat>()->size();
701  }
702 
704  {
705  return myHolder->template attribute<
707  }
708 
710  {
711  return myHolder->template attribute<
712  PDG_AttributeFile>()->size();
713  }
714 
716  {
717  return myHolder->template attribute<
719  }
720 
722  {
723  return myHolder->template attribute<
725  }
726 
728  {
729  return myHolder->template attribute<
731  }
732 
733  default:
734  return 0;
735  }
736  }
737 
738 protected:
739  Holder* myHolder;
740 };
741 
742 /**
743  * Read-only, const attribute ref
744  */
745 template <typename Attribute>
747  public PDG_AttributeRefT<Attribute, const PDG_AttributeHolder>
748 {
749 public:
751  using Base::Base;
752 };
753 
754 /**
755  * Read/write attribute ref that permits modifications of holder flags as
756  * well as non-const access to the underlying data. Accessing the attribute
757  * using either the named accessor or the -> overload will result in a deep
758  * copy + ownership being taken, if the data is not already owned by the
759  * holder.
760  */
761 template <typename Attribute>
763  public PDG_AttributeRefT<Attribute, PDG_AttributeHolder>
764 {
765 public:
768 
769  /// Constructs an uninitialized RW ref
771  const PDG_AttributeOwner* owner)
772  : Base(nullptr, name, owner, PDG_AttributeError::eUninitialized)
773  , myModified(false)
774  {
775  }
776 
777  /// Constructs a ref that can modify attribute data. We store the work
778  /// item so we can emit events.
780  const UT_StringHolder& name,
781  const PDG_AttributeOwner* owner,
784  : Base(holder, name, owner, error)
785  , myModified(false)
786  {
787  }
788 
789  /// Explicitly defined copy constructor, since we don't want to copy the
790  /// myModified flag from the source reference. Doing so would mean that
791  /// we'd potentially by emitting an extra data change event on destruction.
792  PDG_RWAttributeRef(const Self& other)
793  : Base(other)
794  , myModified(false)
795  {
796  }
797 
798  /// Explicitly defined move constructor, since a copy constructor has been
799  /// defined. When moving a ref we do want to preserve the myModified flag,
800  /// unlike in the copy constructor.
802  : Base(std::move(other))
803  , myModified(other.myModified)
804  {
805  other.myModified = false;
806  }
807 
808  /// Emits data changed events if this attribute ref recorded a modification
810  {
811  emitEvents();
812  }
813 
814  /// Explicitly defined copy assignment operator, since the copy constructor
815  /// is defined.
816  Self& operator=(const Self& other)
817  {
818  if (this != &other)
819  {
820  emitEvents();
821 
822  myModified = false;
823  Base::operator=(other);
824  }
825 
826  return *this;
827  }
828 
829  /// Explicitly defined move assignment operator, since the move constructor
830  /// is defined.
831  Self& operator=(Self&& other)
832  {
833  if (this != &other)
834  {
835  emitEvents();
836 
837  myModified = other.myModified;
838  other.myModified = false;
839 
840  Base::operator=(std::move(other));
841  }
842 
843  return *this;
844  }
845 
846  /// Emits pending events from the ref
847  inline void emitEvents()
848  {
849  if (Base::myOwner && myModified)
850  Base::attributeModified(Base::myOwner, Base::type(), Base::myName);
851 
852  myModified = false;
853  }
854 
855  /// Clears any pending events
856  inline void clearEvents()
857  {
858  myModified = false;
859  }
860 
861  /// Returns a non-const pointer to the underlying attribute instance. This
862  /// induces a copy if the attribute is not already owned, and counts as a
863  /// modification for the purpose of event handling.
865  {
866  Base::myHolder->own();
867  Base::myHolder->setIsChanged(true);
868 
869  myModified = true;
870  return Base::myHolder->template attribute<Attribute>();
871  }
872 
873  /// Returns a non-const pointer to the underlying attribute instance
875  {
876  return attribute();
877  }
878 
879  /// Sets the specific flag on or off, based on the set arugment, an
880  /// returns whether or not the flag was changed.
881  inline PDG_AttributeError
883  bool set,
884  bool& changed)
885  {
886  if (!Base::isValid())
887  return Base::error();
888 
889  if (Base::myOwner && !Base::myOwner->isAttribFlagValid(flag))
891 
892  changed = Base::myHolder->setFlag(flag, set);
894  }
895 
896  /// Sets the specific flag on or off
897  inline PDG_AttributeError
898  setFlag(PDG_AttributeFlag flag, bool set)
899  {
900  bool discard;
901  return setFlag(flag, set, discard);
902  }
903 
904  /// Directly sets the flag bits to the specified flags
905  inline PDG_AttributeError
906  setFlags(uint16 flags, bool& changed)
907  {
908  if (!Base::isValid())
909  return Base::error();
910 
911  if (Base::myOwner && !Base::myOwner->areAttribFlagsValid(flags))
913 
914  changed = Base::myHolder->setFlags(flags);
916  }
917 
918  /// Sets all flags
919  inline PDG_AttributeError
921  {
922  bool discard;
923  return setFlags(flags, discard);
924  }
925 
926  /// Truncates the array stored in the attribute
927  inline void truncate(int length)
928  {
929  switch (Base::myHolder->type())
930  {
932  {
933  return Base::myHolder->template attribute<
934  PDG_AttributeInteger>()->truncate(length);
935  }
936 
938  {
939  return Base::myHolder->template attribute<
940  PDG_AttributeFloat>()->truncate(length);
941  }
942 
944  {
945  return Base::myHolder->template attribute<
946  PDG_AttributeString>()->truncate(length);
947  }
948 
950  {
951  return Base::myHolder->template attribute<
952  PDG_AttributeFile>()->truncate(length);
953  }
954 
956  {
957  return Base::myHolder->template attribute<
958  PDG_AttributeDictionary>()->truncate(length);
959  }
960 
961  default:
962  return;
963  }
964  }
965 
966 private:
967  bool myModified;
968 };
969 
970 #endif
PDG_AttributeError
GLenum query
Definition: glad.h:2772
UT_OptionType getOptionType(const UT_StringRef &name) const
GLbitfield flags
Definition: glcorearb.h:1596
unsigned short uint16
Definition: SYS_Types.h:38
const T * attributeT() const
PDG_AttributeError setFlags(uint16 flags)
Sets all flags.
Never overwrite the attribute.
bool isOwner() const
Returns true if the contained attribute holder owns its data.
GLsizei const GLfloat * value
Definition: glcorearb.h:824
UT_Options & setOptionDictArray(const UT_StringHolder &name, const UT_OptionsHolder *values, size_t size)
Set dict array options.
const UT_StringHolder & name() const
Returns the name of the attribute referenced by this attrib ref.
#define PDG_API
Definition: PDG_API.h:23
bool isEmpty() const
Same as !isstring()
UT_OptionType
Definition: UT_Options.h:44
bool isArray() const
Returns true if the attribute is an array.
Attribute * attribute()
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
PDG_RWAttributeRef(PDG_AttributeHolder *holder, const UT_StringHolder &name, const PDG_AttributeOwner *owner, PDG_AttributeError error=PDG_AttributeError::eNone)
PDG_AttributeError setFlag(PDG_AttributeFlag flag, bool set, bool &changed)
PDG_AttributeRefT(Holder *holder, const UT_StringHolder &name, const PDG_AttributeOwner *owner, PDG_AttributeError error=PDG_AttributeError::eNone)
SYS_FORCE_INLINE const char * data() const
void pad(T &out, int n)
Definition: ImfXdr.h:407
< returns > If no error
Definition: snippets.dox:2
UT_Options & setOptionIArray(const UT_StringHolder &name, const int32 *values, size_t size)
PDG_AttributeOverwrite
~PDG_RWAttributeRef()
Emits data changed events if this attribute ref recorded a modification.
bool hasAnyFlags(uint16 flags) const
Returns true if the contained holder has any of the specified flags set.
Cast failed due to a type mismatch (string vs. int)
bool hasFlag(PDG_AttributeFlag flag) const
Returns true if the contained holder has the specified flag set.
const char * buffer() const
Definition: UT_String.h:509
UT_Options & setOptionSArray(const UT_StringHolder &name, const UT_StringHolder *values, size_t size)
Set string array options.
A single PDG_ApplicationShim::Geometry instance.
Hash hash() const
Definition: PDG_File.h:102
No error was specified, i.e. the ref is valid.
void truncate(int length)
Truncates the array stored in the attribute.
int64 Hash
The file hash/modtime type.
Definition: PDG_File.h:39
Definition: core.h:760
bool removeTrailingSpace()
Remove trailing whitespace, return true if whitespace was removed.
UT_Options & setOptionI(const UT_StringHolder &name, int64 value)
UT_StringHolder myName
const UT_StringHolder & tag() const
Definition: PDG_File.h:99
bool hasAnyFlags() const
Returns true if the contained holder has any flags set.
void clearEvents()
Clears any pending events.
static const UT_StringHolder theEmptyString
PDG_AttributeCast
Enumeration of attribute cast results.
PDG_AttributeCast asOptions(UT_Options &options, const UT_StringHolder &key, PDG_AttributeOverwrite overwrite) const
Attribute * operator->()
Returns a non-const pointer to the underlying attribute instance.
PDG_AttributeCast asNumber(fpreal &number, int index) const
PDG_AttributeCast asFile(PDG_File &file, int index, const UT_StringHolder &tag=UT_StringHolder::theEmptyString, PDG_File::Hash hash=0, bool own=false) const
bool hasData() const
Returns true if the contained attribute has any data.
#define PDG_API_TMPL
Definition: PDG_API.h:24
Holder * holder() const
Returns the underlying attribute holder.
PDG_AttributeType
Enumeration of possible attribute types.
PDG_AttributeError setFlag(PDG_AttributeFlag flag, bool set)
Sets the specific flag on or off.
SYS_FORCE_INLINE const char * c_str() const
PDG_RWAttributeRef(const UT_StringHolder &name, const PDG_AttributeOwner *owner)
Constructs an uninitialized RW ref.
const UT_StringHolder & data() const
Definition: PDG_File.h:96
An array of UT_StringHolder values.
GLuint const GLchar * name
Definition: glcorearb.h:786
const Attribute * attribute() const
Returns a const pointer to the underlying attribute instance.
const PDG_AttributeOwner * myOwner
PDG_AttributeFlag
Enumeration of extra attribute flags. Flags can be ORed together.
const PDG_AttributeOwner * owner() const
Returns the PDG_AttributeOwner that owns the underlying attribute.
An array of fpreal values.
fpreal32 SYSrint(fpreal32 val)
Definition: SYS_Floor.h:163
PDG_AttributeCast asNumber(fpreal &number, const PDG_AttributeQuery &query, int index, bool has_component) const
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
#define SYS_PRId64
Definition: SYS_Types.h:76
GLsizeiptr size
Definition: glcorearb.h:664
PDG_RWAttributeRef(const Self &other)
A map of string to various well defined value types.
Definition: UT_Options.h:84
int int appendSprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
int size() const
Returns the size of the data stored in the attribute.
PDG_AttributeError setFlags(uint16 flags, bool &changed)
Directly sets the flag bits to the specified flags.
The ref is uninitialized and needs to be created at a later point.
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
PDG_AttributeCast asStringValues(UT_WorkBuffer &buffer, int pad=0) const
Prints the values contained in the attribute to space-separated string.
PDG_AttributeType type() const
Returns the type of the contained attribute.
An array of PDG_File values, e.g. File info structs.
uint16 flags() const
Returns the flags on the contained holder.
fpreal64 fpreal
Definition: SYS_Types.h:277
bool isNumeric() const
Returns true if the attribute is numeric.
LeafData & operator=(const LeafData &)=delete
GLuint index
Definition: glcorearb.h:786
PDG_AttributeCast asString(UT_WorkBuffer &buffer, int index, int pad=0) const
No cast error occured (success)
UT_Options & setOptionS(const UT_StringHolder &name, const UT_StringHolder &value)
PDG_RWAttributeRef(Self &&other)
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
A single, opaque PyObject.
void protectString(bool protect_empty=false)
An array of int values.
Definition: core.h:1131
PDG_AttributeCast asOptions(UT_Options &options, PDG_AttributeOverwrite overwrite) const
const Attribute * operator->() const
Returns a const pointer to the underlying attribute instance.
void emitEvents()
Emits pending events from the ref.
UT_Options & setOptionDict(const UT_StringHolder &name, const UT_OptionsHolder &value)
UT_Options & setOptionFArray(const UT_StringHolder &name, const fpreal32 *values, size_t size)
Cast failed due to an index being out of bounds.
type
Definition: core.h:1059
Self & operator=(Self &&other)
Self & operator=(const Self &other)
PDG_AttributeCast asString(UT_WorkBuffer &buffer, const PDG_AttributeQuery &query, int index, int pad, bool has_component) const
UT_Options & setOptionF(const UT_StringHolder &name, fpreal64 value)
PDG_AttributeError error() const
Returns the error state of the handle.
An array of UT_OptionsHolder values.
PDG_AttributeRef(const UT_StringHolder &name, const PDG_AttributeOwner *owner, PDG_AttributeError error=PDG_AttributeError::eNone)
bool isValid() const
Returns true if the handle is valid.
bool hasFlags(uint16 flags) const
Returns true if the contained holder has all of the specified flags set.
PDG_AttributeError myError