AGX Dynamics  2.38.0.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:
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 
agx::Vector::resize
void resize(size_t size)
Resize the vector, which then enables direct addressing using the bracket '[]' operator.
Definition: Vector.h:540
InputArchive.h
agxStream::RestoreObjects::m_collectionTitle
const char * m_collectionTitle
Definition: RestoreObjects.h:75
agx::Vector::end
iterator end()
Definition: Vector.h:1044
agx::Vector< T * >
agx::Vector::begin
iterator begin()
Definition: Vector.h:1041
agxStream::RestoreObjects::m_elementTitle
const char * m_elementTitle
Definition: RestoreObjects.h:76
agxStream::RestoreObjects::m_archive
agxStream::InputArchive & m_archive
Definition: RestoreObjects.h:74
agxStream::InputArchive::eof
bool eof() const
Definition: InputArchive.h:356
agxStream::RestoreObjects::m_objects
ObjectPtrVectorType m_objects
Definition: RestoreObjects.h:72
agxStream::RestoreObjects::begin
ObjectPtrVectorType::iterator begin()
Definition: RestoreObjects.h:56
agx::Vector< T * >::iterator
T * * iterator
Definition: Vector.h:62
agxStream::RestoreObjects::end
ObjectPtrVectorType::iterator end()
Definition: RestoreObjects.h:61
agxStream::RestoreObjects::RestoreObjects
RestoreObjects(agxStream::InputArchive &archive, const char *collectionTitle, const char *elementTitle)
Definition: RestoreObjects.h:32
agxStream::in
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:399
agxStream::InputArchive::beginSection
virtual void beginSection(const char *title) override
agxStream::ArchiveException
Definition: Archive.h:126
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:50
agxThrow
#define agxThrow
Definition: debug.h:109
agxStream::RestoreObjects::getObjects
const agx::Vector< T * > & getObjects()
Definition: RestoreObjects.h:66
agxStream::InputArchive::getAttribute
virtual void getAttribute(const char *name, double &value)
agxStream::RestoreObjects::ObjectPtrVectorType
agx::Vector< T * > ObjectPtrVectorType
Definition: RestoreObjects.h:30
agxStream
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
Definition: ElementaryConstraint.h:31
agxStream::RestoreObjects::ObjectPtrType
T * ObjectPtrType
Definition: RestoreObjects.h:29
agxStream::InputArchive::endSection
virtual void endSection(const char *title) override
agxStream::RestoreObjects::ObjectType
T ObjectType
Definition: RestoreObjects.h:28
agxStream::RestoreObjects
Definition: RestoreObjects.h:25