Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using std::optional in favor of bool return #29

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/vsg/core/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

#include <atomic>
#include <string>
#include <optional>

#include <vsg/core/Export.h>
#include <vsg/core/ref_ptr.h>
Expand Down Expand Up @@ -76,7 +77,7 @@ namespace vsg
void setValue(const std::string& key, const char* value) { setValue(key, value ? std::string(value) : std::string()); }

template<typename T>
bool getValue(const std::string& key, T& value) const;
std::optional<T> getValue(const std::string& key) const;

void setObject(const std::string& key, Object* object);
Object* getObject(const std::string& key);
Expand Down
7 changes: 3 additions & 4 deletions include/vsg/core/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,18 @@ namespace vsg
}

template<typename T>
bool Object::getValue(const std::string& key, T& value) const
std::optional<T> Object::getValue(const std::string& key) const
{
using ValueT = Value<T>;
const Object* object = getObject(key);
if (object && (typeid(*object) == typeid(ValueT)))
{
const ValueT* vo = static_cast<const ValueT*>(getObject(key));
value = *vo;
return true;
return *vo;
}
else
{
return false;
return {};
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/vsg/io/ObjectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace vsg;

ObjectFactory::ObjectFactory()
{
_createMap["nulltr"] = []() { return ref_ptr<Object>(); };
_createMap["nullptr"] = []() { return ref_ptr<Object>(); };

VSG_REGISTER_new(vsg::Object);

Expand Down