Skip to content
Snippets Groups Projects
Commit 2e034cb3 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Add explicit ObjectID::FromString() and setFromString()

parent ed01df81
No related branches found
No related tags found
1 merge request!301Add explicit ObjectID::FromString() and setFromString()
......@@ -19,16 +19,7 @@ namespace armarx
{
if (nameOrID.find("/") != nameOrID.npos)
{
const std::vector<std::string> split = simox::alg::split(nameOrID, "/", true);
ARMARX_CHECK(split.size() == 2 || split.size() == 3)
<< "Expected ID of format 'Dataset/ClassName' or 'Dataset/ClassName/InstanceName'"
<< ", but got: '" << nameOrID << "' (too many '/').";
_dataset = split[0];
_className = split[1];
if (split.size() == 3)
{
_instanceName = split[2];
}
setFromString(nameOrID);
}
else
{
......@@ -37,6 +28,30 @@ namespace armarx
}
}
ObjectID ObjectID::FromString(const std::string& idString)
{
ObjectID id;
id.setFromString(idString);
return id;
}
void ObjectID::setFromString(const std::string& idString)
{
const std::vector<std::string> split = simox::alg::split(idString, "/", true);
ARMARX_CHECK(split.size() == 2 || split.size() == 3)
<< "Expected ID of format 'Dataset/ClassName' or 'Dataset/ClassName/InstanceName'"
<< ", but got: '" << idString << "' "
<< "(expected 2 or 3 '/'s, but found " << split.size() << ").";
_dataset = split[0];
_className = split[1];
if (split.size() == 3)
{
_instanceName = split[2];
}
}
std::string ObjectID::str() const
{
std::string _str = _dataset + "/" + _className;
......
......@@ -17,6 +17,9 @@ namespace armarx
/// Construct from either a class name ("myobject") or ID ("mydataset/myobject", "mydataset/myclass/myinstance").
ObjectID(const std::string& nameOrID);
/// Construct from a string produced by `str()`, e.g. ("mydataset/myobject", "mydataset/myclass/myinstance").
static ObjectID FromString(const std::string& idString);
inline std::string dataset() const
{
......@@ -37,6 +40,8 @@ namespace armarx
/// Return "dataset/className" or "dataset/className/instanceName".
std::string str() const;
void setFromString(const std::string& idString);
/// Return just the class ID without an intance name.
ObjectID getClassID() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment