Field3D
OgUtil.cpp File Reference
#include "OgUtil.h"

Go to the source code of this file.

Functions

bool getGroupName (Alembic::Ogawa::IGroupPtr group, std::string &name)
 
FIELD3D_NAMESPACE_OPEN const char * ogGroupTypeToString (OgGroupType type)
 
OgDataType readDataType (Alembic::Ogawa::IGroupPtr group, const size_t idx)
 
bool readString (Alembic::Ogawa::IGroupPtr group, const size_t idx, std::string &s)
 
bool writeString (Alembic::Ogawa::OGroupPtr group, const std::string &s)
 

Function Documentation

◆ ogGroupTypeToString()

FIELD3D_NAMESPACE_OPEN const char* ogGroupTypeToString ( OgGroupType  type)

Definition at line 15 of file OgUtil.cpp.

16 {
17  switch(type)
18  {
19  case F3DGroupType:
20  return "group";
21  case F3DAttributeType:
22  return "attribute";
23  case F3DDatasetType:
24  return "dataset";
25  default:
26  return "";
27  }
28 }

◆ readString()

bool readString ( Alembic::Ogawa::IGroupPtr  group,
const size_t  idx,
std::string &  s 
)

Definition at line 32 of file OgUtil.cpp.

34 {
35  // Grab data
36  Alembic::Ogawa::IDataPtr data = group->getData(idx, OGAWA_THREAD);
37  // Check that we got something
38  if (!data) {
39  std::cout << "OgUtil::readString() got null data for index "
40  << idx << std::endl;
41  std::cout << " numChildren(): " << group->getNumChildren() << std::endl;
42  return false;
43  }
44  // Check data length
45  const size_t length = data->getSize();
46  if (length % sizeof(std::string::value_type) != 0) {
47  return false;
48  }
49  // String length
50  const size_t stringLength = length / sizeof(std::string::value_type);
51  // Read into temp buffer. Reading straight into std::string is Bad.
52  std::vector<std::string::value_type> temp(stringLength + 1);
53  // Add null terminator
54  temp[stringLength] = 0;
55  // Read the data
56  data->read(length, &temp[0], 0, OGAWA_THREAD);
57  // Construct string. The string see the temp buffer as a const char *.
58  s = std::string(&temp[0]);
59  // Done
60  return true;
61 }

Referenced by getGroupName().

◆ readDataType()

OgDataType readDataType ( Alembic::Ogawa::IGroupPtr  group,
const size_t  idx 
)

Definition at line 65 of file OgUtil.cpp.

66 {
67  // Data type
68  OgDataType dataType;;
69  // Grab data
70  Alembic::Ogawa::IDataPtr data = group->getData(idx, OGAWA_THREAD);
71  // Check data length
72  const size_t sizeLength = sizeof(OgDataType);
73  const size_t length = data->getSize();
74  if (length != sizeLength) {
75  std::cout << "readDataType() " << sizeLength << " != " << length << std::endl;
76  return F3DInvalidDataType;
77  }
78  // Read the data directly to the input param
79  data->read(length, &dataType, 0, OGAWA_THREAD);
80  // Done
81  return dataType;
82 }

References F3DInvalidDataType.

◆ writeString()

bool writeString ( Alembic::Ogawa::OGroupPtr  group,
const std::string &  s 
)

Definition at line 86 of file OgUtil.cpp.

87 {
88  // Strings are written without zero terminator
89  Alembic::Ogawa::ODataPtr data =
90  group->addData(s.size() * sizeof(std::string::value_type), s.c_str());
91  return data != NULL;
92 }

◆ getGroupName()

bool getGroupName ( Alembic::Ogawa::IGroupPtr  group,
std::string &  name 
)

Definition at line 96 of file OgUtil.cpp.

98 {
99  return readString(group, 0, name);
100 }

References readString().

F3DInvalidDataType
@ F3DInvalidDataType
Definition: Traits.h:160
readString
bool readString(Alembic::Ogawa::IGroupPtr group, const size_t idx, std::string &s)
Definition: OgUtil.cpp:32
OgDataType
OgDataType
Enumerates the various uses for Ogawa-level groups.
Definition: Traits.h:125