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  exint& query_index,
220  const PDG_AttributeQuery& query,
221  int index,
222  bool has_component) const
223  {
224  if (myHolder->type() == PDG_AttributeType::ePythonObject)
225  {
226  if (!has_component)
227  index = -1;
228  return myHolder->template attribute<PDG_AttributePyObject>()->query(
229  number, query, index);
230  }
231  else if (myHolder->type() == PDG_AttributeType::eDictArray)
232  {
233  if (!has_component)
234  index = 0;
235  return myHolder->template attribute<PDG_AttributeDictionary>()->query(
236  number, query, query_index, index);
237  }
238 
239  return asNumber(number, index);
240  }
241 
242  /// Casts the value contained in the attribute at the particular index to a
243  /// numeric value, if possible.
244  inline PDG_AttributeCast asNumber(fpreal& number, int index) const
245  {
246  if (myHolder->type() == PDG_AttributeType::eIntegerArray)
247  {
249  if (myHolder->template attribute<PDG_AttributeInteger>()->value(
250  temp, index))
251  {
252  number = temp;
254  }
255 
257  }
258  else if (myHolder->type() == PDG_AttributeType::eFloatArray)
259  {
260  if (myHolder->template attribute<PDG_AttributeFloat>()->value(
261  number, index))
262  {
264  }
265 
267  }
268 
270  }
271 
272  /// Casts the value contained in the attribute to a PDG_File object. Only
273  /// valid for string, file and PyObject attribute types
275  PDG_File& file,
276  int index,
277  const UT_StringHolder& tag =
279  PDG_File::Hash hash = 0,
280  bool own = false) const
281  {
282  UT_StringHolder file_path;
283  UT_StringHolder file_tag = tag;
284  PDG_File::Hash file_hash = hash;
285 
286  switch (myHolder->type())
287  {
289  {
290  if (!myHolder->template attribute<PDG_AttributePyObject>()->str(
291  file_path))
292  {
294  }
295 
296  break;
297  }
298 
300  {
301  if (!myHolder->template attribute<PDG_AttributeString>()->value(
302  file_path, index))
303  {
305  }
306 
307  break;
308  }
309 
311  {
313  if (myHolder->template attribute<PDG_AttributeFile>()->value(
314  temp, index))
315  {
316  file_path = temp.data();
317 
318  if (file_tag.isEmpty())
319  file_tag = temp.tag();
320 
321  if (!file_hash)
322  file_hash = temp.hash();
323 
324  break;
325  }
326 
328  }
329 
330  default:
332  }
333 
334  file = PDG_File(file_path, file_tag, file_hash, own);
336  }
337 
338  /// Casts the value contained in the attribute at the particular index to a
339  /// string value, by looking up the value with the query string. Falls
340  /// a regular cast if query strings aren't supported
342  exint& query_index,
343  const PDG_AttributeQuery& query,
344  int index,
345  int pad,
346  bool has_component) const
347  {
348  if (myHolder->type() == PDG_AttributeType::ePythonObject)
349  {
350  if (!has_component)
351  index = -1;
352  return myHolder->template attribute<PDG_AttributePyObject>()->query(
353  buffer, query, index);
354  }
355  else if (myHolder->type() == PDG_AttributeType::eDictArray)
356  {
357  if (!has_component)
358  index = 0;
359  return myHolder->template attribute<PDG_AttributeDictionary>()->query(
360  buffer, query, query_index, index);
361  }
362 
363  return asString(buffer, index, pad);
364  }
365 
366  /// Casts the value contained in the attribute at the particular index to a
367  /// string value, if possible.
369  int index,
370  int pad=0) const
371  {
372  switch (myHolder->type())
373  {
375  {
377  if (myHolder->template attribute<PDG_AttributeInteger>()->value(
378  temp, index))
379  {
380  buffer.sprintf("%0*" SYS_PRId64, pad, temp);
382  }
384  }
385 
387  {
389  if (myHolder->template attribute<PDG_AttributeFloat>()->value(
390  temp, index))
391  {
392  // If a padding was specified, round to the nearest int and
393  // pad the integer value. This is the same behavior as the
394  // padzero() HScript function. Otherwise, format the value
395  // as-is.
396  if (pad > 0)
397  buffer.sprintf("%0*d", pad, (int)SYSrint(temp));
398  else
399  buffer.sprintf("%g", temp);
401  }
403  }
404 
406  {
408  if (myHolder->template attribute<PDG_AttributeString>()->value(
409  temp, index))
410  {
411  buffer.sprintf("%s", temp.c_str());
413  }
415  }
416 
418  {
420  if (myHolder->template attribute<PDG_AttributeFile>()->value(
421  temp, index))
422  {
423  buffer.sprintf("%s", temp.data().c_str());
425  }
427  }
428 
430  {
431  if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
432  buffer, index))
433  {
435  }
436 
438  }
439 
441  {
442  UT_StringHolder temp;
443  if (myHolder->template attribute<PDG_AttributePyObject>()->str(
444  temp))
445  {
446  buffer.sprintf("%s", temp.c_str());
448  }
450  }
451 
452  default:
454  }
455  }
456 
457  /// Prints the values contained in the attribute to space-separated string
459  int pad=0) const
460  {
461  switch (myHolder->type())
462  {
464  {
465  auto&& values = myHolder->template
466  attribute<PDG_AttributeInteger>()->values();
467  for (auto&& value : values)
468  buffer.appendSprintf("%0*" SYS_PRId64 " ", pad, value);
469  buffer.removeTrailingSpace();
471  }
472 
474  {
475  auto&& values = myHolder->template
476  attribute<PDG_AttributeFloat>()->values();
477  for (auto&& value : values)
478  {
479  // If a padding was specified, round to the nearest int and
480  // pad the integer value. This is the same behavior as the
481  // padzero() HScript function. Otherwise, format the value
482  // as-is.
483  if (pad > 0)
484  buffer.appendSprintf("%0*d ", pad, (int)SYSrint(value));
485  else
486  buffer.appendSprintf("%g ", value);
487  }
488 
489  buffer.removeTrailingSpace();
491  }
492 
494  {
495  auto&& values = myHolder->template
496  attribute<PDG_AttributeString>()->values();
497  for (auto&& value : values)
498  {
499  UT_String wrap(value);
500  wrap.protectString();
501  buffer.appendSprintf("%s ", wrap.buffer());
502  }
503 
504  buffer.removeTrailingSpace();
506  }
507 
509  {
510  auto&& values = myHolder->template
511  attribute<PDG_AttributeFile>()->values();
512  for (auto&& value : values)
513  {
514  UT_String wrap(value.data());
515  wrap.protectString();
516  buffer.appendSprintf("%s ", wrap.buffer());
517  }
518 
519  buffer.removeTrailingSpace();
521  }
522 
524  {
525  if (myHolder->template attribute<PDG_AttributeDictionary>()->desc(
526  buffer))
527  {
529  }
531  }
532 
534  {
536  if (myHolder->template attribute<PDG_AttributePyObject>()->str(
537  value))
538  {
539  UT_String wrap(value);
540  wrap.protectString();
541  buffer.appendSprintf("%s", wrap.buffer());
543  }
545  }
546 
547  default:
549  }
550  }
551 
552  /// Imports the attribute data in the ref into a UT_Options instance
553  /// using the name of this attribute as the key string
555  UT_Options& options,
556  PDG_AttributeOverwrite overwrite) const
557  {
558  return asOptions(options, myName, overwrite);
559  }
560 
561  /// Imports the attribute data in the ref into an UT_Options instance
562  /// using the specified key string
564  UT_Options& options,
565  const UT_StringHolder& key,
566  PDG_AttributeOverwrite overwrite) const
567  {
568  UT_OptionType existing_type = options.getOptionType(key);
569  if ((existing_type != UT_OPTION_INVALID) &&
570  (overwrite == PDG_AttributeOverwrite::eNever))
571  {
573  }
574 
575  switch (myHolder->type())
576  {
578  {
579  if (overwrite == PDG_AttributeOverwrite::eAlways ||
580  existing_type == UT_OPTION_INVALID ||
581  existing_type == UT_OPTION_INT ||
582  existing_type == UT_OPTION_INTARRAY)
583  {
584  auto&& attr =
585  myHolder->template attribute<PDG_AttributeInteger>();
586  if (attr->size() == 1)
587  options.setOptionI(key, attr->value(0));
588  else
589  options.setOptionIArray(key, attr->values());
590  }
591 
593  }
594 
596  {
597  if (overwrite == PDG_AttributeOverwrite::eAlways ||
598  existing_type == UT_OPTION_INVALID ||
599  existing_type == UT_OPTION_FPREAL ||
600  existing_type == UT_OPTION_FPREALARRAY ||
601  existing_type == UT_OPTION_VECTOR2 ||
602  existing_type == UT_OPTION_VECTOR3 ||
603  existing_type == UT_OPTION_VECTOR4 ||
604  existing_type == UT_OPTION_QUATERNION ||
605  existing_type == UT_OPTION_MATRIX3 ||
606  existing_type == UT_OPTION_MATRIX4 ||
607  existing_type == UT_OPTION_UV ||
608  existing_type == UT_OPTION_UVW)
609  {
610  auto&& attr =
611  myHolder->template attribute<PDG_AttributeFloat>();
612  if (attr->size() == 1)
613  options.setOptionF(key, attr->value(0));
614  else
615  {
616  options.setOptionFArray(
617  key, attr->values().data(), attr->size());
618  }
619  }
620 
622  }
623 
625  {
626  if (overwrite == PDG_AttributeOverwrite::eAlways ||
627  existing_type == UT_OPTION_INVALID ||
628  existing_type == UT_OPTION_STRING ||
629  existing_type == UT_OPTION_STRINGARRAY)
630  {
631  auto&& attr =
632  myHolder->template attribute<PDG_AttributeString>();
633  if (attr->size() == 1)
634  options.setOptionS(key, attr->value(0));
635  else
636  options.setOptionSArray(key, attr->values());
637  }
638 
640  }
641 
643  {
644  if (overwrite == PDG_AttributeOverwrite::eAlways ||
645  existing_type == UT_OPTION_INVALID ||
646  existing_type == UT_OPTION_STRING ||
647  existing_type == UT_OPTION_STRINGARRAY)
648  {
649  auto&& attr =
650  myHolder->template attribute<PDG_AttributeFile>();
651  if (attr->size() == 1)
652  options.setOptionS(key, attr->value(0).data());
653  else
654  {
655  UT_StringArray values(attr->size());
656  for (auto&& value : attr->values())
657  values.append(value.data());
658  options.setOptionSArray(key, values);
659  }
660  }
661 
663  }
664 
666  {
667  if (overwrite == PDG_AttributeOverwrite::eAlways ||
668  existing_type == UT_OPTION_INVALID ||
669  existing_type == UT_OPTION_DICT ||
670  existing_type == UT_OPTION_DICTARRAY)
671  {
672  auto&& attr =
673  myHolder->template attribute<PDG_AttributeDictionary>();
674  if (attr->size() == 1)
675  options.setOptionDict(key, attr->value(0));
676  else
677  options.setOptionDictArray(key, attr->values());
678  }
679 
681  }
682 
683  default:
685  }
686  }
687 
688  /// Returns the size of the data stored in the attribute
689  inline int size() const
690  {
691  switch (myHolder->type())
692  {
694  {
695  return myHolder->template attribute<
697  }
698 
700  {
701  return myHolder->template attribute<
702  PDG_AttributeFloat>()->size();
703  }
704 
706  {
707  return myHolder->template attribute<
709  }
710 
712  {
713  return myHolder->template attribute<
714  PDG_AttributeFile>()->size();
715  }
716 
718  {
719  return myHolder->template attribute<
721  }
722 
724  {
725  return myHolder->template attribute<
727  }
728 
730  {
731  return myHolder->template attribute<
733  }
734 
735  default:
736  return 0;
737  }
738  }
739 
740 protected:
741  Holder* myHolder;
742 };
743 
744 /**
745  * Read-only, const attribute ref
746  */
747 template <typename Attribute>
749  public PDG_AttributeRefT<Attribute, const PDG_AttributeHolder>
750 {
751 public:
753  using Base::Base;
754 };
755 
756 /**
757  * Read/write attribute ref that permits modifications of holder flags as
758  * well as non-const access to the underlying data. Accessing the attribute
759  * using either the named accessor or the -> overload will result in a deep
760  * copy + ownership being taken, if the data is not already owned by the
761  * holder.
762  */
763 template <typename Attribute>
765  public PDG_AttributeRefT<Attribute, PDG_AttributeHolder>
766 {
767 public:
770 
771  /// Constructs an uninitialized RW ref
773  const PDG_AttributeOwner* owner)
774  : Base(nullptr, name, owner, PDG_AttributeError::eUninitialized)
775  , myModified(false)
776  {
777  }
778 
779  /// Constructs a ref that can modify attribute data. We store the work
780  /// item so we can emit events.
782  const UT_StringHolder& name,
783  const PDG_AttributeOwner* owner,
786  : Base(holder, name, owner, error)
787  , myModified(false)
788  {
789  }
790 
791  /// Explicitly defined copy constructor, since we don't want to copy the
792  /// myModified flag from the source reference. Doing so would mean that
793  /// we'd potentially by emitting an extra data change event on destruction.
794  PDG_RWAttributeRef(const Self& other)
795  : Base(other)
796  , myModified(false)
797  {
798  }
799 
800  /// Explicitly defined move constructor, since a copy constructor has been
801  /// defined. When moving a ref we do want to preserve the myModified flag,
802  /// unlike in the copy constructor.
804  : Base(std::move(other))
805  , myModified(other.myModified)
806  {
807  other.myModified = false;
808  }
809 
810  /// Emits data changed events if this attribute ref recorded a modification
812  {
813  emitEvents();
814  }
815 
816  /// Explicitly defined copy assignment operator, since the copy constructor
817  /// is defined.
818  Self& operator=(const Self& other)
819  {
820  if (this != &other)
821  {
822  emitEvents();
823 
824  myModified = false;
825  Base::operator=(other);
826  }
827 
828  return *this;
829  }
830 
831  /// Explicitly defined move assignment operator, since the move constructor
832  /// is defined.
833  Self& operator=(Self&& other)
834  {
835  if (this != &other)
836  {
837  emitEvents();
838 
839  myModified = other.myModified;
840  other.myModified = false;
841 
842  Base::operator=(std::move(other));
843  }
844 
845  return *this;
846  }
847 
848  /// Emits pending events from the ref
849  inline void emitEvents()
850  {
851  if (Base::myOwner && myModified)
852  Base::attributeModified(Base::myOwner, Base::type(), Base::myName);
853 
854  myModified = false;
855  }
856 
857  /// Clears any pending events
858  inline void clearEvents()
859  {
860  myModified = false;
861  }
862 
863  /// Returns a non-const pointer to the underlying attribute instance. This
864  /// induces a copy if the attribute is not already owned, and counts as a
865  /// modification for the purpose of event handling.
867  {
868  Base::myHolder->own();
869  Base::myHolder->setIsChanged(true);
870 
871  myModified = true;
872  return Base::myHolder->template attribute<Attribute>();
873  }
874 
875  /// Returns a non-const pointer to the underlying attribute instance
877  {
878  return attribute();
879  }
880 
881  /// Sets the specific flag on or off, based on the set arugment, an
882  /// returns whether or not the flag was changed.
883  inline PDG_AttributeError
885  bool set,
886  bool& changed)
887  {
888  if (!Base::isValid())
889  return Base::error();
890 
891  if (Base::myOwner && !Base::myOwner->isAttribFlagValid(flag))
893 
894  changed = Base::myHolder->setFlag(flag, set);
896  }
897 
898  /// Sets the specific flag on or off
899  inline PDG_AttributeError
900  setFlag(PDG_AttributeFlag flag, bool set)
901  {
902  bool discard;
903  return setFlag(flag, set, discard);
904  }
905 
906  /// Directly sets the flag bits to the specified flags
907  inline PDG_AttributeError
908  setFlags(uint16 flags, bool& changed)
909  {
910  if (!Base::isValid())
911  return Base::error();
912 
913  if (Base::myOwner && !Base::myOwner->areAttribFlagsValid(flags))
915 
916  changed = Base::myHolder->setFlags(flags);
918  }
919 
920  /// Sets all flags
921  inline PDG_AttributeError
923  {
924  bool discard;
925  return setFlags(flags, discard);
926  }
927 
928  /// Truncates the array stored in the attribute
929  inline void truncate(int length)
930  {
931  switch (Base::myHolder->type())
932  {
934  {
935  return Base::myHolder->template attribute<
936  PDG_AttributeInteger>()->truncate(length);
937  }
938 
940  {
941  return Base::myHolder->template attribute<
942  PDG_AttributeFloat>()->truncate(length);
943  }
944 
946  {
947  return Base::myHolder->template attribute<
948  PDG_AttributeString>()->truncate(length);
949  }
950 
952  {
953  return Base::myHolder->template attribute<
954  PDG_AttributeFile>()->truncate(length);
955  }
956 
958  {
959  return Base::myHolder->template attribute<
960  PDG_AttributeDictionary>()->truncate(length);
961  }
962 
963  default:
964  return;
965  }
966  }
967 
968 private:
969  bool myModified;
970 };
971 
972 #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.
int64 exint
Definition: SYS_Types.h:125
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
PDG_AttributeCast asString(UT_WorkBuffer &buffer, exint &query_index, const PDG_AttributeQuery &query, int index, int pad, bool has_component) const
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
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)
UT_Options & setOptionF(const UT_StringHolder &name, fpreal64 value)
PDG_AttributeError error() const
Returns the error state of the handle.
PDG_AttributeCast asNumber(fpreal &number, exint &query_index, const PDG_AttributeQuery &query, int index, bool has_component) const
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