source: branches/work_320/lists/ARFieldList.h @ 679

Revision 679, 9.2 KB checked in by jls17, 5 years ago (diff)
  • fixed some memory leaks in case memory allocation fails in ARFieldList.cpp and ARSchemaList.cpp
  • small changes to the initialization of the crash handler
RevLine 
[122]1//Copyright (C) 2010 John Luthgers | jls17
2//
3//This file is part of ARInside.
4//
5//    ARInside is free software: you can redistribute it and/or modify
6//    it under the terms of the GNU General Public License as published by
7//    the Free Software Foundation, version 2 of the License.
8//
9//    ARInside is distributed in the hope that it will be useful,
10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12//    GNU General Public License for more details.
13//
14//    You should have received a copy of the GNU General Public License
15//    along with ARInside.  If not, see <http://www.gnu.org/licenses/>.#pragma once
16#pragma once
17#include "../ARApi.h"
18#include "../util/Uncopyable.h"
[174]19#include "../util/RefItem.h"
[122]20#include <assert.h>
21
22// forward declarations
23class CARSchemaList;
24
25///////////////////////////////////////////////////////////////////////////////
26// CARFieldList - interface definition
27class CARFieldList : Uncopyable
28{
29public:
30        // no special constructor here ... but a virtual destructor to make sure the correct one is called
31        virtual ~CARFieldList(void) { };
32
33        // no loading here ... abstract class!
34
35        // list functions
36        virtual unsigned int GetCount() = 0;
37        virtual int Find(const char *name) = 0;
38        virtual int Find(unsigned int fieldId) = 0;
39        virtual void Sort() = 0;
40
41        // data access
42        virtual const ARNameType& FieldGetName(unsigned int index) const = 0;
43        virtual ARInternalId FieldGetFieldId(unsigned int index) = 0;
44        virtual const ARFieldMappingStruct& FieldGetMapping(unsigned int index) const = 0;
45        virtual unsigned int FieldGetDataType(unsigned int index) = 0;
46        virtual unsigned int FieldGetOption(unsigned int index) = 0;
47        virtual unsigned int FieldGetCreateMode(unsigned int index) = 0;
48        virtual unsigned int FieldGetFieldOption(unsigned int index) = 0;
49        virtual const ARValueStruct& FieldGetDefaultValue(unsigned int index) const = 0;
50        virtual const ARPermissionList& FieldGetPermissions(unsigned int index) const = 0;
51        virtual const ARFieldLimitStruct& FieldGetLimits(unsigned int index) const = 0;
52        virtual const ARDisplayInstanceList& FieldGetDisplayInstances(unsigned int index) const = 0;
53        virtual char* FieldGetHelptext(unsigned int index) const = 0;
54        virtual const ARTimestamp& FieldGetTimestamp(unsigned int index) const = 0;
55        virtual const ARAccessNameType& FieldGetOwner(unsigned int index) const = 0;
56        virtual const ARAccessNameType& FieldGetModifiedBy(unsigned int index) const = 0;
57        virtual const char* FieldGetChangeDiary(unsigned int index) const = 0;
[227]58        virtual const ARPropList& FieldGetPropList(unsigned int index) const = 0;
[165]59
60        // types used for workflow references
[174]61        typedef list<CRefItem> ReferenceList;
[165]62        // Workflow references
[174]63        bool FieldReferenceExists(unsigned int index, const CRefItem& refItem);
64        bool FieldReferenceAdd(unsigned int index, const CRefItem& refItem);
[165]65        size_t FieldReferenceCount(unsigned int index);
66        const ReferenceList& FieldReferenceList(unsigned int index);
67
68protected:
69        vector<ReferenceList> workflowReferences;       // this list holds the workflow references
[122]70};
71
72///////////////////////////////////////////////////////////////////////////////
73// CARFieldListXML - field list support for XML files
74class CARFieldListXML : public CARFieldList
75{
76public:
77        CARFieldListXML(void) { ARZeroMemory(&fieldInfo); }
78        virtual ~CARFieldListXML(void) { }
79
80        // loading
81        void FinishLoading();
82
83        // list functions
84        virtual unsigned int GetCount() { return fieldInfo.numItems; }
85        virtual int Find(const char *name);
86        virtual int Find(unsigned int fieldId);
87        virtual void Sort();
88
89        // data access
90        virtual const ARNameType& FieldGetName(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].fieldName; }
91        virtual ARInternalId FieldGetFieldId(unsigned int index) { return fieldInfo.fieldList[sortedList[index]].fieldId; }
92        virtual const ARFieldMappingStruct& FieldGetMapping(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].fieldMap; }
93        virtual unsigned int FieldGetDataType(unsigned int index) { return fieldInfo.fieldList[sortedList[index]].dataType; }
94        virtual unsigned int FieldGetOption(unsigned int index) { return fieldInfo.fieldList[sortedList[index]].option; }
95        virtual unsigned int FieldGetCreateMode(unsigned int index) { return fieldInfo.fieldList[sortedList[index]].createMode; }
96        virtual unsigned int FieldGetFieldOption(unsigned int index) { return fieldInfo.fieldList[sortedList[index]].fieldOption; }
97        virtual const ARValueStruct& FieldGetDefaultValue(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].defaultVal; }
98        virtual const ARPermissionList& FieldGetPermissions(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].permList; }
99        virtual const ARFieldLimitStruct& FieldGetLimits(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].limit; }
100        virtual const ARDisplayInstanceList& FieldGetDisplayInstances(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].dInstanceList; }
101        virtual char* FieldGetHelptext(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].helpText; }
102        virtual const ARTimestamp& FieldGetTimestamp(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].timestamp; }
103        virtual const ARAccessNameType& FieldGetOwner(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].owner; }
104        virtual const ARAccessNameType& FieldGetModifiedBy(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].lastChanged; }
105        virtual const char* FieldGetChangeDiary(unsigned int index) const { return fieldInfo.fieldList[sortedList[index]].changeDiary; }
[227]106        virtual const ARPropList& FieldGetPropList(unsigned int index) const;
107       
[122]108        friend class CARSchemaList;
109private:
110        ARFieldInfoList fieldInfo;
[671]111        vector<int> sortedList;  // sorted by field name
[122]112};
113
114///////////////////////////////////////////////////////////////////////////////
115// CARFieldListServer - field list support for direct server access
116class CARFieldListServer : public CARFieldList
117{
118public:
119        CARFieldListServer(unsigned int schemaInsideId);
120        virtual ~CARFieldListServer(void);
121
122        // loading ...
123        bool LoadFromServer();
124
125        // list functions
126        virtual unsigned int GetCount() { return names.numItems; }
127        virtual int Find(const char *name);
128        virtual int Find(unsigned int fieldId);
129        virtual void Sort();
130
131        // data access
132        virtual const ARNameType& FieldGetName(unsigned int index) const { return names.nameList[sortedList[index]]; }
133        virtual ARInternalId FieldGetFieldId(unsigned int index) { return fieldIds.internalIdList[sortedList[index]]; }
134        virtual const ARFieldMappingStruct& FieldGetMapping(unsigned int index) const { return fieldMaps.mappingList[sortedList[index]]; }
135        virtual unsigned int FieldGetDataType(unsigned int index) { return dataTypes.intList[sortedList[index]]; }
136        virtual unsigned int FieldGetOption(unsigned int index) { return options.intList[sortedList[index]]; }
137        virtual unsigned int FieldGetCreateMode(unsigned int index) { return createModes.intList[sortedList[index]]; }
138        virtual unsigned int FieldGetFieldOption(unsigned int index) { return fieldOptions.intList[sortedList[index]]; }
139        virtual const ARValueStruct& FieldGetDefaultValue(unsigned int index) const { return defaultValues.valueList[sortedList[index]]; }
140        virtual const ARPermissionList& FieldGetPermissions(unsigned int index) const { return permLists.permissionList[sortedList[index]]; }
141        virtual const ARFieldLimitStruct& FieldGetLimits(unsigned int index) const { return limits.fieldLimitList[sortedList[index]]; }
142        virtual const ARDisplayInstanceList& FieldGetDisplayInstances(unsigned int index) const { return dInstanceLists.dInstanceList[sortedList[index]]; }
143        virtual char* FieldGetHelptext(unsigned int index) const { return helpTexts.stringList[sortedList[index]]; }
144        virtual const ARTimestamp& FieldGetTimestamp(unsigned int index) const { return changedTimes.timestampList[sortedList[index]]; }
145        virtual const ARAccessNameType& FieldGetOwner(unsigned int index) const { return owners.nameList[sortedList[index]]; }
146        virtual const ARAccessNameType& FieldGetModifiedBy(unsigned int index) const { return changedUsers.nameList[sortedList[index]]; }
147        virtual const char* FieldGetChangeDiary(unsigned int index) const { return changeDiary.stringList[sortedList[index]]; }
[227]148        virtual const ARPropList& FieldGetPropList(unsigned int index) const;
[122]149
150private:
[549]151        void Reserve(unsigned int amount);
152        void SetNumItems(unsigned int amount);
153        void BuildIndex();
[679]154        void ClearAllStructs();
[549]155
156private:
[122]157        unsigned int schemaId;
158
159        ARNameList names;
160        ARInternalIdList fieldIds;
161        ARFieldMappingList fieldMaps;
162        ARUnsignedIntList dataTypes;
163        ARUnsignedIntList options;
164        ARUnsignedIntList createModes;
165        ARUnsignedIntList fieldOptions;
166        ARValueList defaultValues;
167        ARPermissionListList permLists;
168        ARFieldLimitList limits;
169        ARDisplayInstanceListList dInstanceLists;
170        ARTextStringList helpTexts;
171        ARTimestampList changedTimes;
172        ARAccessNameList owners;
173        ARAccessNameList changedUsers;
174        ARTextStringList changeDiary;
[227]175#if AR_CURRENT_API_VERSION >= AR_API_VERSION_763
176        ARPropListList objProps;
177#endif
[122]178
[671]179        vector<int> sortedList;  // sorted by field name
[122]180};
Note: See TracBrowser for help on using the repository browser.