gwnavruntime/navdata/navdataindex.h Source File

navdataindex.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 // primary contact: LASI - secondary contact: GUAL
9 #ifndef Navigation_NavDataIndex_H
10 #define Navigation_NavDataIndex_H
11 
19 
20 namespace Kaim
21 {
22 
23 class NavDataDescriptor
24 {
25  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
26  KY_CLASS_WITHOUT_COPY(NavDataDescriptor)
27 public:
28  NavDataDescriptor() {}
29  const char* GetFileName() const { return m_fileName.GetValues(); }
30 
31  BlobArray<char> m_fileName;
32  KyGuid m_guid;
33  Box2f m_boundingBox;
34 };
35 inline void SwapEndianness(Endianness::Target e, NavDataDescriptor& self)
36 {
37  SwapEndianness(e, self.m_fileName);
38  SwapEndianness(e, self.m_guid);
39  SwapEndianness(e, self.m_boundingBox);
40 }
41 
42 
43 class NavDataIndex
44 {
45  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
46  KY_ROOT_BLOB_CLASS(NavData, NavDataIndex, 0)
47  KY_CLASS_WITHOUT_COPY(NavDataIndex)
48 public:
49  NavDataIndex() {}
50  KyUInt32 GetDescriptorsCount() const { return m_descriptors.GetCount(); }
51  const NavDataDescriptor& GetDescriptor(KyUInt32 index) const { return m_descriptors.GetValues()[index]; }
52  BlobArray<NavDataDescriptor> m_descriptors;
53 };
54 
55 inline void SwapEndianness(Endianness::Target e, NavDataIndex& self)
56 {
57  SwapEndianness(e, self.m_descriptors);
58 }
59 
60 class NavDataIndexLoader
61 {
62  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
63 
64 public:
65  static Ptr< BlobHandler<NavDataIndex> > LoadNavDataIndex(const char* filename, FileOpenerBase* fileOpener = KY_NULL)
66  {
67  DefaultFileOpener defaultFileOpener;
68  FileOpenerBase* opener = fileOpener ? fileOpener : &defaultFileOpener;
69  Ptr<File> file = opener->OpenFile(filename, OpenMode_Read);
70  if (file == KY_NULL)
71  {
72  KY_LOG_ERROR(("Could not open file [%s]", filename));
73  return KY_NULL;
74  }
75 
76  BlobAggregate blobAggregate;
77 
78  if (blobAggregate.Load(file, MemStat_Blob, KY_NULL, BLOB_AGGREGATE_IGNORE_UNKNOWN_BLOBTYPES) == KY_ERROR)
79  return KY_NULL;
80 
81  BlobAggregate::Collection<NavDataIndex> collection = blobAggregate.GetCollection<NavDataIndex>();
82 
83  if (collection.GetCount() == 0)
84  {
85  KY_LOG_ERROR(("File [%s] does not contain any NavDataIndex", filename));
86  return KY_NULL;
87  }
88 
89  if (collection.GetCount() > 1)
90  {
91  KY_LOG_ERROR(("ERROR: File [%s] does contains more than 1 NavDataIndex", filename));
92  return KY_NULL;
93  }
94 
95  return collection.GetHandler(0);
96  }
97 };
98 
99 
100 } // namespace Kaim
101 
102 #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