3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
classlist.h
1
2class APICALL Delimiter: public BaseClass{
3public:
4 virtual bool ForceProperty(){
5 return true;
6 }
7 const char* GetClassName() const override{
8 return "Delimiter";
9 }
10 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override{
11 return true;
12 }
13 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override{}
14 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override{}
15 AUTONEW(Delimiter);
16};
17extern APICALL Delimiter& GDLM();
18class APICALL _cStr : public BaseClass {
19public:
20 _cStr() {};
21 ~_cStr() {
22 }
23
24 virtual void Save(TagsList& xml, void* ClassPtr, void* Extra = NULL) override;
25 virtual bool Load(TagsList& xml,void* ClassPtr,void* Extra = NULL) override;
26 virtual const char* GetClassName() const override {
27 return "_cStr";
28 }
29 virtual void reset_class(void* ptr);
30 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override;
31 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override;
32 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override;
33 virtual void UpdateHash(HashSummator& H, void* data = nullptr, void* extra = nullptr) override;
34
35 AUTONEW(_cStr);
36};//_cStr
37reg_auto_specialisation_template(_cStr, comms::cStr);
38
42class StringsList: public BaseClass, comms::cList<comms::cStr*> {
43 comms::cStr* elem(int idx);
44 const comms::cStr* elem(int idx) const;
45public:
48 StringsList(const StringsList& r);
49 void operator = (const StringsList& Src);
50
51 int Count() const ;
52 int GetAmount() const;
53 const comms::cStr& operator[](int pos) const ;
54 comms::cStr& operator[](int pos);
55 void Clear();
56 void Free();
57 int Add(const char* str);
58 //int Add(comms::cStr* str);
59 void RemoveAt(int pos, int num = 1);
60 int IndexOf(const char* str) const;
61 void Split(const char* WhatToSplit, const char* delimiters = " ,;\t");
62 const char* GetLast() const;
63 comms::cStr& GetLast();
64 comms::cStr& GetAt(int idx);
65 const comms::cStr& GetAt(int idx) const;
66 void Insert(int pos, const char* str);
67 bool IsEmpty() const ;
68 const char* GetFirst() const;
69 comms::cStr& GetFirst();
70 void RemoveLast();
71 int AddOnce(const char* str);
72 void Sort(cList<comms::cStr>::Compare* C);
73 void Sort(const cList<comms::cStr>::CompareFunctor& F);
74 void Sort(const int Index, const int Count, cList<comms::cStr>::Compare* C);
75 void Sort(int Index, int Count, const cList<comms::cStr>::CompareFunctor& F);
76
77 comms::cList<comms::cStr> ToList() const ;
78 void FromList(const cList<comms::cStr>& list);
79
80 virtual bool DelElement(int Index) override;
81
82 virtual void Save(TagsList& xml, void* ClassPtr, void* Extra = NULL) override;
83 virtual bool Load(TagsList& xml, void* ClassPtr, void* Extra = NULL) override;
84 virtual const char* GetClassName() const override {
85 return "ClassArray._str";
86 }
87 virtual void reset_class(void* ptr);
88 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override;
89 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override;
90 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override;
91 virtual void UpdateHash(HashSummator& H, void* data = nullptr, void* extra = nullptr) override;
92 virtual bool CheckDirectCasting() const override {
93 return true;
94 }
95
96 virtual void CountObjects(int& required_index, int* counter, HashSummator* hash, BaseClassElement* result,
97 const std::function<bool(BaseClassElement*)>* ForEachElem, bool OnlyPointersMode) override;
98
99 AUTONEW(StringsList);
100
101 struct iterator {
102 int pos;
103 const StringsList* array;
104
105 iterator() {}
106 iterator(int v, StringsList* b) : pos(v), array(b) {}
107 iterator(int v, const StringsList* b) : pos(v), array(b) {}
108 void operator ++() {
109 pos++;
110 }
111 bool operator != (const iterator& itr) const {
112 return pos != itr.pos;
113 }
114 const char* operator*() {
115 return (*array)[pos];
116 }
117 };
118 iterator begin() {
119 return { 0, this };
120 }
121 iterator end() {
122 return { Count(), this };
123 }
124 iterator begin() const {
125 return { 0, this };
126 }
127 iterator end() const {
128 return { Count(), this };
129 }
130};
131class APICALL _int :public BaseClass {
132public:
133 virtual void Save(TagsList& xml, void* ClassPtr, void* Extra = NULL) override;
134 virtual bool Load(TagsList& xml,void* ClassPtr,void* Extra = NULL) override;
135 virtual const char* GetClassName() const override;
136 virtual void reset_class(void* ptr) {
137 *((int*)ptr) = 0;
138 }
139 virtual bool CheckCompartabilityWith(const char* TypeName, int TypeSize) {
140 return TypeSize == 4;
141 }
142 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override {
143 *((int*)DestData) = *((int*)SrcData);
144 return true;
145 }
146 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override;
147 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override;
148 virtual void UpdateHash(HashSummator& H, void* data = nullptr, void* extra = nullptr) override;
149 AUTONEW(_int);
150};
151reg_auto_specialisation_template(_int, int);
152
153class APICALL _float :public BaseClass {
154public:
155 static bool DontUseInHash;
156 virtual void Save(TagsList& xml, void* ClassPtr, void* Extra = NULL) override;
157 virtual bool Load(TagsList& xml,void* ClassPtr,void* Extra = NULL) override;
158 virtual const char* GetClassName() const override;
159 virtual void reset_class(void* ptr) {
160 *((float*)ptr) = 0.0f;
161 }
162 virtual bool CheckCompartabilityWith(const char* TypeName, int TypeSize) {
163 return !strcmp(TypeName, "float");
164 }
165 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override {
166 *((int*)DestData) = *((int*)SrcData);
167 return true;
168 }
169 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override;
170 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override;
171 virtual void UpdateHash(HashSummator& H, void* data = nullptr, void* extra = nullptr) override;
172 AUTONEW(_float);
173}; // class _float
174reg_auto_specialisation_template(_float, float);
175//-----------------------------------------------------------------------------
176// CtrlISlider
177//-----------------------------------------------------------------------------
178class APICALL CtrlISlider : public _int {
179public:
180 static bool ZeroHash;
181 virtual void UpdateHash(HashSummator& H, void* data = nullptr, void* extra = nullptr) override {
182 if(!ZeroHash)_int::UpdateHash(H, data, extra);
183 }
184 virtual const char* GetClassName() const override { return "CtrlISlider"; }
185 AUTONEW(CtrlISlider);
186 virtual BaseWidget* OnCreateControlFromScratch(const ClassEditorContext& Context, Rct& Rect);
187};
188
189class __state : public _int {
190public:
191 AUTONEW(__state);
192 virtual BaseWidget* OnCreateControlFromScratch(const ClassEditorContext& Context, Rct& Rect);
193};
194
195struct CtrlISliderArgs {
196 int MinValue;
197 int MaxValue;
198 int DefValue;
199};
200
201//-----------------------------------------------------------------------------
202// CtrlFSlider
203//-----------------------------------------------------------------------------
204class APICALL CtrlFSlider : public _float {
205public:
206 static bool ZeroHash;
207 virtual void UpdateHash(HashSummator& H, void* data = nullptr, void* extra = nullptr) override {
208 if(!ZeroHash)_float::UpdateHash(H, data, extra);
209 }
210 virtual const char* GetClassName() const override { return "CtrlFSlider"; }
211 AUTONEW(CtrlFSlider);
212 virtual BaseWidget* OnCreateControlFromScratch(const ClassEditorContext& Context, Rct& Rect);
213
214};
215
216struct CtrlFSliderArgs {
217 CtrlFSliderArgs() {
218 MinValue = 0;
219 MaxValue = 1;
220 DefValue = 1;
221 VisModulator = 1;
222 Inv = false;
223 SwapEnds = false;
224 }
225 float MinValue;
226 float MaxValue;
227 float DefValue;
228 float VisModulator;
229 bool Inv;
230 bool SwapEnds;
231};
232struct __slider_container {
233 __slider_container();
234 __slider_container(BaseClass* _b, void* _p) {
235 b = _b;
236 p = _p;
237 }
238 BaseClass* b;
239 void* p;
240};
241template <class tp>
242__slider_container GetSliderContainer(tp minvalue, tp maxvalue)
243{
244 //comms::cMessageBox::Ok("SLIDER registration error!", "SLIDER may not be bound to the type \"%s\"", typeid(tp).name());
245 return __slider_container(nullptr, nullptr);
246}
247template <>
248inline __slider_container GetSliderContainer(float minvalue, float maxvalue)
249{
250 CtrlFSliderArgs* arg = new CtrlFSliderArgs;
251 arg->MinValue = minvalue;
252 arg->MaxValue = maxvalue;
253 return __slider_container(CGARB().GetClass("CtrlFSlider")->OneMemb, (void*)arg);
254}
255template <>
256inline __slider_container GetSliderContainer(int minvalue, int maxvalue)
257{
258 CtrlISliderArgs* arg = new CtrlISliderArgs;
259 arg->MinValue = minvalue;
260 arg->MaxValue = maxvalue;
261 return __slider_container(CGARB().GetClass("CtrlISlider")->OneMemb, (void*)arg);
262}
263class APICALL _bool :public BaseClass {
264public:
265 virtual void Save(TagsList& xml, void* ClassPtr, void* Extra = NULL) override;
266 virtual bool Load(TagsList& xml,void* ClassPtr,void* Extra = NULL) override;
267 virtual const char* GetClassName() const override;
268 virtual void reset_class(void* ptr) {
269 *((bool*)ptr) = false;
270 }
271 virtual bool CheckCompartabilityWith(const char* TypeName, int TypeSize) {
272 return TypeSize == 1;
273 }
274 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override {
275 *((BYTE*)DestData) = *((BYTE*)SrcData);
276 return true;
277 }
278 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override;
279 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override;
280 virtual void UpdateHash(HashSummator& H, void* data = nullptr, void* extra = nullptr) override;
281 BaseWidget* OnCreateControlFromScratch(const ClassEditorContext& Context, Rct& Rect);
282 AUTONEW(_bool);
283}; // class _bool
284reg_auto_specialisation_template(_bool, bool);
285
286class APICALL _index :public BaseClass {
287public:
288 virtual bool CheckCompartabilityWith(const char* TypeName, int TypeSize) {
289 return TypeSize == 4;
290 }
291 virtual void Save(TagsList& xml, void* ClassPtr, void* Extra = NULL) override {
292 if (Extra) {
293 Enumerator* E = (Enumerator*)Extra;
294 xml.Assign(E->Get(*((int*)ClassPtr)));
295 }
296 }
297 virtual bool Load(TagsList& xml,void* ClassPtr,void* Extra = NULL) override {
298 if (Extra) {
299 Enumerator* E = (Enumerator*)Extra;
300 const char* s = xml.to_string();
301 if (s) {
302 int p = E->Get((char*)xml.to_string());
303 if (p != -1) {
304 *((int*)ClassPtr) = E->Get((char*)xml.to_string());
305 }
306 else {
307 *((int*)ClassPtr) = E->GetVal(0);
308 //Error->xml_print(xml,"identifier \"%s\" not found in list \"%s\" for variable \"%s\"\n",xml.Get_string(),E->EnumeratorID,xml.GetQuoteName());
309 }
310 }
311 else {
312 *((int*)ClassPtr) = E->GetVal(0);
313 //Error->xml_print(xml,"xml node is empty for variable %s\n",xml.GetQuoteName());
314 }
315 return true;
316 }
317 return false;
318 }
319 virtual const char* GetClassName() const override {
320 return "_index";
321 }
322 virtual void reset_class(void* ptr) {
323 *((int*)ptr) = 0;
324 }
325 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override {
326 *((int*)DestData) = *((int*)SrcData);
327 return true;
328 }
329 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override;
330 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override;
331 virtual void UpdateHash(HashSummator& H, void* data = nullptr, void* extra = nullptr) override;
332 AUTONEW(_index);
333};
334
340template<class X>class ClassArray :public BaseClass, public comms::cList<X*> {
341public:
342 ClassArray() {
343
344 }
345 ClassArray(const ClassArray<X>& src);
346 void operator = (const ClassArray<X>& src);
347 virtual ~ClassArray() {
348 reset_class(this);
349 };
350 virtual void reset_class(void* ptr) {
351 ClassArray<X>* CA = (ClassArray<X>*)ptr;
352 for (int i = 0; i < CA->Count(); i++)if ((*CA)[i]) {
353 //try{
354 delete((*CA)[i]);
355 //}catch(...){
356 //}
357 CA->ToPtr()[i] = NULL;
358 }
359 CA->Free();
360 }
361 void Clear() {
362 reset_class(this);
363 }
364 const char* GetClassName() const override {
365 static char N[64] = "";
366 if (N[0] != 'C') {
367 X* x = new X;
368 sprintf_s(N, sizeof(N), "ClassArray.%s", x->GetClassName());
369 delete(x);
370 }
371 return N;
372 }
373 int GetAmountOfElements() override {
374 return comms::cList<X*>::Count();
375 }
376 virtual void CountObjects(int& required_index, int* counter, HashSummator* hash, BaseClassElement* result, const std::function<bool(BaseClassElement*)>* ForEachElem, bool OnlyPointersMode) override {
377 if (counter)* counter += GetAmountOfElements();
378 if(hash) {
379 bool pa = MayBeParent();
380 for(int i=0;i<GetAmountOfElements();i++) {
381 BaseClass* B = (*this)[i];
382 if (B) {
383 B->UpdateHash(*hash, nullptr, nullptr);
384 if(pa && B->UsePointerInHashCalculation())(*hash) << cPtrDiff(B);
385 }
386 }
387 }
388 if (ForEachElem) {
389 for (int i = 0; i < GetAmountOfElements(); i++) {
390 BaseClass* elm = (*this)[i];
391 result->BC = elm;
392 if(!OnlyPointersMode)result->ID = elm ? elm->GetClassName() : NULL;
393 result->Ptr = elm;
394 if ((*ForEachElem)(result))return;
395 }
396 } else
397 if(result && required_index>=0 && required_index < GetAmountOfElements()) {
398 BaseClass* elm = (*this)[required_index];
399 result->BC = elm;
400 if (!OnlyPointersMode)result->ID = elm ? elm->GetClassName() : NULL;
401 result->Ptr = elm;
402 }
403 }
404
405 // @copy DynArray::End()
406 X* End() const {
407 const int n = comms::cList<X*>::Count();
408 if (n == 0) {
409#ifdef SAFE_ARRAY
410 return comms::cList<X*>::m_Container->List[0];//DlaBitja;
411#endif
412 }
413 return comms::cList<X*>::m_Container->List[n - 1];
414 }
415
416 inline int Add(X* V) {
417 if (V)V->SimplySetParent(this);
418 return comms::cList<X*>::Add(V);
419 }
420 inline int Add(X* V, int N) {
421 int p = comms::cList<X*>::Add(V, N);
422 if (V)V->SetParent(this);
423 return p;
424 }
425 inline bool Insert(int pos, X* V) {
426 bool p = false;
427 if (!(pos<0 || pos>comms::cList<X*>::Count())) {
428 comms::cList<X*>::Insert(pos, V);
429 p = true;
430 }
431 if (V)V->SetParent(this);
432 return p;
433 }
434 virtual bool Load(TagsList& xml,void* ClassPtr,void* Extra = NULL) override {
435 ((ClassArray<X>*)ClassPtr)->Clear();
436 return BaseClass::Load(xml,ClassPtr,Extra);
437 }
438 virtual bool IsArray() const override {
439 return true;
440 }
441 virtual int ExpandWith(const char* ElmName, void* base) {
442 if(ElmName && ElmName[0]) {
443 ClassArray<X>* BC = (ClassArray<X>*)base;
444 OneClassStorage* OCS = CGARB().GetClass(ElmName);
445 if (OCS) {
446 BaseClass* NewBase = OCS->OneMemb;
447 if (NewBase) {
448 BaseClass* B1 = NewBase->new_element();
449 BC->Add((X*)B1);
450 B1->SetParent(this);
451 return BC->Count() - 1;
452 }
453 else {
454 cAssert(0); // Reg class "REG_CLASS(ElmName)" or check "_modify_class_name"
455 return -1;
456 }
457 }
458 else {
459 cAssert(0);
460 return -1;
461 }
462 }
463 else {
464 ClassArray<X>* BC = (ClassArray<X>*)base;
465 BC->Add(new X);
466 return BC->Count() - 1;
467 }
468 }
469 virtual bool DelElement(int index) {
470 if (index >= 0 && index < comms::cList<X*>::Count()) {
471 if ((*this)[index])delete((*this)[index]);
472 comms::cList<X*>::RemoveAt(index, 1);
473 return true;
474 }
475 else return false;
476 }
477
478 // @copy DynArray::Del()
479 void Del(int index, int n) {
480 // @todo stable We always called in the project DynArray::Del().
481 // But look to DelElement() above! Verify it.
482 comms::cList<X*>::RemoveAt(index, n);
483 }
484
485 virtual bool CheckDirectCasting() const override {
486 return true;
487 }
488 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override {
489 ClassArray<X>* SA = (ClassArray<X>*)SrcData;
490 ClassArray<X>* DA = (ClassArray<X>*)DestData;
491 DA->Clear();
492 for (int i = 0; i < SA->Count(); i++)if ((*SA)[i]) {
493 X* E = (X*)(*SA)[i]->new_element();
494 DA->Add(E);
495 (*SA)[i]->FullCopy((*SA)[i], SrcDataExtra, E, E, DestExtraPtr, C);
496 }
497 return true;
498 }
499 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override {
500 Out->WriteDWORD(comms::cList<X*>::Count());
501 comms::cStr s;
502 for (int i = 0; i < comms::cList<X*>::Count(); i++) {
503 BaseClass* BC = (BaseClass*)((*this)[i]);
504 s = BC->GetClassName();
505 ::_cStr sc;
506 sc.SaveBin(&s, NULL, Out, ExDictionary, SkipList);
507 BC->SaveBin(BC, Extra, Out, ExDictionary, SkipList);
508 }
509 }
510 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override {
511 Clear();
512 int N = In->ReadDWORD();
513 comms::cStr s;
514 for (int i = 0; i < N; i++) {
515 ::_cStr sc;
516 sc.LoadBin(&s, NULL, In, ExDictionary);
517 int id = ExpandWith(s.ToCharPtr(), Data);
518 if (id != -1) {
519 BaseClass* BC = (BaseClass *)((*this)[id]);
520 BC->LoadBin(BC, Extra, In, ExDictionary);
521 }
522 else {
523 //Log.Warning("%s::LoadBin : unable to find class %s",GetClassName(),s.ToCharPtr());
524 }
525 if (In->GetReadPos() >= In->Size()) {
526 break;
527 }
528 }
529 }
530 X* GetLast() {
531 if (comms::cList<X*>::Count() == 0)return NULL;
532 return comms::cList<X*>::m_Container->List[comms::cList<X*>::m_Container->Count - 1];
533 }
534 AUTONEW(ClassArray);
535};
536
537template <class X>
539 operator = (src);
540}
541
542template <class X>
544 Clear();
545 for (int i = 0; i < src.Count(); i++) {
546 BaseClass* B1 = src[i]->new_element();
547 BaseClass* B0 = static_cast<BaseClass*>(src[i]);
548 B0->CopyBaseClass(B1);
549 Add((X*)B1);
550 }
551}
552
553template<class X>class ClonesArray :public ClassArray<X> {
554public:
555 virtual int GetExpansionRules() {
556 return 1;//0-no expansion 1-expand with base type only 2-expand with child classes
557 }
558};
559
565template <class X> class ClassPtr :public BaseClass {
566 X* ptr;
567public:
568 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override {
569 if (ptr) {
570 X* x = (X*)ptr->new_element();
571 x->SetParent(Dest);
572 ((ClassPtr<X>*)Dest)->ptr = x;
573 ptr->FullCopy(ptr, SrcDataExtra, x, x, DestExtraPtr, C);
574 }
575 return true;
576 }
577 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override {
578 BaseClass* BC = Get();
579 Out->WriteBYTE(BC ? 1 : 0);
580 if (BC) {
581 comms::cStr s = BC->GetClassName();
582 ::_cStr sc;
583 sc.SaveBin(&s, Extra, Out, ExDictionary, SkipList);
584 BC->SaveBin(BC, Extra, Out, ExDictionary, SkipList);
585 }
586 }
587 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override {
588 int N = In->ReadBYTE();
589 if (N) {
590 comms::cStr s;
591 ::_cStr sc;
592 sc.LoadBin(&s, Extra, In, ExDictionary);
593 ExpandWith(s.ToCharPtr(), Data);
594 BaseClass* BC = Get();
595 if (BC) {
596 BC->LoadBin(BC, Extra, In, ExDictionary);
597 }
598 }
599 else Set(NULL);
600 }
601 //ClassPtr& operator = (X* x){ptr=x;}
602 X* Get() {
603 return ptr;
604 }
605 void Set(X* x) {
606 ptr = x;
607 if (ptr)ptr->SetParent(this);
608 }
609
610
611 ClassPtr() {
612 ptr = nullptr;
613 }
614 virtual ~ClassPtr() {
615 reset_class(this);
616 };
617 virtual void reset_class(void* p) {
618 ClassPtr<X>* cp = (ClassPtr<X>*)p;
619 if (cp->ptr)delete(cp->ptr);
620 cp->ptr = NULL;
621 }
622 void Clear() {
623 reset_class(this);
624 }
625 const char* GetClassName() const override {
626 static char N[64] = "";
627 if (!N[0]) {
628 X* x = new X;
629 sprintf(N, "ClassPtr.%s", x->GetClassName());
630 delete(x);
631 }
632 return N;
633 }
634 int GetAmountOfElements() override {
635 return ptr ? 1 : 0;
636 }
637 virtual bool GetElement(BaseClassElement& res, int idx, const void* Ptr, const void* Extra) override {
638 if (idx == 0 && ptr) {
639 res.BC = ptr;
640 res.ID = ptr->GetClassName();
641 res.Ptr = ptr;
642 return true;
643 }
644 return false;
645 }
646 virtual int ExpandWith(const char* ElmName, void* base) {
647 reset_class(base);
648 ClassPtr<X>* BC = (ClassPtr<X>*)base;
649 OneClassStorage* OCS = CGARB().GetClass(ElmName);
650 if (OCS) {
651 BaseClass* NewBase = OCS->OneMemb;
652 if (NewBase) {
653 BC->ptr = (X*)NewBase->new_element();
654 BC->ptr->SetParent(this);
655 return 0;
656 }
657 else return -1;
658 }
659 else return -1;
660 }
661
662 virtual bool DelElement(int index) {
663 reset_class(this);
664 return true;
665 }
666 virtual bool CheckDirectCasting() const override {
667 return true;
668 }
669 virtual bool ForceProperty() { return true; }
670 virtual void CountObjects(int& required_index, int* counter, HashSummator* hash, BaseClassElement* result, const std::function<bool(BaseClassElement*)>* ForEachElem, bool OnlyPointersMode) override {
671 if (counter && ptr)* counter ++;
672 if (hash) {
673 if(ptr){
674 ptr->UpdateHash(*hash, ptr, nullptr);
675 //(*hash) << cPtrDiff(ptr);
676 }
677 }
678 if (ForEachElem) {
679 if (ptr) {
680 if (ptr->valid()) {
681 result->BC = ptr;
682 if (!OnlyPointersMode) {
683 result->ID = ptr->GetClassName();
684 }
685 result->Ptr = ptr;
686 (*ForEachElem)(result);
687 } else ptr = nullptr;
688 }
689 }
690 else
691 if (result && required_index == 0 && ptr) {
692 result->BC = ptr;
693 if (!OnlyPointersMode) {
694 result->ID = ptr->GetClassName();
695 }
696 result->Ptr = ptr;
697 }
698 }
699 AUTONEW(ClassPtr);
700};
701
706template <class X> class ClassRef :public BaseClass {
707 X* ptr;
708public:
709 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DestExtraPtr, CECopyContext* C) override {
710 return true;
711 }
712 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList) override {
713 }
714 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary) override {
715 }
716 //ClassRef& operator = (X* x){ptr=x;}
717 X* Get() {
718 return ptr;
719 }
720 void Set(X* x) {
721 ptr = x;
722 }
723
724
725 ClassRef() {
726 ptr = nullptr;
727 }
728 virtual ~ClassRef() {
729 ptr = nullptr;
730 };
731 virtual void reset_class(void* p) {
732 ptr = nullptr;
733 }
734 void Clear() {
735 ptr = nullptr;
736 }
737 const char* GetClassName() const override {
738 static char N[64] = "";
739 if (!N[0]) {
740 X* x = new X;
741 sprintf(N, "ClassRef.%s", x->GetClassName());
742 delete(x);
743 }
744 return N;
745 }
746 int GetAmountOfElements() override {
747 return ptr ? 1 : 0;
748 }
749 virtual bool GetElement(BaseClassElement& res, int idx, const void* Ptr, const void* Extra) override {
750 if (idx == 0 && ptr) {
751 res.BC = ptr;
752 res.ID = ptr->GetClassName();
753 res.Ptr = ptr;
754 return true;
755 }
756 return false;
757 }
758 virtual int ExpandWith(const char* ElmName, void* base) {
759 return -1;
760 }
761
762 virtual bool DelElement(int index) {
763 ptr = nullptr;
764 return true;
765 }
766 virtual bool CheckDirectCasting() const override {
767 return true;
768 }
769 virtual bool MayBeParent() override {
770 return false;
771 }
772 virtual bool ForceProperty() { return true; }
773 virtual void CountObjects(int& required_index, int* counter, HashSummator* hash, BaseClassElement* result, const std::function<bool(BaseClassElement*)>* ForEachElem, bool OnlyPointersMode) override {
774 if (counter && ptr)* counter++;
775 if (hash) {
776 if (ptr) {
777 ptr->UpdateHash(*hash, ptr, nullptr);
778 //(*hash) << cPtrDiff(ptr);
779 }
780 }
781 if (ForEachElem) {
782 if (ptr) {
783 result->BC = ptr;
784 if (!OnlyPointersMode) {
785 result->ID = ptr->GetClassName();
786 }
787 result->Ptr = ptr;
788 (*ForEachElem)(result);
789 }
790 }
791 else
792 if (result && required_index == 0 && ptr) {
793 result->BC = ptr;
794 if (!OnlyPointersMode) {
795 result->ID = ptr->GetClassName();
796 }
797 result->Ptr = ptr;
798 }
799 }
800 AUTONEW(ClassRef);
801};
802template<class X, class BaseForX> class LinearArray :public BaseClass, public comms::cList<X> {
803public:
804 BaseForX B;
805 X B1;
806 virtual ~LinearArray() {
807 reset_class(this);
808 };
809 virtual void reset_class(void* DataPtr) {
810 LinearArray* LA = (LinearArray*)DataPtr;
811 LA->Free();
812 }
813 virtual bool Load(TagsList& xml,void* ClassPtr,void* Extra = NULL) override {
814 ((LinearArray<X, BaseForX>*)ClassPtr)->Clear();
815 return BaseClass::Load(xml,ClassPtr,Extra);
816 }
817 const char* GetClassName() const override {
818 static char N[64] = "";
819 if (N[0] != 'L') {
820 BaseForX* x = new BaseForX;
821 sprintf(N, "LinearArray.%s", x->GetClassName());
822 delete(x);
823 }
824 return N;
825 }
826 int GetAmountOfElements() override {
827 return comms::cList<X>::Count();
828 }
829 virtual void CountObjects(int& required_index, int* counter, HashSummator* hash, BaseClassElement* result, const std::function<bool(BaseClassElement*)>* ForEachElem, bool OnlyPointersMode) override {
830 if (counter)* counter += GetAmountOfElements();
831 if (hash) {
832 for (int i = 0; i < GetAmountOfElements(); i++) {
833 B.UpdateHash(*hash, &(*this)[i], nullptr);
834 }
835 }
836 if (ForEachElem) {
837 for (int i = 0; i < GetAmountOfElements(); i++) {
838 result->BC = &B;
839 if (!OnlyPointersMode) {
840 static char temp[16] = "";
841 sprintf(temp, "e%d", i);
842 result->ID = temp;
843 }
844 result->Ptr = &(*this)[i];
845 if ((*ForEachElem)(result))return;
846 }
847 }
848 else
849 if (result && required_index >= 0 && required_index < GetAmountOfElements()) {
850 result->BC = &B;
851 if (!OnlyPointersMode){
852 static char temp[16] = "";
853 sprintf(temp, "e%d", required_index);
854 result->ID = temp;
855 }
856 result->Ptr = &(*this)[required_index];
857 }
858 }
859 virtual int ExpandWith(const char* ElmName, void* base) {
860 LinearArray<X, BaseForX>* BC = (LinearArray<X, BaseForX>*)base;
861 BC->Add(B1);
862 return BC->Count() - 1;
863 }
864 virtual bool DelElement(int index) {
865 if (index >= 0 && index < comms::cList<X>::Count()) {
866 comms::cList<X>::RemoveAt(index, 1);
867 return true;
868 }
869 else return false;
870 }
871 typedef LinearArray<X, BaseForX> LA;
872 virtual bool CheckDirectCasting() const override {
873 return true;
874 }
875 AUTONEW(LA);
876};
Definition classlist.h:189
virtual BaseWidget * OnCreateControlFromScratch(const ClassEditorContext &Context, Rct &Rect)
Create completely own control for ClassEditor.
Use this class for build a class for UI or serialization. see class_reg.h for details about the class...
Definition BaseClass.h:91
virtual void LoadBin(void *Data, void *Extra, BinStream *In, Enumerator *ExDictionary)
Load the class from the memory. Use only for temporary storage in memory!!!
virtual bool CopyBaseClass(BaseClass *Dest, bool Add=false)
Copy base class to other class uning names correspondence.
virtual BaseWidget * OnCreateControlFromScratch(const ClassEditorContext &Context, Rct &Rect)
Create completely own control for ClassEditor.
Definition BaseClass.h:379
virtual bool CheckCompartabilityWith(const char *TypeName, int TypeSize)
Checking for errors of registration.
Definition BaseClass.h:339
virtual bool DelElement(int Index)
removes element if the operation supported
Definition BaseClass.h:272
virtual BaseClass * new_element() const
construct pointer to class of the same type like this. Elements will not be copied into the new place
virtual bool Load(TagsList &xml, void *ClassPtr, void *Extra=NULL)
Load the class from the XML structure.
virtual void reset_class(void *DataPtr=nullptr)
Clearing all registered content of the class. If DataPtr is nullptr, this class will be cleared.
virtual void SetParent(BaseClass *Parent)
set parent recursively
virtual const char * GetClassName() const
return class name there if need. Usually you don't need, if you are using AUTONEW or SERIALIZE
virtual void SaveBin(void *Data, void *Extra, BinStream *Out, Enumerator *ExDictionary, Enumerator *SkipList)
Save in binaly form. Use only for temporary storage in memory!!!
virtual int GetAmountOfElements()
return complete amount of elements. Even invisible, masked and non-serialized elements will be counte...
virtual void Save(TagsList &xml, void *ClassPtr, void *Extra=NULL)
Save class to the XML structure.
virtual void CountObjects(int &required_index, int *counter, HashSummator *hash, BaseClassElement *result, const std::function< bool(BaseClassElement *)> *ForEachElem=nullptr, bool OnlyPointersMode=false)
This is the main function used for the access to class members. Each class that has SERIALIZE section...
Definition BaseClass.h:134
virtual bool FullCopy(const void *SrcData, const void *SrcDataExtra, BaseClass *Dest, void *DestData, void *DstDataExtra, CECopyContext *C)
Fast copy from one BaseClass to another. Names and types correspondence used to copy.
virtual bool CheckDirectCasting() const
Definition BaseClass.h:227
virtual int ExpandWith(const char *ElmName, void *base)
Expand array with class ElmName.
Definition BaseClass.h:270
virtual void UpdateHash(HashSummator &S, void *data=nullptr, void *extra=nullptr)
returns hash value dependent on data fields of this class
The array of elements derived from the BaseClass. If you create ClassArray and register if with the R...
Definition classlist.h:340
virtual bool DelElement(int index)
removes element if the operation supported
Definition classlist.h:469
virtual void reset_class(void *ptr)
Clearing all registered content of the class. If DataPtr is nullptr, this class will be cleared.
Definition classlist.h:350
virtual void SaveBin(void *Data, void *Extra, BinStream *Out, Enumerator *ExDictionary, Enumerator *SkipList) override
Save in binaly form. Use only for temporary storage in memory!!!
Definition classlist.h:499
int GetAmountOfElements() override
return complete amount of elements. Even invisible, masked and non-serialized elements will be counte...
Definition classlist.h:373
const char * GetClassName() const override
return class name there if need. Usually you don't need, if you are using AUTONEW or SERIALIZE
Definition classlist.h:364
virtual void LoadBin(void *Data, void *Extra, BinStream *In, Enumerator *ExDictionary) override
Load the class from the memory. Use only for temporary storage in memory!!!
Definition classlist.h:510
virtual bool CheckDirectCasting() const override
Definition classlist.h:485
virtual void CountObjects(int &required_index, int *counter, HashSummator *hash, BaseClassElement *result, const std::function< bool(BaseClassElement *)> *ForEachElem, bool OnlyPointersMode) override
This is the main function used for the access to class members. Each class that has SERIALIZE section...
Definition classlist.h:376
virtual int ExpandWith(const char *ElmName, void *base)
Expand array with class ElmName.
Definition classlist.h:441
virtual bool Load(TagsList &xml, void *ClassPtr, void *Extra=NULL) override
Load the class from the XML structure.
Definition classlist.h:434
virtual bool FullCopy(const void *SrcData, const void *SrcDataExtra, BaseClass *Dest, void *DestData, void *DestExtraPtr, CECopyContext *C) override
Fast copy from one BaseClass to another. Names and types correspondence used to copy.
Definition classlist.h:488
The pointer to the allocated class derived from the BaseClass. It allows serialization/presentation i...
Definition classlist.h:565
virtual bool FullCopy(const void *SrcData, const void *SrcDataExtra, BaseClass *Dest, void *DestData, void *DestExtraPtr, CECopyContext *C) override
Fast copy from one BaseClass to another. Names and types correspondence used to copy.
Definition classlist.h:568
virtual void SaveBin(void *Data, void *Extra, BinStream *Out, Enumerator *ExDictionary, Enumerator *SkipList) override
Save in binaly form. Use only for temporary storage in memory!!!
Definition classlist.h:577
virtual void LoadBin(void *Data, void *Extra, BinStream *In, Enumerator *ExDictionary) override
Load the class from the memory. Use only for temporary storage in memory!!!
Definition classlist.h:587
const char * GetClassName() const override
return class name there if need. Usually you don't need, if you are using AUTONEW or SERIALIZE
Definition classlist.h:625
virtual bool GetElement(BaseClassElement &res, int idx, const void *Ptr, const void *Extra) override
Definition classlist.h:637
virtual bool DelElement(int index)
removes element if the operation supported
Definition classlist.h:662
virtual int ExpandWith(const char *ElmName, void *base)
Expand array with class ElmName.
Definition classlist.h:646
virtual void CountObjects(int &required_index, int *counter, HashSummator *hash, BaseClassElement *result, const std::function< bool(BaseClassElement *)> *ForEachElem, bool OnlyPointersMode) override
This is the main function used for the access to class members. Each class that has SERIALIZE section...
Definition classlist.h:670
virtual void reset_class(void *p)
Clearing all registered content of the class. If DataPtr is nullptr, this class will be cleared.
Definition classlist.h:617
virtual bool CheckDirectCasting() const override
Definition classlist.h:666
int GetAmountOfElements() override
return complete amount of elements. Even invisible, masked and non-serialized elements will be counte...
Definition classlist.h:634
The reference to the element derived from the BaseClass. This is the reference, element should be all...
Definition classlist.h:706
const char * GetClassName() const override
return class name there if need. Usually you don't need, if you are using AUTONEW or SERIALIZE
Definition classlist.h:737
virtual void reset_class(void *p)
Clearing all registered content of the class. If DataPtr is nullptr, this class will be cleared.
Definition classlist.h:731
virtual void LoadBin(void *Data, void *Extra, BinStream *In, Enumerator *ExDictionary) override
Load the class from the memory. Use only for temporary storage in memory!!!
Definition classlist.h:714
virtual bool DelElement(int index)
removes element if the operation supported
Definition classlist.h:762
int GetAmountOfElements() override
return complete amount of elements. Even invisible, masked and non-serialized elements will be counte...
Definition classlist.h:746
virtual void SaveBin(void *Data, void *Extra, BinStream *Out, Enumerator *ExDictionary, Enumerator *SkipList) override
Save in binaly form. Use only for temporary storage in memory!!!
Definition classlist.h:712
virtual bool GetElement(BaseClassElement &res, int idx, const void *Ptr, const void *Extra) override
Definition classlist.h:749
virtual int ExpandWith(const char *ElmName, void *base)
Expand array with class ElmName.
Definition classlist.h:758
virtual void CountObjects(int &required_index, int *counter, HashSummator *hash, BaseClassElement *result, const std::function< bool(BaseClassElement *)> *ForEachElem, bool OnlyPointersMode) override
This is the main function used for the access to class members. Each class that has SERIALIZE section...
Definition classlist.h:773
virtual bool FullCopy(const void *SrcData, const void *SrcDataExtra, BaseClass *Dest, void *DestData, void *DestExtraPtr, CECopyContext *C) override
Fast copy from one BaseClass to another. Names and types correspondence used to copy.
Definition classlist.h:709
virtual bool CheckDirectCasting() const override
Definition classlist.h:766
StringsList is the main container used as array of strings.
Definition classlist.h:42
virtual void LoadBin(void *Data, void *Extra, BinStream *In, Enumerator *ExDictionary) override
Load the class from the memory. Use only for temporary storage in memory!!!
virtual void SaveBin(void *Data, void *Extra, BinStream *Out, Enumerator *ExDictionary, Enumerator *SkipList) override
Save in binaly form. Use only for temporary storage in memory!!!
virtual bool CheckDirectCasting() const override
Definition classlist.h:92
virtual bool FullCopy(const void *SrcData, const void *SrcDataExtra, BaseClass *Dest, void *DestData, void *DestExtraPtr, CECopyContext *C) override
Fast copy from one BaseClass to another. Names and types correspondence used to copy.
virtual bool DelElement(int Index) override
removes element if the operation supported
virtual bool Load(TagsList &xml, void *ClassPtr, void *Extra=NULL) override
Load the class from the XML structure.
virtual void CountObjects(int &required_index, int *counter, HashSummator *hash, BaseClassElement *result, const std::function< bool(BaseClassElement *)> *ForEachElem, bool OnlyPointersMode) override
This is the main function used for the access to class members. Each class that has SERIALIZE section...
virtual void Save(TagsList &xml, void *ClassPtr, void *Extra=NULL) override
Save class to the XML structure.
virtual const char * GetClassName() const override
return class name there if need. Usually you don't need, if you are using AUTONEW or SERIALIZE
Definition classlist.h:84
virtual void reset_class(void *ptr)
Clearing all registered content of the class. If DataPtr is nullptr, this class will be cleared.
virtual void UpdateHash(HashSummator &H, void *data=nullptr, void *extra=nullptr) override
returns hash value dependent on data fields of this class
This class intended to load/save the class derived from the BaseClass as XML/JSON....
Definition TagsList.h:21
void Assign(int v)
assign int value to the tag value
const char * to_string() const
get value of the tag
The array template, refer it as coat::list <...> if you are using the Core API.
Definition cList.h:133
Definition classlist.h:101