Skip to content

Commit

Permalink
Merge pull request #2310 from bradking/type-enum
Browse files Browse the repository at this point in the history
Convert internal data type ids from std::string to an enumeration
  • Loading branch information
Chuck Atkins authored Jun 9, 2020
2 parents 6b718da + 35d7abb commit 130c4f1
Show file tree
Hide file tree
Showing 83 changed files with 545 additions and 515 deletions.
6 changes: 3 additions & 3 deletions bindings/C/adios2/c/adios2_c_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ adios2_error adios2_attribute_type_string(char *type, size_t *size,

const adios2::core::AttributeBase *attributeBase =
reinterpret_cast<const adios2::core::AttributeBase *>(attribute);
return String2CAPI(attributeBase->m_Type, type, size);
return String2CAPI(ToString(attributeBase->m_Type), type, size);
}
catch (...)
{
Expand Down Expand Up @@ -146,9 +146,9 @@ adios2_error adios2_attribute_data(void *data, size_t *size,
const adios2::core::AttributeBase *attributeBase =
reinterpret_cast<const adios2::core::AttributeBase *>(attribute);

const std::string type(attributeBase->m_Type);
const adios2::Type type(attributeBase->m_Type);

if (type == "")
if (type == adios2::Type::None)
{
// not supported
}
Expand Down
16 changes: 8 additions & 8 deletions bindings/C/adios2/c/adios2_c_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ adios2_error adios2_put(adios2_engine *engine, adios2_variable *variable,

adios2::core::VariableBase *variableBase =
reinterpret_cast<adios2::core::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
const adios2::Type type(variableBase->m_Type);

const adios2::Mode modeCpp = adios2_ToMode(
mode, "only adios2_mode_deferred or adios2_mode_sync are valid, "
"in call to adios2_put");

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -302,10 +302,10 @@ adios2_error adios2_put_by_name(adios2_engine *engine,
mode, "only adios2_mode_deferred or adios2_mode_sync are valid, "
"in call to adios2_put_by_name");

const std::string type(
const adios2::Type type(
engineCpp->m_IO.InquireVariableType(variable_name));

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -379,9 +379,9 @@ adios2_error adios2_get(adios2_engine *engine, adios2_variable *variable,
adios2::core::VariableBase *variableBase =
reinterpret_cast<adios2::core::VariableBase *>(variable);

const std::string type(variableBase->m_Type);
const adios2::Type type(variableBase->m_Type);

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -438,10 +438,10 @@ adios2_error adios2_get_by_name(adios2_engine *engine,
const adios2::Mode modeCpp = adios2_ToMode(
mode, "only adios2_mode_deferred or adios2_mode_sync are valid, "
"in call to adios2_get_by_name");
const std::string type(
const adios2::Type type(
engineCpp->m_IO.InquireVariableType(variable_name));

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down
16 changes: 8 additions & 8 deletions bindings/C/adios2/c/adios2_c_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ adios2_variable *adios2_inquire_variable(adios2_io *io, const char *name)
return variable;
}

const std::string type(ioCpp.InquireVariableType(name));
const adios2::Type type(ioCpp.InquireVariableType(name));
adios2::core::VariableBase *variableCpp = nullptr;

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -308,10 +308,10 @@ adios2_error adios2_inquire_all_variables(adios2_variable ***variables,
for (auto &name : names)
{
auto it = dataMap.find(name);
const std::string type(it->second.first);
const adios2::Type type(it->second.first);
adios2::core::VariableBase *variable = nullptr;

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -506,10 +506,10 @@ adios2_attribute *adios2_inquire_attribute(adios2_io *io, const char *name)
return attribute;
}

const std::string type(itAttribute->second.first);
const adios2::Type type(itAttribute->second.first);
adios2::core::AttributeBase *attributeCpp = nullptr;

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -567,10 +567,10 @@ adios2_error adios2_inquire_all_attributes(adios2_attribute ***attributes,
for (auto &name : names)
{
auto it = dataMap.find(name);
const std::string type(it->second.first);
const adios2::Type type(it->second.first);
adios2::core::AttributeBase *attribute = nullptr;

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down
24 changes: 12 additions & 12 deletions bindings/C/adios2/c/adios2_c_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ adios2_error adios2_variable_type(adios2_type *type,
const adios2::core::VariableBase *variableBase =
reinterpret_cast<const adios2::core::VariableBase *>(variable);

const std::string typeCpp = variableBase->m_Type;
const adios2::Type typeCpp = variableBase->m_Type;
if (typeCpp == adios2::helper::GetType<std::string>())
{
*type = adios2_type_string;
Expand Down Expand Up @@ -254,7 +254,7 @@ adios2_error adios2_variable_type_string(char *type, size_t *size,

const adios2::core::VariableBase *variableBase =
reinterpret_cast<const adios2::core::VariableBase *>(variable);
return String2CAPI(variableBase->m_Type, type, size);
return String2CAPI(ToString(variableBase->m_Type), type, size);
}
catch (...)
{
Expand Down Expand Up @@ -319,8 +319,8 @@ adios2_error adios2_variable_shape(size_t *shape,
const adios2::core::VariableBase *variableBase =
reinterpret_cast<const adios2::core::VariableBase *>(variable);

const std::string typeCpp = variableBase->m_Type;
if (typeCpp == "compound")
const adios2::Type typeCpp = variableBase->m_Type;
if (typeCpp == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -382,8 +382,8 @@ adios2_error adios2_variable_count(size_t *count,
const adios2::core::VariableBase *variableBase =
reinterpret_cast<const adios2::core::VariableBase *>(variable);

const std::string typeCpp = variableBase->m_Type;
if (typeCpp == "compound")
const adios2::Type typeCpp = variableBase->m_Type;
if (typeCpp == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -458,9 +458,9 @@ adios2_error adios2_selection_size(size_t *size,
const adios2::core::VariableBase *variableBase =
reinterpret_cast<const adios2::core::VariableBase *>(variable);

const std::string typeCpp = variableBase->m_Type;
const adios2::Type typeCpp = variableBase->m_Type;

if (typeCpp == "compound")
if (typeCpp == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -552,9 +552,9 @@ adios2_error adios2_variable_min(void *min, const adios2_variable *variable)

const adios2::core::VariableBase *variableBase =
reinterpret_cast<const adios2::core::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
const adios2::Type type(variableBase->m_Type);

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -589,9 +589,9 @@ adios2_error adios2_variable_max(void *max, const adios2_variable *variable)

const adios2::core::VariableBase *variableBase =
reinterpret_cast<const adios2::core::VariableBase *>(variable);
const std::string type(variableBase->m_Type);
const adios2::Type type(variableBase->m_Type);

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/CXX11/adios2/cxx11/Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace adios2
{ \
helper::CheckForNullptr(m_Attribute, \
"in call to Attribute<T>::Type()"); \
return m_Attribute->m_Type; \
return ToString(m_Attribute->m_Type); \
} \
\
template <> \
Expand Down
4 changes: 2 additions & 2 deletions bindings/CXX11/adios2/cxx11/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ IO::AvailableAttributes(const std::string &variableName,
std::string IO::VariableType(const std::string &name) const
{
helper::CheckForNullptr(m_IO, "in call to IO::VariableType");
return m_IO->InquireVariableType(name);
return ToString(m_IO->InquireVariableType(name));
}

std::string IO::AttributeType(const std::string &name) const
{
helper::CheckForNullptr(m_IO, "in call to IO::AttributeType");
return m_IO->InquireAttributeType(name);
return ToString(m_IO->InquireAttributeType(name));
}

size_t IO::AddOperation(const Operator op, const Params &parameters)
Expand Down
2 changes: 1 addition & 1 deletion bindings/CXX11/adios2/cxx11/Types.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace adios2
template <class T>
std::string GetType() noexcept
{
return helper::GetType<typename TypeInfo<T>::IOType>();
return ToString(helper::GetType<typename TypeInfo<T>::IOType>());
}

} // end namespace adios2
Expand Down
2 changes: 1 addition & 1 deletion bindings/CXX11/adios2/cxx11/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace adios2
std::string Variable<T>::Type() const \
{ \
helper::CheckForNullptr(m_Variable, "in call to Variable<T>::Type"); \
return m_Variable->m_Type; \
return ToString(m_Variable->m_Type); \
} \
template <> \
size_t Variable<T>::Sizeof() const \
Expand Down
8 changes: 4 additions & 4 deletions bindings/Python/py11Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ std::string Attribute::Name() const
std::string Attribute::Type() const
{
helper::CheckForNullptr(m_Attribute, "in call to Attribute::Type");
return m_Attribute->m_Type;
return ToString(m_Attribute->m_Type);
}

std::vector<std::string> Attribute::DataString()
{
helper::CheckForNullptr(m_Attribute, "in call to Attribute::DataStrings");
const std::string type = m_Attribute->m_Type;
const adios2::Type type = m_Attribute->m_Type;

std::vector<std::string> data;

Expand Down Expand Up @@ -73,9 +73,9 @@ std::vector<std::string> Attribute::DataString()
pybind11::array Attribute::Data()
{
helper::CheckForNullptr(m_Attribute, "in call to Attribute::Data");
const std::string type = m_Attribute->m_Type;
const adios2::Type type = m_Attribute->m_Type;

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down
15 changes: 8 additions & 7 deletions bindings/Python/py11Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ void Engine::Put(Variable variable, const pybind11::array &array,
helper::CheckForNullptr(variable.m_VariableBase,
"for variable, in call to Engine::Put numpy array");

const std::string type = variable.Type();
const adios2::Type type = helper::GetTypeFromString(variable.Type());

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -103,7 +103,8 @@ void Engine::Put(Variable variable, const std::string &string)
helper::CheckForNullptr(variable.m_VariableBase,
"for variable, in call to Engine::Put string");

if (variable.Type() != helper::GetType<std::string>())
if (helper::GetTypeFromString(variable.Type()) !=
helper::GetType<std::string>())
{
throw std::invalid_argument(
"ERROR: variable " + variable.Name() +
Expand Down Expand Up @@ -138,9 +139,9 @@ void Engine::Get(Variable variable, pybind11::array &array, const Mode launch)
variable.m_VariableBase,
"for variable, in call to Engine::Get a numpy array");

const std::string type = variable.Type();
const adios2::Type type = helper::GetTypeFromString(variable.Type());

if (type == "compound")
if (type == adios2::Type::Compound)
{
// not supported
}
Expand Down Expand Up @@ -176,7 +177,7 @@ void Engine::Get(Variable variable, std::string &string, const Mode launch)
helper::CheckForNullptr(variable.m_VariableBase,
"for variable, in call to Engine::Get a string");

const std::string type = variable.Type();
const adios2::Type type = helper::GetTypeFromString(variable.Type());

if (type == helper::GetType<std::string>())
{
Expand Down Expand Up @@ -287,7 +288,7 @@ Engine::BlocksInfo(std::string &var_name, const size_t step) const
std::vector<std::map<std::string, std::string>> rv;

// Grab the specified variable object and get its type string
std::string var_type = m_Engine->GetIO().InquireVariableType(var_name);
adios2::Type var_type = m_Engine->GetIO().InquireVariableType(var_name);

// Use the macro incantation to call the right instantiation of
// core::BlocksInfo<>() Note that we are flatting the Dims type items, and
Expand Down
10 changes: 5 additions & 5 deletions bindings/Python/py11File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pybind11::array File::Read(const std::string &name, const size_t blockID)
pybind11::array File::Read(const std::string &name, const Dims &start,
const Dims &count, const size_t blockID)
{
const std::string type = m_Stream->m_IO->InquireVariableType(name);
const Type type = m_Stream->m_IO->InquireVariableType(name);

if (type == helper::GetType<std::string>())
{
Expand All @@ -226,9 +226,9 @@ pybind11::array File::Read(const std::string &name, const Dims &start,
const Dims &count, const size_t stepStart,
const size_t stepCount, const size_t blockID)
{
const std::string type = m_Stream->m_IO->InquireVariableType(name);
const Type type = m_Stream->m_IO->InquireVariableType(name);

if (type.empty())
if (type == Type::None)
{
}
#define declare_type(T) \
Expand All @@ -251,10 +251,10 @@ pybind11::array File::ReadAttribute(const std::string &name,
const std::string &variableName,
const std::string separator)
{
const std::string type =
const Type type =
m_Stream->m_IO->InquireAttributeType(name, variableName, separator);

if (type.empty())
if (type == Type::None)
{
}
#define declare_type(T) \
Expand Down
Loading

0 comments on commit 130c4f1

Please sign in to comment.