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.

{
switch(type)
{
case F3DGroupType:
return "group";
case F3DAttributeType:
return "attribute";
case F3DDatasetType:
return "dataset";
default:
return "";
}
}

## readString()

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

Definition at line 32 of file OgUtil.cpp.

{
// Grab data
Alembic::Ogawa::IDataPtr data = group->getData(idx, OGAWA_THREAD);
// Check that we got something
if (!data) {
std::cout << "OgUtil::readString() got null data for index "
<< idx << std::endl;
std::cout << " numChildren(): " << group->getNumChildren() << std::endl;
return false;
}
// Check data length
const size_t length = data->getSize();
if (length % sizeof(std::string::value_type) != 0) {
return false;
}
// String length
const size_t stringLength = length / sizeof(std::string::value_type);
// Read into temp buffer. Reading straight into std::string is Bad.
std::vector<std::string::value_type> temp(stringLength + 1);
// Add null terminator
temp[stringLength] = 0;
// Read the data
data->read(length, &temp[0], 0, OGAWA_THREAD);
// Construct string. The string see the temp buffer as a const char *.
s = std::string(&temp[0]);
// Done
return true;
}

Referenced by getGroupName().

## readDataType()

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

Definition at line 65 of file OgUtil.cpp.

{
// Data type
OgDataType dataType;;
// Grab data
Alembic::Ogawa::IDataPtr data = group->getData(idx, OGAWA_THREAD);
// Check data length
const size_t sizeLength = sizeof(OgDataType);
const size_t length = data->getSize();
if (length != sizeLength) {
std::cout << "readDataType() " << sizeLength << " != " << length << std::endl;
return F3DInvalidDataType;
}
// Read the data directly to the input param
data->read(length, &dataType, 0, OGAWA_THREAD);
// Done
return dataType;
}
OgDataType
OgDataType
Enumerates the various uses for Ogawa-level groups.
Definition Traits.h:125
F3DInvalidDataType
@ F3DInvalidDataType
Definition Traits.h:160

References F3DInvalidDataType.

## writeString()

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

Definition at line 86 of file OgUtil.cpp.

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

## getGroupName()

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

Definition at line 96 of file OgUtil.cpp.

{
return readString(group, 0, name);
}
readString
bool readString(Alembic::Ogawa::IGroupPtr group, const size_t idx, std::string &s)
Definition OgUtil.cpp:32

References readString().