AGX Dynamics  2.37.3.2
RestoreObjects.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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:
72  ObjectPtrVectorType m_objects;
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 
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
iterator begin()
Definition: Vector.h:1041
ObjectPtrVectorType m_objects
ObjectPtrVectorType::iterator begin()
agxStream::InputArchive & m_archive
agx::Vector< T * > ObjectPtrVectorType
virtual void beginSection(const char *title) override
iterator end()
Definition: Vector.h:1044
T * iterator
Definition: Vector.h:62
RestoreObjects(agxStream::InputArchive &archive, const char *collectionTitle, const char *elementTitle)
void resize(size_t size)
Resize the vector, which then enables direct addressing using the bracket &#39;[]&#39; operator.
Definition: Vector.h:540
const agx::Vector< T * > & getObjects()
virtual void getAttribute(const char *name, double &value)
#define agxThrow
Definition: debug.h:109
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
virtual void endSection(const char *title) override
ObjectPtrVectorType::iterator end()
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
const char * m_collectionTitle