7 #ifndef Navigation_AggregatedDataIndex_H
8 #define Navigation_AggregatedDataIndex_H
20 class DatabaseDescriptorIndex :
public RefCountBaseNTS<DatabaseDescriptorIndex, MemStat_Data_Other>
25 enum DataIndexLoadMode
27 LoadDataIndex_NavData = 1 << 0,
28 LoadDataIndex_AbstractData = 1 << 1,
29 LoadDataIndex_ColData = 1 << 2,
35 DatabaseDescriptorIndex() {}
39 m_navDataIndexHandler =
KY_NULL;
40 m_abstractDataIndexHandler =
KY_NULL;
41 m_colDataIndexHandler =
KY_NULL;
42 m_databaseDescriptor.m_databaseIndex = 0;
46 KyResult LoadDataIndex(
const char* filename, FileOpenerBase* fileOpener =
KY_NULL, DataIndexLoadMode loadMode = LoadDataIndex_All)
48 DefaultFileOpener defaultFileOpener;
49 FileOpenerBase* opener = fileOpener ? fileOpener : &defaultFileOpener;
53 KY_LOG_ERROR((
"Could not open file [%s]", filename));
57 BlobAggregate blobAggregate;
59 if (blobAggregate.Load(file, MemStat_Blob,
KY_NULL, BLOB_AGGREGATE_IGNORE_UNKNOWN_BLOBTYPES) ==
KY_ERROR)
62 return LoadDataIndex(blobAggregate, loadMode);
66 KyResult LoadDataIndex(
const BlobAggregate& blobAggregate, DataIndexLoadMode loadMode = LoadDataIndex_All)
68 if (LoadDataIndex_NavData & loadMode)
70 m_navDataIndexHandler =
KY_NULL;
71 BlobAggregate::Collection<NavDataIndex> collection = blobAggregate.GetCollection<NavDataIndex>();
72 if (collection.GetCount() == 1)
73 m_navDataIndexHandler = collection.GetHandler(0);
74 else if (collection.GetCount() > 1)
76 KY_LOG_ERROR((
"ERROR: BlobAggregate contains more than 1 NavDataIndex. No NavDataIndex has been loaded"));
82 if (LoadDataIndex_AbstractData & loadMode)
84 m_abstractDataIndexHandler =
KY_NULL;
85 BlobAggregate::Collection<AbstractDataIndex> collection = blobAggregate.GetCollection<AbstractDataIndex>();
86 if (collection.GetCount() == 1)
87 m_abstractDataIndexHandler = collection.GetHandler(0);
88 else if (collection.GetCount() > 1)
90 KY_LOG_ERROR((
"ERROR: BlobAggregate contains more than 1 AbstractDataIndex. No AbstractDataIndex has been loaded"));
96 if (LoadDataIndex_ColData & loadMode)
98 m_colDataIndexHandler =
KY_NULL;
99 BlobAggregate::Collection<ColDataIndex> collection = blobAggregate.GetCollection<ColDataIndex>();
100 if (collection.GetCount() == 1)
101 m_colDataIndexHandler = collection.GetHandler(0);
102 else if (collection.GetCount() > 1)
104 KY_LOG_ERROR((
"ERROR: BlobAggregate contains more than 1 ColDataIndex. No ColDataIndex has been loaded"));
110 BlobAggregate::Collection<DatabaseDescriptorBlob> databaseDescriptor = blobAggregate.GetCollection<DatabaseDescriptorBlob>();
111 if (databaseDescriptor.GetCount() != 0)
113 if (m_databaseDescriptor.ReadFromAggregate(blobAggregate) ==
KY_ERROR)
115 KY_LOG_ERROR((
"ERROR: BlobAggregate contains more than 1 ColDataIndex. No ColDataIndex has been loaded"));
125 KyResult Save(
const char* absoluteFilename, FileOpenerBase* fileOpener =
KY_NULL)
127 DefaultFileOpener defaultFileOpener;
128 FileOpenerBase* opener = fileOpener ? fileOpener : &defaultFileOpener;
129 Ptr<File> file = opener->OpenFile(absoluteFilename,
OpenMode_Write);
132 KY_LOG_ERROR((
"Could not access file [%s]", absoluteFilename));
136 BlobAggregate blobAggregate;
139 if (m_navDataIndexHandler !=
KY_NULL && m_navDataIndexHandler->Blob() !=
KY_NULL)
140 blobAggregate.AddBlob(m_navDataIndexHandler);
143 if (m_abstractDataIndexHandler !=
KY_NULL && m_abstractDataIndexHandler->Blob() !=
KY_NULL)
144 blobAggregate.AddBlob(m_abstractDataIndexHandler);
147 if (m_colDataIndexHandler !=
KY_NULL && m_colDataIndexHandler->Blob() !=
KY_NULL)
148 blobAggregate.AddBlob(m_colDataIndexHandler);
151 Ptr<BlobHandler<DatabaseDescriptorBlob> > databaseDescriptorBlobHandler = *KY_NEW BlobHandler<DatabaseDescriptorBlob>;
152 DatabaseDescriptorBlobBuilder descriptorBlobBuilder(&m_databaseDescriptor);
153 descriptorBlobBuilder.Build(*databaseDescriptorBlobHandler);
154 blobAggregate.AddBlob(databaseDescriptorBlobHandler);
158 KY_LOG_ERROR((
"Could not save DatabaseDescriptorIndex to [%s]", absoluteFilename));
166 Ptr< BlobHandler<NavDataIndex> > m_navDataIndexHandler;
167 Ptr< BlobHandler<AbstractDataIndex> > m_abstractDataIndexHandler;
168 Ptr< BlobHandler<ColDataIndex> > m_colDataIndexHandler;
170 DatabaseDescriptor m_databaseDescriptor;
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
Opens the file for writing.
Definition: fileopener.h:31
#define KY_NULL
Null value.
Definition: types.h:247
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
Opens the file for reading only.
Definition: fileopener.h:30
bool Fail(KyResult result)
Returns true if the specified result code indicates that the requested operation failed.
Definition: types.h:268
Definition: gamekitcrowddispersion.h:20
#define KY_SUCCESS
Shorthand for Kaim::Result::Success.
Definition: types.h:273
#define KY_ERROR
Shorthand for Kaim::Result::Failure.
Definition: types.h:272
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226