Skip to content

Libs/Optimize/Utils/ObjectReader.h

Classes

Name
class ObjectReader

Source code

```cpp

pragma once

include

include

include

template class ObjectReader { public: typedef ObjectReader Self; typedef T ObjectType;

const std::vector &GetOutput() const { return m_Output; } std::vector &GetOutput() { return m_Output; }

void SetFileName(const char *fn) { m_FileName = fn; } void SetFileName(const std::string &fn) { m_FileName = fn; } const std::string &GetFileName() const { return m_FileName; }

inline void Read() { this->Update(); } void Update() { // Open the output file. std::ifstream in(m_FileName.c_str(), std::ios::binary);

if (!in) {
  std::cerr << "Could not open filename " << m_FileName << std::endl;
  throw 1;
}
// Read the number of transforms
int N;
in.read(reinterpret_cast<char *>(&N), sizeof(int));

int sz = sizeof(ObjectType);
// Read the transforms
for (unsigned int i = 0; i < (unsigned int)N; i++) {
  ObjectType q;  // maybe not the most efficient, but safe
  in.read(reinterpret_cast<char *>(&q), sz);
  m_Output.push_back(q);
}

in.close();

}

ObjectReader() {} virtual ~ObjectReader(){};

private: ObjectReader(const Self &); // purposely not implemented void operator=(const Self &); // purposely not implemented

std::vector m_Output; std::string m_FileName; }; ```


Updated on 2026-03-31 at 16:02:11 +0000