CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
OdVector.h
Go to the documentation of this file.
1// FELIX_CHANGE_BEGIN file was take from ODA gitlab repository https://gitlab.opendesign.com/
3// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
4// All rights reserved.
5//
6// This software and its documentation and related materials are owned by
7// the Alliance. The software may only be incorporated into application
8// programs owned by members of the Alliance, subject to a signed
9// Membership Agreement and Supplemental Software License Agreement with the
10// Alliance. The structure and organization of this software are the valuable
11// trade secrets of the Alliance and its suppliers. The software is also
12// protected by copyright law and international treaty provisions. Application
13// programs incorporating this software must include the following statement
14// with their copyright notices:
15//
16// This application incorporates Open Design Alliance software pursuant to a license
17// agreement with Open Design Alliance.
18// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
19// All rights reserved.
20//
21// By use of this software, its documentation or related materials, you
22// acknowledge and accept the above terms.
24
25#ifndef OdVector_H_INCLUDED
26#define OdVector_H_INCLUDED
27
28#include <new>
29#include <utility>
30
31#include "TD_PackPush.h"
32
33#include "OdArrayMemAlloc.h"
34#include "OdAlloc.h"
35
36template <class T, class A = OdObjectsAllocator<T>, class Mm = OdrxMemoryManager> class OdVector;
37
64template <class T, class A, class Mm> class OdVector
65{
66public:
67 using size_type = typename A::size_type;
68 using iterator = T*;
69 using const_iterator = const T*;
70 // compatibility with OdArray
71 using value_type = T;
72 using const_reference = const T&;
73 using reference = T&;
74 using ConstForPtrT = typename std::conditional<std::is_pointer<T>::value,
75 typename std::add_const<typename std::remove_pointer<T>::type>::type*, T>::type;
76
77private:
78 static T* allocate(size_type physicalLength);
79
80 size_type calcPhysicalLength(size_type minPhysicalLength)
81 {
82 if (m_growLength > 0)
83 {
84 return ((minPhysicalLength + m_growLength - 1) / m_growLength) * m_growLength;
85 }
86 else
87 {
88 size_type newPhysicalLength = m_logicalLength + (-m_growLength)*m_logicalLength / 100;
89
90 if (newPhysicalLength < minPhysicalLength)
91 newPhysicalLength = minPhysicalLength;
92
93 return newPhysicalLength;
94 }
95 }
96
97 void release();
98
99 void reallocate(size_type physicalLength, bool isUseRealloc = false, bool isForcePhysicalLength = false);
100
101 bool isValid(size_type index) const;
102 void assertValid(size_type index) const;
103
104 static void riseError(OdResult res);
105
106 const_iterator begin_const() const;
107 iterator begin_non_const();
108 const_iterator end_const() const;
109 iterator end_non_const();
110
111public:
119
124
130 OdVector(const OdVector& vec);
131
138
143
146
151
156
161
166
177
187 void insertMove(iterator before, iterator first, iterator afterLast);
188
196 iterator insert(iterator before, size_type numElem, const T& value);
197
204 iterator insert(iterator before, const T& value = T());
211 iterator insert(iterator before, T&& value = T());
212
224
236
247
258
268 bool remove(const T& value, size_type startIndex = 0);
269
279
288
296
302 bool empty() const;
303
311
318 void reserve(size_type reserveLength);
319
330
341
349
356
360 void clear();
361
367 void push_back(const T& value);
368
374 void push_back(T&& value);
375
383 bool contains(const ConstForPtrT& value, size_type startIndex = 0) const;
384
391
397 bool isEmpty() const;
398
405
412
418 int growLength() const;
419
425 const T* asArrayPtr() const;
426
432 const T* getPtr() const;
433
440
444 const T& operator[](size_type index) const;
445
450
458
465 const T& at(size_type index) const;
466
475
482 const T& getAt(size_type index) const;
483
489 T& first();
490
496 const T& first() const;
497
503 T& last();
504
510 const T& last() const;
511
519
527
535
543
551
559
564
569
570 bool operator==(const OdVector& vec) const;
571
579
588 bool find(const ConstForPtrT& value, size_type& index, size_type startIndex = 0) const;
589
600
611
621
628
636 OdVector& swap(size_type firstIndex, size_type secondIndex);
637
642 void swap(OdVector &other);
643
644private:
645 T* m_pData;
646 size_type m_physicalLength;
647 size_type m_logicalLength;
648 int m_growLength;
649};
650
651#define VEC_SIZE_TYPE typename OdVector<T, A, Mm>::size_type
652#define VEC_ITERATOR typename OdVector<T, A, Mm>::iterator
653#define VEC_CONST_ITERATOR typename OdVector<T, A, Mm>::const_iterator
654
655template<class T, class A, class Mm>
656inline OdVector<T, A, Mm>::OdVector(size_type physicalLength, int growLength)
657: m_pData(NULL), m_physicalLength(physicalLength), m_logicalLength(0)
658, m_growLength(growLength)
659{
660 if(m_growLength == 0)
661 {
662 ODA_FAIL();
663 m_growLength = -200;
664 }
665 if (m_physicalLength)
666 {
667 m_pData = allocate(m_physicalLength);
668 }
669}
670
671template <class T, class A, class Mm>
673: m_pData(NULL), m_physicalLength(0), m_logicalLength(0), m_growLength(-200)
674{
675}
676
677template <class T, class A, class Mm>
679: m_pData(NULL), m_physicalLength(vec.m_physicalLength)
680, m_logicalLength(vec.m_logicalLength), m_growLength(vec.m_growLength)
681{
682 static_assert(std::is_copy_constructible<T>::value, "Can not copy vector with non-copyable argument");
683 if(m_physicalLength > 0)
684 {
685 m_pData = allocate(m_physicalLength);
686
687 A::copyConstructRange(m_pData, vec.m_pData, m_logicalLength);
688 }
689}
690
691template <class T, class A, class Mm>
693 : m_pData(vec.m_pData), m_physicalLength(vec.m_physicalLength)
694 , m_logicalLength(vec.m_logicalLength), m_growLength(vec.m_growLength)
695{
696 vec.m_pData = nullptr;
697 vec.m_physicalLength = 0;
698 vec.m_logicalLength = 0;
699 vec.m_growLength = -200;
700}
701
702template <class T, class A, class Mm>
704{
705 release();
706}
707
708template <class T, class A, class Mm>
710{
711 static_assert(std::is_copy_constructible<T>::value, "Can not copy vector with non-copyable argument");
712 if(this != &vec)
713 {
714 release();
715 m_logicalLength = 0;
716 if (vec.m_logicalLength > 0)
717 {
718 m_pData = allocate(vec.m_logicalLength);
719 m_physicalLength = vec.m_logicalLength;
720 A::copyConstructRange(m_pData, vec.m_pData, vec.m_logicalLength);
721 m_logicalLength = vec.m_logicalLength;
722 }
723 }
724 return *this;
725}
726
727template <class T, class A, class Mm>
729{
730 if(this != &vec)
731 {
732 release();
733 m_pData = vec.m_pData;
734 m_physicalLength = vec.m_physicalLength;
735 m_logicalLength = vec.m_logicalLength;
736 m_growLength = vec.m_growLength;
737 vec.m_pData = nullptr;
738 vec.m_physicalLength = 0;
739 vec.m_logicalLength = 0;
740 vec.m_growLength = -200;
741 }
742 return *this;
743}
744
745template <class T, class A, class Mm>
746inline T* OdVector<T, A, Mm>::allocate(size_type physicalLength)
747{
748 ODA_ASSERT(physicalLength != 0);
749 const size_type numByte = physicalLength*sizeof(T);
750
751 ODA_ASSERT(numByte >= physicalLength); // size_type overflow
752
753 T* pData = ((numByte >= physicalLength)
754 ? reinterpret_cast<T*>(Mm::Alloc(numByte))
755 : NULL);
756
757 if(pData == NULL)
758 throw OdError(eOutOfMemory);
759
760 return pData;
761}
762
763template <class T, class A, class Mm>
764inline void OdVector<T, A, Mm>::release()
765{
766 if(m_pData != NULL)
767 {
768 A::destroyRange(m_pData, m_logicalLength);
769
770 Mm::Free(m_pData);
771 m_pData = NULL;
772 m_physicalLength = 0;
773 }
774}
775
776template <class T, class A, class Mm>
777inline void OdVector<T, A, Mm>::reallocate(size_type physicalLength, bool isUseRealloc, bool isForcePhysicalLength)
778{
779 T* pOldData = m_pData;
780 size_type newPhysicalLength = physicalLength;
781
782 if(!isForcePhysicalLength)
783 newPhysicalLength = calcPhysicalLength(physicalLength);
784
785 if(isUseRealloc && A::useRealloc() && m_logicalLength > 0 && m_pData != NULL)
786 {
787 m_pData = reinterpret_cast<T*>(Mm::Realloc(pOldData, newPhysicalLength*sizeof(T), m_physicalLength*sizeof(T)));
788
789 if (!m_pData)
790 throw OdError(eOutOfMemory);
791
792 m_physicalLength = newPhysicalLength;
793
794 if(physicalLength < m_logicalLength)
795 m_logicalLength = physicalLength;
796 }
797 else
798 {
799 T* pNewData = allocate(newPhysicalLength);
800 const size_type newLogicalLength = odmin(m_logicalLength, physicalLength);
801
802 A::moveConstructRange(pNewData, pOldData, newLogicalLength);
803
804 release();
805
806 m_pData = pNewData;
807 m_physicalLength = newPhysicalLength;
808 m_logicalLength = newLogicalLength;
809 }
810}
811
812template <class T, class A, class Mm>
813inline bool OdVector<T, A, Mm>::isValid(size_type index) const
814{
815 // index is unsigned here, no need >= 0 check
816 return (index < m_logicalLength);
817}
818
819template <class T, class A, class Mm>
820inline void OdVector<T, A, Mm>::assertValid(size_type index) const
821{
822 if(!isValid(index))
823 {
824 ODA_FAIL();
825 throw OdError_InvalidIndex();
826 }
827}
828
829template <class T, class A, class Mm>
831{
832 ODA_FAIL();
833 throw OdError(res);
834}
835
836template <class T, class A, class Mm>
838{
839 return begin();
840}
841
842template <class T, class A, class Mm>
844{
845 return begin();
846}
847
848template <class T, class A, class Mm>
850{
851 return end();
852}
853
854template <class T, class A, class Mm>
856{
857 return end();
858}
859
860template <class T, class A, class Mm>
862{
863 return (!isEmpty() ? m_pData : NULL);
864}
865
866template <class T, class A, class Mm>
868{
869 return (!isEmpty() ? m_pData : NULL);
870}
871
872template <class T, class A, class Mm>
874{
875 return (!isEmpty() ? m_pData + m_logicalLength : NULL);
876}
877
878template <class T, class A, class Mm>
880{
881 return (!isEmpty() ? m_pData + m_logicalLength : NULL);
882}
883
884template <class T, class A, class Mm>
886{
887#ifdef ODA_DIAGNOSTICS
888 if (first >= begin_const() && first < end_const() && before < afterLast)
889 throw OdError(L"Inserted iterator range will become invalid while inserting.");
890#endif
891 const size_type oldLogicalLength = m_logicalLength;
892 const size_type index = (size_type)(before - begin_const());
893
894 if(index <= m_logicalLength && afterLast >= first)
895 {
896 if(afterLast > first)
897 {
898 const size_type numElem = (size_type)(afterLast - first);
899 const size_type newLogicalLength = oldLogicalLength + numElem;
900
901 if (newLogicalLength <= m_physicalLength)
902 {
903 A::defaultConstructFill(m_pData + oldLogicalLength, numElem);
904 m_logicalLength = newLogicalLength;
905 T* pData = m_pData + index;
906
907 if (index != oldLogicalLength)
908 A::moveAssignRange(pData + numElem, pData, oldLogicalLength - index);
909
910 A::copyAssignRangeDisjoint(pData, first, numElem);
911 }
912 else
913 {
914 size_type newPhysicalLength = calcPhysicalLength(newLogicalLength);
915 T* pNewData = allocate(newPhysicalLength);
916 A::moveConstructRange(pNewData, m_pData, index);
917 if (first >= begin_const() && afterLast <= end_const()) {
918 size_type newBufFirst = (size_type)(first - begin_const());
919 first = pNewData + newBufFirst;
920 }
921 A::copyConstructRange(pNewData + index, first, numElem);
922 A::moveConstructRange(pNewData + index + numElem, m_pData + index, m_logicalLength - index);
923 release();
924 m_pData = pNewData;
925 m_physicalLength = newPhysicalLength;
926 m_logicalLength = newLogicalLength;
927 }
928 }
929 }
930 else
931 riseError(eInvalidInput);
932}
933
934template <class T, class A, class Mm>
935inline void OdVector<T, A, Mm>::insertMove(iterator before, iterator first, iterator afterLast)
936{
937#ifdef ODA_DIAGNOSTICS
938 if (first >= begin_const() && first < end_const() && before < afterLast)
939 throw OdError(L"Inserted iterator range will become invalid while inserting.");
940#endif
941 const size_type oldLogicalLength = m_logicalLength;
942 const size_type index = (size_type)(before - begin_const());
943
944 if (index <= m_logicalLength && afterLast >= first)
945 {
946 if (afterLast > first)
947 {
948 const size_type numElem = (size_type)(afterLast - first);
949 const size_type newLogicalLength = oldLogicalLength + numElem;
950
951 if (newLogicalLength <= m_physicalLength)
952 {
953 A::defaultConstructFill(m_pData + oldLogicalLength, numElem);
954 m_logicalLength = newLogicalLength;
955 T* pData = m_pData + index;
956
957 if (index != oldLogicalLength)
958 A::moveAssignRange(pData + numElem, pData, oldLogicalLength - index);
959
960 A::moveAssignRange(pData, first, numElem);
961 }
962 else
963 {
964 size_type newPhysicalLength = calcPhysicalLength(newLogicalLength);
965 T* pNewData = allocate(newPhysicalLength);
966 A::moveConstructRange(pNewData, m_pData, index);
967 if (first >= begin_const() && afterLast <= end_const()) {
968 size_type newBufFirst = (size_type)(first - begin_const());
969 first = pNewData + newBufFirst;
970 }
971 A::moveConstructRange(pNewData + index, first, numElem);
972 A::moveConstructRange(pNewData + index + numElem, m_pData + index, m_logicalLength - index);
973 release();
974 m_pData = pNewData;
975 m_physicalLength = newPhysicalLength;
976 m_logicalLength = newLogicalLength;
977 }
978 }
979 }
980 else
981 riseError(eInvalidInput);
982}
983
984template <class T, class A, class Mm>
986{
987 if (numElem == 0)
988 return before;
989
990 const size_type oldLogicalLength = m_logicalLength;
991 const size_type newLogicalLength = oldLogicalLength + numElem;
992 const size_type index = (size_type)(before - begin_const());
993
994 if (index == oldLogicalLength)
995 {
996 if (newLogicalLength <= m_physicalLength)
997 {
998 A::copyConstructFill(m_pData + oldLogicalLength, numElem, value);
999 }
1000 else
1001 {
1002 const T valueCopy(value);
1003 reallocate(newLogicalLength, true);
1004 A::copyConstructFill(m_pData + oldLogicalLength, numElem - 1, valueCopy);
1005 A::copyConstruct(m_pData + oldLogicalLength + numElem - 1, std::move(valueCopy));
1006 }
1007 m_logicalLength = newLogicalLength;
1008 }
1009 else if (index < oldLogicalLength)
1010 {
1011 const T valueCopy(value);
1012 if (newLogicalLength > m_physicalLength)
1013 reallocate(newLogicalLength, true);
1014
1015 A::defaultConstructFill(m_pData + oldLogicalLength, numElem);
1016
1017 m_logicalLength = newLogicalLength;
1018
1019 T* pData = m_pData + index;
1020
1021 A::moveAssignRange(pData + numElem, pData, oldLogicalLength - index);
1022
1023 while (numElem-- > 1)
1024 pData[numElem] = valueCopy;
1025 pData[0] = std::move(valueCopy);
1026 }
1027
1028 return (begin_non_const() + index);
1029}
1030
1031template <class T, class A, class Mm>
1033{
1034 const size_type index = (size_type)(before - begin_const());
1035
1036 insertAt(index, value);
1037
1038 return (begin_non_const() + index);
1039}
1040
1041template <class T, class A, class Mm>
1043{
1044 const size_type index = (size_type)(before - begin_const());
1045
1046 insertAt(index, std::move(value));
1047
1048 return (begin_non_const() + index);
1049}
1050
1051template <class T, class A, class Mm>
1053{
1054 const size_type oldLogicalLength = m_logicalLength;
1055 const size_type newLogicalLength = oldLogicalLength + 1;
1056
1057 if (index == oldLogicalLength)
1058 {
1059 push_back(value);
1060 }
1061 else if (index < oldLogicalLength)
1062 {
1063 const T valueCopy(value);
1064 if (newLogicalLength > m_physicalLength)
1065 reallocate(newLogicalLength, true);
1066
1067 A::defaultConstruct(m_pData + oldLogicalLength);
1068
1069 ++m_logicalLength;
1070
1071 T* pData = m_pData + index;
1072
1073 A::moveAssignRange(pData + 1, pData, oldLogicalLength - index);
1074
1075 *pData = std::move(valueCopy);
1076 }
1077 else
1078 riseError(eInvalidIndex);
1079
1080 return *this;
1081}
1082
1083template <class T, class A, class Mm>
1085{
1086 const size_type oldLogicalLength = m_logicalLength;
1087 const size_type newLogicalLength = oldLogicalLength + 1;
1088
1089 if (index == oldLogicalLength)
1090 {
1091 push_back(std::move(value));
1092 }
1093 else if (index < oldLogicalLength)
1094 {
1095 T valueMoved(std::move(value));
1096 if (newLogicalLength > m_physicalLength)
1097 reallocate(newLogicalLength, true);
1098
1099 A::defaultConstruct(m_pData + oldLogicalLength);
1100
1101 ++m_logicalLength;
1102
1103 T* pData = m_pData + index;
1104
1105 A::moveAssignRange(pData + 1, pData, oldLogicalLength - index);
1106
1107 *pData = std::move(valueMoved);
1108 }
1109 else
1110 riseError(eInvalidIndex);
1111
1112 return *this;
1113}
1114
1115template <class T, class A, class Mm>
1117{
1118 assertValid(index);
1119
1120 const size_type newLogicalLength = m_logicalLength - 1;
1121
1122 if(index < newLogicalLength)
1123 {
1124 T* pData = m_pData + index;
1125 A::moveAssignRange(pData, pData + 1, newLogicalLength - index);
1126 }
1127
1128 resize(newLogicalLength);
1129 return *this;
1130}
1131
1132template <class T, class A, class Mm>
1134{
1135 if(!isValid(startIndex) || startIndex > endIndex)
1136 riseError(eInvalidIndex);
1137
1138 const size_type oldLogicalLength = m_logicalLength;
1139
1140 T* pData = m_pData;
1141
1142 ++endIndex;
1143
1144 const size_type numElem = endIndex - startIndex;
1145
1146 A::moveAssignRange(pData + startIndex, pData + endIndex, oldLogicalLength - endIndex);
1147 A::destroyRange(pData + oldLogicalLength - numElem, numElem);
1148
1149 m_logicalLength -= numElem;
1150 return *this;
1151}
1152
1153template <class T, class A, class Mm>
1154inline bool OdVector<T, A, Mm>::remove(const T& value, size_type startIndex)
1155{
1156 size_type index = 0;
1157 if(find(value, index, startIndex))
1158 {
1159 removeAt(index);
1160 return true;
1161 }
1162 return false;
1163}
1164
1165template <class T, class A, class Mm>
1166inline void OdVector<T, A, Mm>::resize(size_type logicalLength, const T& value)
1167{
1168 const size_type oldLogicalLength = m_logicalLength;
1169 const int lengthDiff = logicalLength - oldLogicalLength;
1170
1171 if(lengthDiff > 0)
1172 {
1173 const T valueCopy(value);
1174 if (logicalLength > m_physicalLength)
1175 reallocate(logicalLength, true);
1176
1177 A::copyConstructFill(m_pData + oldLogicalLength, lengthDiff, valueCopy);
1178 }
1179 else if(lengthDiff < 0)
1180 A::destroyRange(m_pData + logicalLength, -lengthDiff);
1181
1182 m_logicalLength = logicalLength;
1183}
1184
1185template <class T, class A, class Mm>
1186inline void OdVector<T, A, Mm>::resize(size_type logicalLength)
1187{
1188 const size_type oldLogicalLength = m_logicalLength;
1189 const int lengthDiff = logicalLength - oldLogicalLength;
1190
1191 if(lengthDiff > 0)
1192 {
1193 if(logicalLength > m_physicalLength)
1194 reallocate(logicalLength, true);
1195 A::defaultConstructFill(m_pData + oldLogicalLength, lengthDiff);
1196 }
1197 else if(lengthDiff < 0)
1198 A::destroyRange(m_pData + logicalLength, -lengthDiff);
1199
1200 m_logicalLength = logicalLength;
1201}
1202
1203template <class T, class A, class Mm>
1205{
1206 return m_logicalLength;
1207}
1208
1209template <class T, class A, class Mm>
1210inline bool OdVector<T, A, Mm>::empty() const
1211{
1212 return (m_logicalLength == 0);
1213}
1214
1215template <class T, class A, class Mm>
1217{
1218 return m_physicalLength;
1219}
1220
1221template <class T, class A, class Mm>
1222inline void OdVector<T, A, Mm>::reserve(size_type reserveLength)
1223{
1224 if(m_physicalLength < reserveLength)
1225 setPhysicalLength(reserveLength);
1226}
1227
1228template <class T, class A, class Mm>
1230{
1231#ifdef ODA_DIAGNOSTICS
1232 if (first >= begin_const() && first < end_const())
1233 throw OdError(L"Assignment of a subrange from self is not allowed.");
1234#endif
1235 clear();
1236 insert(begin_non_const(), first, afterLast);
1237}
1238
1239template <class T, class A, class Mm>
1241{
1242#ifdef ODA_DIAGNOSTICS
1243 if (first >= begin_const() && first < end_const())
1244 throw OdError(L"Assignment of a subrange from self is not allowed.");
1245#endif
1246 clear();
1247 insertMove(begin_non_const(), first, afterLast);
1248}
1249
1250template <class T, class A, class Mm>
1252{
1253 const size_type index = (size_type)(first - begin_const());
1254
1255 if(first != afterLast)
1256 removeSubArray(index, (size_type)(afterLast - begin_const() - 1));
1257
1258 return (begin_non_const() + index);
1259}
1260
1261template <class T, class A, class Mm>
1263{
1264 const size_type index = (size_type)(it - begin_const());
1265
1266 removeAt(index);
1267
1268 return (begin_non_const() + index);
1269}
1270
1271template <class T, class A, class Mm>
1273{
1274 const size_type numElem = (size_type)(end_const() - begin_const());
1275 A::destroyRange(m_pData, numElem);
1276 m_logicalLength = 0;
1277}
1278
1279template <class T, class A, class Mm>
1281{
1282 if (m_physicalLength > m_logicalLength)
1283 {
1284 A::copyConstruct(m_pData + m_logicalLength, value);
1285 }
1286 else
1287 {
1288 const T valueCopy(value);
1289 reallocate(m_logicalLength + 1, true);
1290 A::copyConstruct(m_pData + m_logicalLength, std::move(valueCopy));
1291 }
1292 ++m_logicalLength;
1293}
1294
1295template <class T, class A, class Mm>
1297{
1298 if (m_physicalLength > m_logicalLength)
1299 {
1300 A::moveConstruct(m_pData + m_logicalLength, std::move(value));
1301 }
1302 else
1303 {
1304 T valueMoved(std::move(value));
1305 reallocate(m_logicalLength + 1, true);
1306 A::moveConstruct(m_pData + m_logicalLength, std::move(valueMoved));
1307 }
1308 ++m_logicalLength;
1309}
1310
1311template <class T, class A, class Mm>
1312inline bool OdVector<T, A, Mm>::contains(const ConstForPtrT& value, size_type startIndex) const
1313{
1315
1316 return find(value, index, startIndex);
1317}
1318
1319template <class T, class A, class Mm>
1321{
1322 return m_logicalLength;
1323}
1324
1325template <class T, class A, class Mm>
1327{
1328 return (m_logicalLength == 0);
1329}
1330
1331template <class T, class A, class Mm>
1333{
1334 return m_logicalLength;
1335}
1336
1337template <class T, class A, class Mm>
1339{
1340 return m_physicalLength;
1341}
1342
1343template <class T, class A, class Mm>
1345{
1346 return m_growLength;
1347}
1348
1349template <class T, class A, class Mm>
1350inline const T* OdVector<T, A, Mm>::asArrayPtr() const
1351{
1352 return m_pData;
1353}
1354
1355template <class T, class A, class Mm>
1356inline const T* OdVector<T, A, Mm>::getPtr() const
1357{
1358 return m_pData;
1359}
1360
1361template <class T, class A, class Mm>
1363{ // OdArray::asArrayPtr invokes non-const version of data() method which checks length and return null.
1364 // Constant version of asArrayPtr and getPtr will return m_pData as is for OdArray too.
1365 return (length()) ? m_pData : NULL;
1366}
1367
1368template <class T, class A, class Mm>
1370{
1371 assertValid(index);
1372 return m_pData[index];
1373}
1374
1375template <class T, class A, class Mm>
1377{
1378 assertValid(index);
1379 return m_pData[index];
1380}
1381
1382template <class T, class A, class Mm>
1384{
1385 assertValid(index);
1386 return m_pData[index];
1387}
1388
1389template <class T, class A, class Mm>
1391{
1392 assertValid(index);
1393 return m_pData[index];
1394}
1395
1396template <class T, class A, class Mm>
1398{
1399 assertValid(index);
1400
1401 m_pData[index] = value;
1402
1403 return *this;
1404}
1405
1406template <class T, class A, class Mm>
1408{
1409 assertValid(index);
1410 return m_pData[index];
1411}
1412
1413template <class T, class A, class Mm>
1415{
1416 return m_pData[0];
1417}
1418
1419template <class T, class A, class Mm>
1420inline const T& OdVector<T, A, Mm>::first() const
1421{
1422 return m_pData[0];
1423}
1424
1425template <class T, class A, class Mm>
1427{
1428 return m_pData[m_logicalLength - 1];
1429}
1430
1431template <class T, class A, class Mm>
1432inline const T& OdVector<T, A, Mm>::last() const
1433{
1434 return m_pData[m_logicalLength - 1];
1435}
1436
1437template <class T, class A, class Mm>
1439{
1440 push_back(value);
1441 return (m_logicalLength - 1);
1442}
1443template <class T, class A, class Mm>
1445{
1446 push_back(std::move(value));
1447 return (m_logicalLength - 1);
1448}
1449
1450template <class T, class A, class Mm>
1452{
1453 const size_type index = append(T());
1454 return (begin_non_const() + index);
1455}
1456
1457template <class T, class A, class Mm>
1459{
1460 insert(end_non_const(), vec.begin(), vec.end());
1461 return *this;
1462}
1463
1464template <class T, class A, class Mm>
1466{
1467 insertMove(end_non_const(), vec.begin(), vec.end());
1468 return *this;
1469}
1470
1471template <class T, class A, class Mm>
1473{
1474 return appendMove(vec);
1475}
1476
1477template <class T, class A, class Mm>
1479{
1480 return removeAt(0);
1481}
1482
1483template <class T, class A, class Mm>
1485{
1486 return removeAt(m_logicalLength - 1);
1487}
1488
1489template <class T, class A, class Mm>
1491{
1492 if(m_logicalLength == vec.m_logicalLength)
1493 {
1494 for(size_type i = 0; i < m_logicalLength; ++i)
1495 {
1496 if(m_pData[i] != vec.m_pData[i])
1497 return false;
1498 }
1499 return true;
1500 }
1501 return false;
1502}
1503
1504template <class T, class A, class Mm>
1506{
1507 for(size_type i = 0; i < m_logicalLength; ++i)
1508 m_pData[i] = value;
1509
1510 return *this;
1511}
1512
1513template <class T, class A, class Mm>
1515{
1516 if(!isEmpty())
1517 {
1518 assertValid(startIndex);
1519
1520 for(size_type i = startIndex; i < m_logicalLength; ++i)
1521 {
1522 if(m_pData[i] == value)
1523 {
1524 index = i;
1525 return true;
1526 }
1527 }
1528 }
1529 return false;
1530}
1531
1532template <class T, class A, class Mm>
1534{
1535 resize(logicalLength);
1536 return *this;
1537}
1538
1539template <class T, class A, class Mm>
1541{
1542 if(physicalLength == 0)
1543 {
1544 release();
1545
1546 m_pData = NULL;
1547 m_physicalLength = 0;
1548 }
1549 else if(physicalLength != m_physicalLength)
1550 reallocate(physicalLength, true, true);
1551
1552 if(m_physicalLength < m_logicalLength)
1553 m_logicalLength = m_physicalLength;
1554
1555 return *this;
1556}
1557
1558template <class T, class A, class Mm>
1560{
1561 if(growLength != 0)
1562 m_growLength = growLength;
1563 else
1564 ODA_FAIL();
1565
1566 return *this;
1567}
1568
1569template <class T, class A, class Mm>
1571{
1572 if(!isEmpty())
1573 {
1574 T value;
1575 iterator it1 = begin_non_const();
1576 iterator it2 = end_non_const();
1577
1578 --it2;
1579
1580 while(it1 < it2)
1581 {
1582 value = *it1;
1583 *it1 = *it2;
1584 *it2 = value;
1585
1586 ++it1;
1587 --it2;
1588 }
1589 }
1590 return *this;
1591}
1592
1593template <class T, class A, class Mm>
1595{
1596 if(!isValid(firstIndex) || !isValid(secondIndex))
1597 riseError(eInvalidIndex);
1598
1599 if(firstIndex != secondIndex)
1600 {
1601 T value = std::move(m_pData[firstIndex]);
1602 m_pData[firstIndex] = std::move(m_pData[secondIndex]);
1603 m_pData[secondIndex] = std::move(value);
1604 }
1605
1606 return *this;
1607}
1608
1609template <class T, class A, class Mm>
1611{
1612 T* ptr = m_pData;
1613 m_pData = other.m_pData;
1614 other.m_pData = ptr;
1615 size_type sz = m_physicalLength;
1616 m_physicalLength = other.m_physicalLength;
1617 other.m_physicalLength = sz;
1618 sz = m_logicalLength;
1619 m_logicalLength = other.m_logicalLength;
1620 other.m_logicalLength = sz;
1621 int tmpi = m_growLength;
1622 m_growLength = other.m_growLength;
1623 other.m_growLength = tmpi;
1624}
1625
1626
1627#include "TD_PackPop.h"
1628
1635#ifdef OD_GEPNT3D_H
1637#endif
1638#ifdef OD_GEVEC3D_H
1640#endif
1641
1642#endif // OdVector_H_INCLUDED
1643// FELIX_CHANGE_END file was take from ODA gitlab repository https://gitlab.opendesign.com/
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:57
#define ODA_FAIL()
Definition: DebugStuff.h:88
#define odmin(X, Y)
Definition: OdPlatform.h:34
OdResult
Definition: OdResult.h:29
#define VEC_CONST_ITERATOR
Definition: OdVector.h:653
#define VEC_SIZE_TYPE
Definition: OdVector.h:651
OdVector< bool, OdMemoryAllocator< bool > > OdBoolVector
Definition: OdVector.h:1634
OdVector< OdUInt8, OdMemoryAllocator< OdUInt8 > > OdUInt8Vector
Definition: OdVector.h:1632
OdVector< OdUInt64, OdMemoryAllocator< OdUInt64 > > OdUInt64Vector
Definition: OdVector.h:1633
OdVector< int, OdMemoryAllocator< int > > OdIntVector
Definition: OdVector.h:1629
#define VEC_ITERATOR
Definition: OdVector.h:652
OdVector< OdInt32, OdMemoryAllocator< OdInt32 > > OdInt32Vector
Definition: OdVector.h:1631
OdVector< OdUInt32, OdMemoryAllocator< OdUInt32 > > OdUInt32Vector
Definition: OdVector.h:1630
OdVector & reverse()
Definition: OdVector.h:1570
const_iterator begin() const
Definition: OdVector.h:867
iterator append()
Definition: OdVector.h:1451
OdVector & setAll(const T &value)
Definition: OdVector.h:1505
const_iterator end() const
Definition: OdVector.h:879
void reserve(size_type reserveLength)
Definition: OdVector.h:1222
iterator insert(iterator before, size_type numElem, const T &value)
Definition: OdVector.h:985
iterator insert(iterator before, T &&value=T())
Definition: OdVector.h:1042
OdVector & setGrowLength(int growLength)
Definition: OdVector.h:1559
OdVector & removeSubArray(size_type startIndex, size_type endIndex)
Definition: OdVector.h:1133
bool empty() const
Definition: OdVector.h:1210
const T & operator[](size_type index) const
Definition: OdVector.h:1369
typename A::size_type size_type
Definition: OdVector.h:67
OdVector & removeLast()
Definition: OdVector.h:1484
T & operator[](size_type index)
Definition: OdVector.h:1376
bool find(const ConstForPtrT &value, size_type &index, size_type startIndex=0) const
Definition: OdVector.h:1514
OdVector(OdVector &&vec)
Definition: OdVector.h:692
OdVector()
Definition: OdVector.h:672
iterator erase(iterator where)
Definition: OdVector.h:1262
bool remove(const T &value, size_type startIndex=0)
Definition: OdVector.h:1154
iterator begin()
Definition: OdVector.h:861
iterator insert(iterator before, const T &value=T())
Definition: OdVector.h:1032
size_type length() const
Definition: OdVector.h:1320
void clear()
Definition: OdVector.h:1272
size_type physicalLength() const
Definition: OdVector.h:1338
iterator erase(iterator first, iterator afterLast)
Definition: OdVector.h:1251
const T & first() const
Definition: OdVector.h:1420
OdVector & operator=(OdVector &&vec)
Definition: OdVector.h:728
void resize(size_type logicalLength, const T &value)
Definition: OdVector.h:1166
void push_back(T &&value)
Definition: OdVector.h:1296
OdVector & append(const OdVector &vec)
Definition: OdVector.h:1458
const T & at(size_type index) const
Definition: OdVector.h:1390
~OdVector()
Definition: OdVector.h:703
void push_back(const T &value)
Definition: OdVector.h:1280
OdVector & insertAt(size_type index, const T &value)
Definition: OdVector.h:1052
const T & getAt(size_type index) const
Definition: OdVector.h:1407
size_type size() const
Definition: OdVector.h:1204
const T * const_iterator
Definition: OdVector.h:69
void assign(const_iterator first, const_iterator afterLast)
Definition: OdVector.h:1229
T & first()
Definition: OdVector.h:1414
const T * asArrayPtr() const
Definition: OdVector.h:1350
const T * getPtr() const
Definition: OdVector.h:1356
size_type append(const T &value)
Definition: OdVector.h:1438
size_type logicalLength() const
Definition: OdVector.h:1332
T * asArrayPtr()
Definition: OdVector.h:1362
size_type capacity() const
Definition: OdVector.h:1216
void insertMove(iterator before, iterator first, iterator afterLast)
Definition: OdVector.h:935
typename std::conditional< std::is_pointer< T >::value, typename std::add_const< typename std::remove_pointer< T >::type >::type *, T >::type ConstForPtrT
Definition: OdVector.h:75
OdVector & setLogicalLength(size_type logicalLength)
Definition: OdVector.h:1533
bool isEmpty() const
Definition: OdVector.h:1326
OdVector & removeAt(size_type index)
Definition: OdVector.h:1116
OdVector & setPhysicalLength(size_type physicalLength)
Definition: OdVector.h:1540
T * iterator
Definition: OdVector.h:68
size_type append(T &&value)
Definition: OdVector.h:1444
void resize(size_type logicalLength)
Definition: OdVector.h:1186
OdVector & swap(size_type firstIndex, size_type secondIndex)
Definition: OdVector.h:1594
bool operator==(const OdVector &vec) const
Definition: OdVector.h:1490
OdVector & operator=(const OdVector &vec)
Definition: OdVector.h:709
OdVector(size_type physicalLength, int growLength=8)
Definition: OdVector.h:656
T & reference
Definition: OdVector.h:73
int growLength() const
Definition: OdVector.h:1344
void swap(OdVector &other)
Definition: OdVector.h:1610
void insert(iterator before, const_iterator first, const_iterator afterLast)
Definition: OdVector.h:885
bool contains(const ConstForPtrT &value, size_type startIndex=0) const
Definition: OdVector.h:1312
T & at(size_type index)
Definition: OdVector.h:1383
OdVector(const OdVector &vec)
Definition: OdVector.h:678
OdVector & removeFirst()
Definition: OdVector.h:1478
T & last()
Definition: OdVector.h:1426
iterator end()
Definition: OdVector.h:873
void assignMove(iterator first, iterator afterLast)
Definition: OdVector.h:1240
OdVector & appendMove(OdVector &vec)
Definition: OdVector.h:1465
T value_type
Definition: OdVector.h:71
const T & const_reference
Definition: OdVector.h:72
OdVector & append(OdVector &&vec)
Definition: OdVector.h:1472
OdVector & insertAt(size_type index, T &&value)
Definition: OdVector.h:1084
OdVector & setAt(size_type index, const T &value)
Definition: OdVector.h:1397
const T & last() const
Definition: OdVector.h:1432
GLuint index
Definition: gles2_ext.h:265
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
GLuint GLsizei GLsizei * length
Definition: gles2_ext.h:274
GLsizei const GLfloat * value
Definition: gles2_ext.h:302