gwnavruntime/abstractgraph/blobs/abstractdataindex.h Source File

abstractdataindex.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 #ifndef Navigation_AbstractDataIndex_H
9 #define Navigation_AbstractDataIndex_H
10 
18 
19 namespace Kaim
20 {
21 
22 class AbstractDataDescriptor
23 {
24  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
25  KY_CLASS_WITHOUT_COPY(AbstractDataDescriptor)
26 public:
27  AbstractDataDescriptor() {}
28  const char* GetFileName() const { return m_fileName.GetValues(); }
29 
30  BlobArray<char> m_fileName;
31  KyGuid m_guid;
32  Box2f m_boundingBox;
33 };
34 inline void SwapEndianness(Endianness::Target e, AbstractDataDescriptor& self)
35 {
36  SwapEndianness(e, self.m_fileName);
37  SwapEndianness(e, self.m_guid);
38  SwapEndianness(e, self.m_boundingBox);
39 }
40 
41 
42 class AbstractDataIndex
43 {
44  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
45  KY_ROOT_BLOB_CLASS(NavData, AbstractDataIndex, 0)
46  KY_CLASS_WITHOUT_COPY(AbstractDataIndex)
47 public:
48  AbstractDataIndex() {}
49  KyUInt32 GetDescriptorsCount() const { return m_descriptors.GetCount(); }
50  const AbstractDataDescriptor& GetDescriptor(KyUInt32 index) const { return m_descriptors.GetValues()[index]; }
51  BlobArray<AbstractDataDescriptor> m_descriptors;
52 };
53 
54 inline void SwapEndianness(Endianness::Target e, AbstractDataIndex& self)
55 {
56  SwapEndianness(e, self.m_descriptors);
57 }
58 
59 class AbstractDataIndexLoader
60 {
61  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
62 
63 public:
64  static Ptr< BlobHandler<AbstractDataIndex> > LoadAbstractDataIndex(const char* filename, FileOpenerBase* fileOpener = KY_NULL)
65  {
66  DefaultFileOpener defaultFileOpener;
67  FileOpenerBase* opener = fileOpener ? fileOpener : &defaultFileOpener;
68  Ptr<File> file = opener->OpenFile(filename, OpenMode_Read);
69  if (file == KY_NULL)
70  {
71  KY_LOG_ERROR(("Could not open file [%s]", filename));
72  return KY_NULL;
73  }
74 
75  BlobAggregate blobAggregate;
76  if (blobAggregate.Load(file, MemStat_Blob, KY_NULL, BLOB_AGGREGATE_IGNORE_UNKNOWN_BLOBTYPES) == KY_ERROR)
77  return KY_NULL;
78 
79  BlobAggregate::Collection<AbstractDataIndex> collection = blobAggregate.GetCollection<AbstractDataIndex>();
80 
81  if (collection.GetCount() == 0)
82  {
83  KY_LOG_ERROR(("File [%s] does not contain any AbstractDataIndex", filename));
84  return KY_NULL;
85  }
86 
87  if (collection.GetCount() > 1)
88  {
89  KY_LOG_ERROR(("ERROR: File [%s] does contains more than 1 AbstractDataIndex", filename));
90  return KY_NULL;
91  }
92 
93  return collection.GetHandler(0);
94  }
95 };
96 
97 
98 } // namespace Kaim
99 
100 #endif
#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
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
Opens the file for reading only.
Definition: fileopener.h:30
Definition: gamekitcrowddispersion.h:20
#define KY_ERROR
Shorthand for Kaim::Result::Failure.
Definition: types.h:272
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36