SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
DMX.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <filesystem>
5#include <span>
6#include <string>
7#include <string_view>
8#include <variant>
9#include <vector>
10
11#include <sourcepp/Math.h>
12
13namespace kvpp {
14
15namespace DMXValue {
16
17using UUID = std::array<std::byte, 16>;
18
19struct Element {
20 int32_t index;
21 std::string externalGUID;
22
23 static constexpr int32_t NULL_INDEX = -1;
24 static constexpr int32_t EXTERNAL_INDEX = -2;
25};
26
27using ByteArray = std::vector<std::byte>;
28
29struct Time {
30 float seconds;
31};
32
33struct Color {
34 uint8_t r;
35 uint8_t g;
36 uint8_t b;
37 uint8_t a;
38};
39
40using Vector2 = sourcepp::math::Vec2f;
41
42using Vector3 = sourcepp::math::Vec3f;
43
44using Vector4 = sourcepp::math::Vec4f;
45
47
49
50using Matrix4x4 = sourcepp::math::Mat4x4f;
51
89
127
169
171enum class IDVersion {
175};
176
220
221[[nodiscard]] constexpr ID decodeID(IDv1 id) {
222 switch (id) {
223 case IDv1::INVALID: return ID::INVALID;
224 case IDv1::ELEMENT: return ID::ELEMENT;
225 case IDv1::INT32: return ID::INT32;
226 case IDv1::FLOAT: return ID::FLOAT;
227 case IDv1::BOOL: return ID::BOOL;
228 case IDv1::STRING: return ID::STRING;
229 case IDv1::BYTEARRAY: return ID::BYTEARRAY;
230 case IDv1::UUID: return ID::UUID;
231 case IDv1::COLOR: return ID::COLOR;
232 case IDv1::VECTOR2: return ID::VECTOR2;
233 case IDv1::VECTOR3: return ID::VECTOR3;
234 case IDv1::VECTOR4: return ID::VECTOR4;
236 case IDv1::QUATERNION: return ID::QUATERNION;
237 case IDv1::MATRIX_4X4: return ID::MATRIX_4X4;
241 case IDv1::ARRAY_BOOL: return ID::ARRAY_BOOL;
244 case IDv1::ARRAY_UUID: return ID::ARRAY_UUID;
252 }
253 return ID::INVALID;
254}
255
256[[nodiscard]] constexpr ID decodeID(IDv2 id) {
257 switch (id) {
258 case IDv2::INVALID: return ID::INVALID;
259 case IDv2::ELEMENT: return ID::ELEMENT;
260 case IDv2::INT32: return ID::INT32;
261 case IDv2::FLOAT: return ID::FLOAT;
262 case IDv2::BOOL: return ID::BOOL;
263 case IDv2::STRING: return ID::STRING;
264 case IDv2::BYTEARRAY: return ID::BYTEARRAY;
265 case IDv2::TIME: return ID::TIME;
266 case IDv2::COLOR: return ID::COLOR;
267 case IDv2::VECTOR2: return ID::VECTOR2;
268 case IDv2::VECTOR3: return ID::VECTOR3;
269 case IDv2::VECTOR4: return ID::VECTOR4;
271 case IDv2::QUATERNION: return ID::QUATERNION;
272 case IDv2::MATRIX_4X4: return ID::MATRIX_4X4;
276 case IDv2::ARRAY_BOOL: return ID::ARRAY_BOOL;
279 case IDv2::ARRAY_TIME: return ID::ARRAY_TIME;
287 }
288 return ID::INVALID;
289}
290
291[[nodiscard]] constexpr ID decodeID(IDv3 id) {
292 switch (id) {
293 case IDv3::INVALID: return ID::INVALID;
294 case IDv3::ELEMENT: return ID::ELEMENT;
295 case IDv3::INT32: return ID::INT32;
296 case IDv3::FLOAT: return ID::FLOAT;
297 case IDv3::BOOL: return ID::BOOL;
298 case IDv3::STRING: return ID::STRING;
299 case IDv3::BYTEARRAY: return ID::BYTEARRAY;
300 case IDv3::TIME: return ID::TIME;
301 case IDv3::COLOR: return ID::COLOR;
302 case IDv3::VECTOR2: return ID::VECTOR2;
303 case IDv3::VECTOR3: return ID::VECTOR3;
304 case IDv3::VECTOR4: return ID::VECTOR4;
306 case IDv3::QUATERNION: return ID::QUATERNION;
307 case IDv3::MATRIX_4X4: return ID::MATRIX_4X4;
308 case IDv3::UINT64: return ID::UINT64;
309 case IDv3::UINT8: return ID::UINT8;
313 case IDv3::ARRAY_BOOL: return ID::ARRAY_BOOL;
316 case IDv3::ARRAY_TIME: return ID::ARRAY_TIME;
326 }
327 return ID::INVALID;
328}
329
330[[nodiscard]] constexpr std::byte encodeID(ID id, IDVersion version, bool& incompatible) {
331 incompatible = false;
332 switch (version) {
333 case IDVersion::V1: {
334 auto out = IDv1::INVALID;
335 switch (id) {
336 case ID::INVALID: break;
337 case ID::ELEMENT: out = IDv1::ELEMENT; break;
338 case ID::INT32: out = IDv1::INT32; break;
339 case ID::FLOAT: out = IDv1::FLOAT; break;
340 case ID::BOOL: out = IDv1::BOOL; break;
341 case ID::STRING: out = IDv1::STRING; break;
342 case ID::BYTEARRAY: out = IDv1::BYTEARRAY; break;
343 case ID::UUID: out = IDv1::UUID; break;
344 case ID::TIME: out = IDv1::STRING; incompatible = true; break;
345 case ID::COLOR: out = IDv1::COLOR; break;
346 case ID::VECTOR2: out = IDv1::VECTOR2; break;
347 case ID::VECTOR3: out = IDv1::VECTOR3; break;
348 case ID::VECTOR4: out = IDv1::VECTOR4; break;
349 case ID::EULER_ANGLES: out = IDv1::EULER_ANGLES; break;
350 case ID::QUATERNION: out = IDv1::QUATERNION; break;
351 case ID::MATRIX_4X4: out = IDv1::MATRIX_4X4; break;
352 case ID::UINT64:
353 case ID::UINT8: out = IDv1::STRING; incompatible = true; break;
354 case ID::ARRAY_ELEMENT: out = IDv1::ARRAY_ELEMENT; break;
355 case ID::ARRAY_INT32: out = IDv1::ARRAY_INT32; break;
356 case ID::ARRAY_FLOAT: out = IDv1::ARRAY_FLOAT; break;
357 case ID::ARRAY_BOOL: out = IDv1::ARRAY_BOOL; break;
358 case ID::ARRAY_STRING: out = IDv1::ARRAY_STRING; break;
360 case ID::ARRAY_UUID: out = IDv1::ARRAY_UUID; break;
361 case ID::ARRAY_TIME: out = IDv1::ARRAY_STRING; incompatible = true; break;
362 case ID::ARRAY_COLOR: out = IDv1::ARRAY_COLOR; break;
363 case ID::ARRAY_VECTOR2: out = IDv1::ARRAY_VECTOR2; break;
364 case ID::ARRAY_VECTOR3: out = IDv1::ARRAY_VECTOR3; break;
365 case ID::ARRAY_VECTOR4: out = IDv1::ARRAY_VECTOR4; break;
369 case ID::ARRAY_UINT64:
370 case ID::ARRAY_UINT8: out = IDv1::ARRAY_STRING; incompatible = true; break;
371 }
372 return static_cast<std::byte>(out);
373 }
374 case IDVersion::V2: {
375 auto out = IDv2::INVALID;
376 switch (id) {
377 case ID::INVALID: break;
378 case ID::ELEMENT: out = IDv2::ELEMENT; break;
379 case ID::INT32: out = IDv2::INT32; break;
380 case ID::FLOAT: out = IDv2::FLOAT; break;
381 case ID::BOOL: out = IDv2::BOOL; break;
382 case ID::STRING: out = IDv2::STRING; break;
383 case ID::BYTEARRAY: out = IDv2::BYTEARRAY; break;
384 case ID::UUID: out = IDv2::STRING; incompatible = true; break;
385 case ID::TIME: out = IDv2::TIME; break;
386 case ID::COLOR: out = IDv2::COLOR; break;
387 case ID::VECTOR2: out = IDv2::VECTOR2; break;
388 case ID::VECTOR3: out = IDv2::VECTOR3; break;
389 case ID::VECTOR4: out = IDv2::VECTOR4; break;
390 case ID::EULER_ANGLES: out = IDv2::EULER_ANGLES; break;
391 case ID::QUATERNION: out = IDv2::QUATERNION; break;
392 case ID::MATRIX_4X4: out = IDv2::MATRIX_4X4; break;
393 case ID::UINT64:
394 case ID::UINT8: out = IDv2::STRING; incompatible = true; break;
395 case ID::ARRAY_ELEMENT: out = IDv2::ARRAY_ELEMENT; break;
396 case ID::ARRAY_INT32: out = IDv2::ARRAY_INT32; break;
397 case ID::ARRAY_FLOAT: out = IDv2::ARRAY_FLOAT; break;
398 case ID::ARRAY_BOOL: out = IDv2::ARRAY_BOOL; break;
399 case ID::ARRAY_STRING: out = IDv2::ARRAY_STRING; break;
401 case ID::ARRAY_UUID: out = IDv2::STRING; incompatible = true; break;
402 case ID::ARRAY_TIME: out = IDv2::ARRAY_TIME; break;
403 case ID::ARRAY_COLOR: out = IDv2::ARRAY_COLOR; break;
404 case ID::ARRAY_VECTOR2: out = IDv2::ARRAY_VECTOR2; break;
405 case ID::ARRAY_VECTOR3: out = IDv2::ARRAY_VECTOR3; break;
406 case ID::ARRAY_VECTOR4: out = IDv2::ARRAY_VECTOR4; break;
410 case ID::ARRAY_UINT64:
411 case ID::ARRAY_UINT8: out = IDv2::STRING; incompatible = true; break;
412 }
413 return static_cast<std::byte>(out);
414 }
415 case IDVersion::V3: {
416 auto out = IDv3::INVALID;
417 switch (id) {
418 case ID::INVALID: break;
419 case ID::ELEMENT: out = IDv3::ELEMENT; break;
420 case ID::INT32: out = IDv3::INT32; break;
421 case ID::FLOAT: out = IDv3::FLOAT; break;
422 case ID::BOOL: out = IDv3::BOOL; break;
423 case ID::STRING: out = IDv3::STRING; break;
424 case ID::BYTEARRAY: out = IDv3::BYTEARRAY; break;
425 case ID::UUID: out = IDv3::STRING; incompatible = true; break;
426 case ID::TIME: out = IDv3::TIME; break;
427 case ID::COLOR: out = IDv3::COLOR; break;
428 case ID::VECTOR2: out = IDv3::VECTOR2; break;
429 case ID::VECTOR3: out = IDv3::VECTOR3; break;
430 case ID::VECTOR4: out = IDv3::VECTOR4; break;
431 case ID::EULER_ANGLES: out = IDv3::EULER_ANGLES; break;
432 case ID::QUATERNION: out = IDv3::QUATERNION; break;
433 case ID::MATRIX_4X4: out = IDv3::MATRIX_4X4; break;
434 case ID::UINT64: out = IDv3::UINT64; break;
435 case ID::UINT8: out = IDv3::UINT8; break;
436 case ID::ARRAY_ELEMENT: out = IDv3::ARRAY_ELEMENT; break;
437 case ID::ARRAY_INT32: out = IDv3::ARRAY_INT32; break;
438 case ID::ARRAY_FLOAT: out = IDv3::ARRAY_FLOAT; break;
439 case ID::ARRAY_BOOL: out = IDv3::ARRAY_BOOL; break;
440 case ID::ARRAY_STRING: out = IDv3::ARRAY_STRING; break;
442 case ID::ARRAY_UUID: out = IDv3::STRING; incompatible = true; break;
443 case ID::ARRAY_TIME: out = IDv3::ARRAY_TIME; break;
444 case ID::ARRAY_COLOR: out = IDv3::ARRAY_COLOR; break;
445 case ID::ARRAY_VECTOR2: out = IDv3::ARRAY_VECTOR2; break;
446 case ID::ARRAY_VECTOR3: out = IDv3::ARRAY_VECTOR3; break;
447 case ID::ARRAY_VECTOR4: out = IDv3::ARRAY_VECTOR4; break;
451 case ID::ARRAY_UINT64: out = IDv3::ARRAY_UINT64; break;
452 case ID::ARRAY_UINT8: out = IDv3::ARRAY_UINT8; break;
453 }
454 return static_cast<std::byte>(out);
455 }
456 }
457 return {};
458}
459
460using Generic = std::variant<
461 std::monostate,
462
463 Element,
464 int32_t,
465 float,
466 bool,
467 std::string,
468 std::vector<std::byte>,
469 UUID,
470 Time,
471 Color,
472 Vector2,
473 Vector3,
474 Vector4,
477 Matrix4x4,
478 uint64_t,
479 uint8_t,
480
481 std::vector<Element>,
482 std::vector<int32_t>,
483 std::vector<float>,
484 std::vector<bool>,
485 std::vector<std::string>,
486 std::vector<std::vector<std::byte>>,
487 std::vector<UUID>,
488 std::vector<Time>,
489 std::vector<Color>,
490 std::vector<Vector2>,
491 std::vector<Vector3>,
492 std::vector<Vector4>,
493 std::vector<EulerAngles>,
494 std::vector<Quaternion>,
495 std::vector<Matrix4x4>,
496 std::vector<uint64_t>,
497 std::vector<uint8_t>
498>;
499
500[[nodiscard]] constexpr ID arrayIDToInnerID(ID id) {
501 if (id >= ID::ARRAY_START) {
502 return static_cast<ID>(static_cast<uint8_t>(id) - static_cast<uint8_t>(ID::VALUE_END));
503 }
504 return id;
505}
506
507[[nodiscard]] constexpr ID innerIDToArrayID(ID id) {
508 if (id <= ID::VALUE_END) {
509 return static_cast<ID>(static_cast<uint8_t>(id) + static_cast<uint8_t>(ID::VALUE_END));
510 }
511 return id;
512}
513
514[[nodiscard]] std::string idToString(ID id);
515
516// NOLINTNEXTLINE(*-no-recursion)
517[[nodiscard]] constexpr ID stringToID(std::string_view id) {
518 using enum ID;
519 if (id == "element") return ELEMENT;
520 if (id == "int") return INT32;
521 if (id == "float") return FLOAT;
522 if (id == "bool") return BOOL;
523 if (id == "string") return STRING;
524 if (id == "binary") return BYTEARRAY;
525 if (id == "objectid") return UUID;
526 if (id == "time") return TIME;
527 if (id == "color") return COLOR;
528 if (id == "vector2") return VECTOR2;
529 if (id == "vector3") return VECTOR3;
530 if (id == "vector4") return VECTOR4;
531 if (id == "angle") return EULER_ANGLES;
532 if (id == "quaternion") return QUATERNION;
533 if (id == "matrix") return MATRIX_4X4;
534 if (id == "uint64") return UINT64;
535 if (id == "uint8") return UINT8;
536 if (id.ends_with("_array")) {
537 return innerIDToArrayID(stringToID(id.substr(0, id.length() - 6)));
538 }
539 return INVALID;
540}
541
542} // namespace DMXValue
543
545 friend class DMXElement;
546 friend class DMX;
547
548public:
550 [[nodiscard]] bool isInvalid() const;
551
552 [[nodiscard]] explicit operator bool() const;
553
554 [[nodiscard]] std::string_view getKey() const;
555
556 void setKey(std::string key_);
557
558 [[nodiscard]] DMXValue::ID getValueType() const;
559
560 [[nodiscard]] bool isValueArray() const;
561
562 [[nodiscard]] const DMXValue::Generic& getValue() const;
563
564 template<typename T>
565 [[nodiscard]] T getValue() const {
566 return std::get<T>(this->value);
567 }
568
569 [[nodiscard]] std::string getValueString() const;
570
572 void setValue(DMXValue::Generic value_);
573
576
577protected:
578 DMXAttribute() = default;
579
580 std::string key;
582};
583
585 friend class DMX;
586
587public:
588 [[nodiscard]] explicit operator bool() const;
589
591 [[nodiscard]] std::string_view getType() const;
592
594 void setType(std::string type_);
595
597 [[nodiscard]] std::string_view getKey() const;
598
600 void setKey(std::string key_);
601
602 // Get the UUID associated with this element
603 [[nodiscard]] const DMXValue::UUID& getUUID() const;
604
605 // Set the UUID associated with this element
606 void setUUID(const DMXValue::UUID& guid_);
607
609 [[nodiscard]] bool hasAttribute(std::string_view attributeKey) const;
610
612 DMXAttribute& addAttribute(std::string key_, DMXValue::Generic value_ = {});
613
615 [[nodiscard]] uint64_t getAttributeCount() const;
616
618 [[nodiscard]] uint64_t getAttributeCount(std::string_view childKey) const;
619
621 [[nodiscard]] const std::vector<DMXAttribute>& getAttributes() const;
622
624 [[nodiscard]] std::vector<DMXAttribute>& getAttributes();
625
626 using iterator = std::vector<DMXAttribute>::iterator;
627
628 [[nodiscard]] constexpr iterator begin() {
629 return this->attributes.begin();
630 }
631
632 [[nodiscard]] constexpr iterator end() {
633 return this->attributes.end();
634 }
635
636 using const_iterator = std::vector<DMXAttribute>::const_iterator;
637
638 [[nodiscard]] constexpr const_iterator begin() const {
639 return this->attributes.begin();
640 }
641
642 [[nodiscard]] constexpr const_iterator end() const {
643 return this->attributes.end();
644 }
645
646 [[nodiscard]] constexpr const_iterator cbegin() const {
647 return this->attributes.cbegin();
648 }
649
650 [[nodiscard]] constexpr const_iterator cend() const {
651 return this->attributes.cend();
652 }
653
655 [[nodiscard]] const DMXAttribute& operator[](unsigned int n) const;
656
658 [[nodiscard]] DMXAttribute& operator[](unsigned int n);
659
661 [[nodiscard]] const DMXAttribute& operator[](std::string_view attributeKey) const;
662
664 [[nodiscard]] DMXAttribute& operator[](std::string_view attributeKey);
665
667 [[nodiscard]] const DMXAttribute& operator()(std::string_view attributeKey) const;
668
670 [[nodiscard]] DMXAttribute& operator()(std::string_view attributeKey);
671
673 [[nodiscard]] const DMXAttribute& operator()(std::string_view attributeKey, unsigned int n) const;
674
676 [[nodiscard]] DMXAttribute& operator()(std::string_view attributeKey, unsigned int n);
677
679 void removeAttribute(unsigned int n);
680
682 void removeAttribute(std::string_view attributeKey, int n = -1);
683
684 static const DMXAttribute& getInvalidAttribute();
685
686protected:
687 DMXElement() = default;
688
689 std::string type;
690 std::string key;
692 std::vector<DMXAttribute> attributes;
693};
694
695class DMX {
696public:
709
710 DMX(Encoding encodingType_, int encodingVersion_, std::string formatType_, int formatVersion_);
711
712 explicit DMX(std::span<const std::byte> dmxData);
713
714 explicit DMX(std::string_view dmxData);
715
716 [[nodiscard]] explicit operator bool() const;
717
718 [[nodiscard]] Encoding getEncodingType() const;
719
720 void setEncodingType(Encoding encodingType_);
721
722 [[nodiscard]] bool doesEncodingTypeHaveUnicodePrefix() const;
723
724 void shouldEncodingTypeHaveUnicodePrefix(bool encodingTypeHasUnicodePrefix_);
725
726 [[nodiscard]] int getEncodingVersion() const;
727
728 void setEncodingVersion(int encodingVersion_);
729
730 [[nodiscard]] std::string_view getFormatType() const;
731
732 void setFormatType(std::string formatType_);
733
734 [[nodiscard]] int getFormatVersion() const;
735
736 void setFormatVersion(int formatVersion_);
737
739
741 [[nodiscard]] uint64_t getPrefixAttributeContainerCount() const;
742
743 [[nodiscard]] const std::vector<DMXElement>& getPrefixAttributeContainers() const;
744
745 [[nodiscard]] std::vector<DMXElement>& getPrefixAttributeContainers();
746
747 void removePrefixAttributeContainer(unsigned int n);
748
750 [[nodiscard]] bool hasElement(std::string_view key) const;
751
753 DMXElement& addElement(std::string type, std::string key);
754
756 [[nodiscard]] uint64_t getElementCount() const;
757
759 [[nodiscard]] uint64_t getElementCount(std::string_view key) const;
760
761 [[nodiscard]] const std::vector<DMXElement>& getElements() const;
762
763 [[nodiscard]] std::vector<DMXElement>& getElements();
764
765 using iterator = std::vector<DMXElement>::iterator;
766
767 [[nodiscard]] constexpr iterator begin() {
768 return this->elements.begin();
769 }
770
771 [[nodiscard]] constexpr iterator end() {
772 return this->elements.end();
773 }
774
775 using const_iterator = std::vector<DMXElement>::const_iterator;
776
777 [[nodiscard]] constexpr const_iterator begin() const {
778 return this->elements.begin();
779 }
780
781 [[nodiscard]] constexpr const_iterator end() const {
782 return this->elements.end();
783 }
784
785 [[nodiscard]] constexpr const_iterator cbegin() const {
786 return this->elements.cbegin();
787 }
788
789 [[nodiscard]] constexpr const_iterator cend() const {
790 return this->elements.cend();
791 }
792
794 [[nodiscard]] const DMXElement& operator[](unsigned int n) const;
795
797 [[nodiscard]] DMXElement& operator[](unsigned int n);
798
800 [[nodiscard]] const DMXElement& operator[](std::string_view key) const;
801
803 [[nodiscard]] DMXElement& operator[](std::string_view key);
804
806 [[nodiscard]] const DMXElement& operator()(std::string_view key) const;
807
809 [[nodiscard]] DMXElement& operator()(std::string_view key);
810
812 [[nodiscard]] const DMXElement& operator()(std::string_view key, unsigned int n) const;
813
815 [[nodiscard]] DMXElement& operator()(std::string_view key, unsigned int n);
816
818 void removeElement(unsigned int n);
819
820 [[nodiscard]] std::vector<std::byte> bake() const;
821
822 void bake(const std::filesystem::path& dmxPath) const;
823
824 [[nodiscard]] static constexpr bool isEncodingVersionValid(Encoding encodingType, int encodingVersion) {
825 switch (encodingType) {
826 case ENCODING_INVALID:
827 break;
829 return encodingVersion >= 1 && encodingVersion <= 2;
831 return encodingVersion >= 1 && encodingVersion <= 9;
832 case ENCODING_BINARY:
834 return (encodingVersion >= 1 && encodingVersion <= 5) || encodingVersion == 9;
837 return encodingVersion == 1;
840 return encodingVersion >= 1 && encodingVersion <= 4;
842 return encodingVersion == 1;
843 }
844 return false;
845 }
846
847 [[nodiscard]] static DMXValue::UUID createRandomUUID();
848
849 [[nodiscard]] static const DMXElement& getInvalidElement();
850
851protected:
855 std::string formatType;
857
858 std::vector<DMXElement> prefixAttributeContainers;
859 std::vector<DMXElement> elements;
860};
861
862namespace literals {
863
864DMX operator""_kv2(const char* str, std::size_t len);
865
866} // namespace literals
867
868} // namespace kvpp
bool isInvalid() const
Check if the given attribute is invalid.
Definition DMX.cpp:61
friend class DMX
Definition DMX.h:546
std::string key
Definition DMX.h:580
T getValue() const
Definition DMX.h:565
DMXAttribute()=default
DMXAttribute & operator=(DMXValue::Generic value_)
Set the value associated with the attribute.
Definition DMX.cpp:347
DMXValue::Generic value
Definition DMX.h:581
friend class DMXElement
Definition DMX.h:545
void setValue(DMXValue::Generic value_)
Set the value associated with the attribute.
Definition DMX.cpp:343
bool isValueArray() const
Definition DMX.cpp:81
const DMXValue::Generic & getValue() const
Definition DMX.cpp:85
DMXValue::ID getValueType() const
Definition DMX.cpp:77
void setKey(std::string key_)
Definition DMX.cpp:73
std::string getValueString() const
Definition DMX.cpp:89
std::string_view getKey() const
Definition DMX.cpp:69
static const DMXAttribute & getInvalidAttribute()
Definition DMX.cpp:499
uint64_t getAttributeCount() const
Get the number of child attributes.
Definition DMX.cpp:392
constexpr const_iterator cbegin() const
Definition DMX.h:646
std::string key
Definition DMX.h:690
void setUUID(const DMXValue::UUID &guid_)
Definition DMX.cpp:376
void setKey(std::string key_)
Set the key associated with the element.
Definition DMX.cpp:368
bool hasAttribute(std::string_view attributeKey) const
Check if the element has one or more children with the given name.
Definition DMX.cpp:380
constexpr const_iterator cend() const
Definition DMX.h:650
const DMXAttribute & operator()(std::string_view attributeKey) const
Get the first attribute of the element with the given key.
Definition DMX.cpp:430
constexpr iterator begin()
Definition DMX.h:628
std::string_view getType() const
Get the C++ type the element maps to.
Definition DMX.cpp:356
DMXElement()=default
const DMXAttribute & operator[](unsigned int n) const
Get the attribute of the element at the given index.
Definition DMX.cpp:414
std::vector< DMXAttribute >::const_iterator const_iterator
Definition DMX.h:636
friend class DMX
Definition DMX.h:585
constexpr const_iterator end() const
Definition DMX.h:642
constexpr const_iterator begin() const
Definition DMX.h:638
DMXAttribute & addAttribute(std::string key_, DMXValue::Generic value_={})
Add an attribute to the element.
Definition DMX.cpp:384
constexpr iterator end()
Definition DMX.h:632
const std::vector< DMXAttribute > & getAttributes() const
Get the child attributes of the element.
Definition DMX.cpp:406
std::string type
Definition DMX.h:689
void setType(std::string type_)
Set the C++ type the element maps to.
Definition DMX.cpp:360
std::vector< DMXAttribute > attributes
Definition DMX.h:692
const DMXValue::UUID & getUUID() const
Definition DMX.cpp:372
void removeAttribute(unsigned int n)
Remove an attribute from the element.
Definition DMX.cpp:478
std::vector< DMXAttribute >::iterator iterator
Definition DMX.h:626
std::string_view getKey() const
Get the key associated with the element.
Definition DMX.cpp:364
DMXValue::UUID uuid
Definition DMX.h:691
std::vector< DMXElement > prefixAttributeContainers
Definition DMX.h:858
int encodingVersion
Definition DMX.h:854
const DMXElement & operator()(std::string_view key) const
Get the first element in the element list with the given key.
Definition DMX.cpp:977
constexpr iterator begin()
Definition DMX.h:767
int getFormatVersion() const
Definition DMX.cpp:895
DMX(Encoding encodingType_, int encodingVersion_, std::string formatType_, int formatVersion_)
Definition DMX.cpp:504
std::vector< DMXElement >::const_iterator const_iterator
Definition DMX.h:775
void removeElement(unsigned int n)
Remove an element from the element list and update all element references.
Definition DMX.cpp:1025
bool doesEncodingTypeHaveUnicodePrefix() const
Definition DMX.cpp:869
static const DMXElement & getInvalidElement()
Definition DMX.cpp:1079
Encoding
Definition DMX.h:697
@ ENCODING_KEYVALUES2
Definition DMX.h:705
@ ENCODING_BINARY_OLD
Definition DMX.h:699
@ ENCODING_BINARY
Definition DMX.h:701
@ ENCODING_BINARY_SEQIDS
Definition DMX.h:702
@ ENCODING_KEYVALUES2_FLAT
Definition DMX.h:706
@ ENCODING_INVALID
Definition DMX.h:698
@ ENCODING_KEYVALUES2_NOIDS
Definition DMX.h:707
@ ENCODING_KEYVALUES2_FLAT_OLD
Definition DMX.h:704
@ ENCODING_KEYVALUES2_OLD
Definition DMX.h:703
@ ENCODING_BINARY_OLD_SFM
Definition DMX.h:700
bool encodingTypeHasUnicodePrefix
Definition DMX.h:853
const std::vector< DMXElement > & getPrefixAttributeContainers() const
Definition DMX.cpp:912
constexpr iterator end()
Definition DMX.h:771
std::vector< DMXElement >::iterator iterator
Definition DMX.h:765
void shouldEncodingTypeHaveUnicodePrefix(bool encodingTypeHasUnicodePrefix_)
Definition DMX.cpp:873
void setFormatType(std::string formatType_)
Definition DMX.cpp:891
constexpr const_iterator begin() const
Definition DMX.h:777
std::vector< DMXElement > elements
Definition DMX.h:859
constexpr const_iterator end() const
Definition DMX.h:781
Encoding getEncodingType() const
Definition DMX.cpp:858
std::vector< std::byte > bake() const
Definition DMX.cpp:1054
uint64_t getElementCount() const
Get the number of elements.
Definition DMX.cpp:939
const std::vector< DMXElement > & getElements() const
Definition DMX.cpp:953
bool hasElement(std::string_view key) const
Check if the element list has one or more elements with the given name.
Definition DMX.cpp:926
void setEncodingVersion(int encodingVersion_)
Definition DMX.cpp:881
constexpr const_iterator cend() const
Definition DMX.h:789
Encoding encodingType
Definition DMX.h:852
constexpr const_iterator cbegin() const
Definition DMX.h:785
DMXElement & addPrefixAttributeContainer()
Definition DMX.cpp:903
int formatVersion
Definition DMX.h:856
void removePrefixAttributeContainer(unsigned int n)
Definition DMX.cpp:920
static DMXValue::UUID createRandomUUID()
Definition DMX.cpp:1067
const DMXElement & operator[](unsigned int n) const
Get the element in the element list at the given index.
Definition DMX.cpp:961
static constexpr bool isEncodingVersionValid(Encoding encodingType, int encodingVersion)
Definition DMX.h:824
std::string formatType
Definition DMX.h:855
void setFormatVersion(int formatVersion_)
Definition DMX.cpp:899
std::string_view getFormatType() const
Definition DMX.cpp:887
DMXElement & addElement(std::string type, std::string key)
Add an element to the element list.
Definition DMX.cpp:930
void setEncodingType(Encoding encodingType_)
Definition DMX.cpp:862
int getEncodingVersion() const
Definition DMX.cpp:877
uint64_t getPrefixAttributeContainerCount() const
Get the number of prefix attributes.
Definition DMX.cpp:908
IDVersion
Not representative of DMX encoding version, although the attribute type enum variances are linked to ...
Definition DMX.h:171
sourcepp::math::Mat4x4f Matrix4x4
Definition DMX.h:50
constexpr ID arrayIDToInnerID(ID id)
Definition DMX.h:500
std::variant< std::monostate, Element, int32_t, float, bool, std::string, std::vector< std::byte >, UUID, Time, Color, Vector2, Vector3, Vector4, EulerAngles, Quaternion, Matrix4x4, uint64_t, uint8_t, std::vector< Element >, std::vector< int32_t >, std::vector< float >, std::vector< bool >, std::vector< std::string >, std::vector< std::vector< std::byte > >, std::vector< UUID >, std::vector< Time >, std::vector< Color >, std::vector< Vector2 >, std::vector< Vector3 >, std::vector< Vector4 >, std::vector< EulerAngles >, std::vector< Quaternion >, std::vector< Matrix4x4 >, std::vector< uint64_t >, std::vector< uint8_t > > Generic
Definition DMX.h:460
constexpr ID stringToID(std::string_view id)
Definition DMX.h:517
std::array< std::byte, 16 > UUID
Definition DMX.h:17
sourcepp::math::Vec3f Vector3
Definition DMX.h:42
std::string idToString(ID id)
Definition DMX.cpp:19
constexpr ID decodeID(IDv1 id)
Definition DMX.h:221
constexpr ID innerIDToArrayID(ID id)
Definition DMX.h:507
sourcepp::math::Vec4f Vector4
Definition DMX.h:44
sourcepp::math::Vec2f Vector2
Definition DMX.h:40
std::vector< std::byte > ByteArray
Definition DMX.h:27
constexpr std::byte encodeID(ID id, IDVersion version, bool &incompatible)
Definition DMX.h:330
Definition DMX.h:13
Vec4f Quat
Definition Math.h:333
Vec3f EulerAngles
Definition Math.h:331
static constexpr int32_t NULL_INDEX
Definition DMX.h:23
static constexpr int32_t EXTERNAL_INDEX
Definition DMX.h:24
std::string externalGUID
Definition DMX.h:21