AGX Dynamics  2.35.0.1
RestoreObjects.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 
20 #include <agxStream/InputArchive.h>
21 
22 namespace agxStream
23 {
24  template<typename T>
26  {
27  public:
28  typedef T ObjectType;
29  typedef T* ObjectPtrType;
31 
32  RestoreObjects(agxStream::InputArchive& archive, const char* collectionTitle, const char* elementTitle) :
33  m_archive(archive),
34  m_collectionTitle(collectionTitle),
35  m_elementTitle(elementTitle)
36  {
38  size_t size;
39  m_archive.getAttribute("size", size);
40  m_objects.resize(size);
41  for(size_t i = 0; i < size; i++)
42  {
44  if (m_archive.eof())
45  {
46  std::stringstream str;
47  str << "Reached EOF while restoring " << m_collectionTitle << ". " <<
48  "There should be " << size << " RigidBodies, reached eof after restoring " << i;
50  }
51  }
53  }
54 
55 
57  {
58  return m_objects.begin();
59  }
60 
62  {
63  return m_objects.end();
64  }
65 
67  {
68  return m_objects;
69  }
70 
71  protected:
73 
75  const char* m_collectionTitle;
76  const char*m_elementTitle;
77 
78 
79  private:
80  RestoreObjects& operator =(const RestoreObjects&)
81  {
82  return *this;
83  }
84  };
85 }
86 
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:52
virtual void getAttribute(const char *name, double &value)
virtual void endSection(const char *title) override
virtual void beginSection(const char *title) override
ObjectPtrVectorType::iterator end()
RestoreObjects(agxStream::InputArchive &archive, const char *collectionTitle, const char *elementTitle)
agx::Vector< T * > ObjectPtrVectorType
agxStream::InputArchive & m_archive
const char * m_collectionTitle
const agx::Vector< T * > & getObjects()
ObjectPtrVectorType::iterator begin()
ObjectPtrVectorType m_objects
iterator end()
Definition: agx/Vector.h:1044
void resize(size_t size)
Resize the vector, which then enables direct addressing using the bracket '[]' operator.
Definition: agx/Vector.h:540
iterator begin()
Definition: agx/Vector.h:1041
#define agxThrow
Definition: debug.h:109
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400