gwnavruntime/abstractgraph/blobs/abstractdataindex.h Source File

abstractdataindex.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
9 
17 
18 namespace Kaim
19 {
20 
21 class AbstractDataDescriptor
22 {
23  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
24  KY_CLASS_WITHOUT_COPY(AbstractDataDescriptor)
25 public:
26  AbstractDataDescriptor() {}
27  const char* GetFileName() const { return m_fileName.GetValues(); }
28 
29  BlobArray<char> m_fileName;
30  KyGuid m_guid;
31  Box2f m_boundingBox;
32 };
33 inline void SwapEndianness(Endianness::Target e, AbstractDataDescriptor& self)
34 {
35  SwapEndianness(e, self.m_fileName);
36  SwapEndianness(e, self.m_guid);
37  SwapEndianness(e, self.m_boundingBox);
38 }
39 
40 
41 class AbstractDataIndex
42 {
43  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
44  KY_ROOT_BLOB_CLASS(NavData, AbstractDataIndex, 0)
45  KY_CLASS_WITHOUT_COPY(AbstractDataIndex)
46 public:
47  AbstractDataIndex() {}
48  KyUInt32 GetDescriptorsCount() const { return m_descriptors.GetCount(); }
49  const AbstractDataDescriptor& GetDescriptor(KyUInt32 index) const { return m_descriptors.GetValues()[index]; }
50  BlobArray<AbstractDataDescriptor> m_descriptors;
51 };
52 
53 inline void SwapEndianness(Endianness::Target e, AbstractDataIndex& self)
54 {
55  SwapEndianness(e, self.m_descriptors);
56 }
57 
58 class AbstractDataIndexLoader
59 {
60  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavData)
61 
62 public:
63  static Ptr< BlobHandler<AbstractDataIndex> > LoadAbstractDataIndex(const char* filename, FileOpenerBase* fileOpener = nullptr)
64  {
65  Ptr<File> file = Kaim::DefaultFileOpener(fileOpener).OpenFile(filename, OpenMode_Read);
66  if (file == nullptr)
67  {
68  KY_LOG_ERROR(("Could not open file [%s]", filename));
69  return nullptr;
70  }
71 
72  BlobAggregate blobAggregate;
73  if (blobAggregate.Load(file, MemStat_Blob, nullptr, BLOB_AGGREGATE_IGNORE_UNKNOWN_BLOBTYPES) == KY_ERROR)
74  return nullptr;
75 
76  BlobAggregate::Collection<AbstractDataIndex> collection = blobAggregate.GetCollection<AbstractDataIndex>();
77 
78  if (collection.GetCount() == 0)
79  {
80  KY_LOG_ERROR(("File [%s] does not contain any AbstractDataIndex", filename));
81  return nullptr;
82  }
83 
84  if (collection.GetCount() > 1)
85  {
86  KY_LOG_ERROR(("ERROR: File [%s] does contains more than 1 AbstractDataIndex", filename));
87  return nullptr;
88  }
89 
90  return collection.GetHandler(0);
91  }
92 };
93 
94 
95 } // namespace Kaim
96 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
virtual Ptr< File > OpenFile(const char *filename, FileOpenerMode mode)
Override to open a file using user-defined function and/or File class.
Definition: fileopener.h:62
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
Opens the file for reading only.
Definition: fileopener.h:25
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
#define KY_ERROR
use result == KY_ERROR to test for error
Definition: types.h:132
Simple default implementation of an object that opens a file on disk that is called when the primaryF...
Definition: fileopener.h:55