Made changes according to pull request feedback

This commit is contained in:
GPayne
2017-04-13 11:12:26 -06:00
parent bef3f2b652
commit 7a7fef239c
8 changed files with 88 additions and 89 deletions
-1
View File
@@ -383,7 +383,6 @@ protected:
/// The callback function that will be invoked whenever the encapsulated value changes
std::function<void()> _onChangeCallback;
};
} // namespace properties
+1 -1
View File
@@ -212,7 +212,7 @@ public:
* trying to find a match for a desired batch operation on Properties.
* \return Pointer to vector of string tags that were assigned to the Property
*/
const std::vector<std::string> tags() const;
std::vector<std::string> tags() const;
/**
* Adds a tag to the Property's list of assigned tags. Tags are useful for creating
+2 -2
View File
@@ -324,12 +324,12 @@ const std::string& PropertyOwner::name() const {
return _name;
}
const std::vector<std::string> PropertyOwner::tags() const {
std::vector<std::string> PropertyOwner::tags() const {
return _tags;
}
void PropertyOwner::addTag(std::string tag) {
_tags.push_back(tag);
_tags.push_back(std::move(tag));
}
} // namespace properties
+9 -10
View File
@@ -113,19 +113,18 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary)
dictionary.getValue(keyStart, _startTime);
dictionary.getValue(keyEnd, _endTime);
std::string tagName;
ghoul::Dictionary tagNames;
if (dictionary.hasKeyAndValue<std::string>(KeyTag)) {
dictionary.getValue(KeyTag, tagName);
if (! tagName.empty())
addTag(tagName);
std::string tagName = dictionary.value<std::string>(KeyTag);
if (!tagName.empty())
addTag(std::move(tagName));
} else if (dictionary.hasKeyAndValue<ghoul::Dictionary>(KeyTag)) {
dictionary.getValue(KeyTag, tagNames);
ghoul::Dictionary tagNames = dictionary.value<ghoul::Dictionary>(KeyTag);
std::vector<std::string> keys = tagNames.keys();
for (const std::string key : keys) {
tagNames.getValue(key, tagName);
if (! tagName.empty())
addTag(tagName);
std::string tagName;
for (const std::string& key : keys) {
tagName = tagNames.value<std::string>(key);
if (!tagName.empty())
addTag(std::move(tagName));
}
}
+9 -10
View File
@@ -146,19 +146,18 @@ ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary
dictionary.getValue(KeyDepth, _depth);
dictionary.getValue(KeyAlpha, _alpha);
std::string tagName;
ghoul::Dictionary tagNames;
if (dictionary.hasKeyAndValue<std::string>(KeyTag)) {
dictionary.getValue(KeyTag, tagName);
if (! tagName.empty())
addTag(tagName);
std::string tagName = dictionary.value<std::string>(KeyTag);
if (!tagName.empty())
addTag(std::move(tagName));
} else if (dictionary.hasKeyAndValue<ghoul::Dictionary>(KeyTag)) {
dictionary.getValue(KeyTag, tagNames);
ghoul::Dictionary tagNames = dictionary.value<ghoul::Dictionary>(KeyTag);
std::vector<std::string> keys = tagNames.keys();
for (const std::string key : keys) {
tagNames.getValue(key, tagName);
if (! tagName.empty())
addTag(tagName);
std::string tagName;
for (const std::string& key : keys) {
tagName = tagNames.value<std::string>(key);
if (!tagName.empty())
addTag(std::move(tagName));
}
}
+22 -22
View File
@@ -651,38 +651,38 @@ scripting::LuaLibrary Scene::luaLibrary() {
"setPropertyValue",
&luascriptfunctions::property_setValue,
"string, *",
"Sets all property(s) identified by the URI (with potential wildcards) "
"in the first argument. The second argument can be any type, but it has "
"to match the type that the property (or properties) expect. If the "
"first term (separated by '.') in the uri is bracketed with { }, then "
"this term is treated as a group tag name, and the function will "
"search through all property owners to find those that are tagged with "
"this group name, and set their property values accordingly."
"Sets all property(s) identified by the URI (with potential wildcards) "
"in the first argument. The second argument can be any type, but it has "
"to match the type that the property (or properties) expect. If the "
"first term (separated by '.') in the uri is bracketed with { }, then "
"this term is treated as a group tag name, and the function will "
"search through all property owners to find those that are tagged with "
"this group name, and set their property values accordingly."
},
{
"setPropertyValueRegex",
&luascriptfunctions::property_setValueRegex,
"string, *",
"Sets all property(s) that pass the regular expression in the first "
"argument. The second argument can be any type, but it has to match "
"the type of the properties that matched the regular expression. "
"The regular expression has to be of the ECMAScript grammar. If the "
"first term (separated by '.') in the uri is bracketed with { }, then "
"this term is treated as a group tag name, and the function will search "
"through all property owners to find those that are tagged with this "
"group name, and set their property values accordingly."
"Sets all property(s) that pass the regular expression in the first "
"argument. The second argument can be any type, but it has to match "
"the type of the properties that matched the regular expression. "
"The regular expression has to be of the ECMAScript grammar. If the "
"first term (separated by '.') in the uri is bracketed with { }, then "
"this term is treated as a group tag name, and the function will search "
"through all property owners to find those that are tagged with this "
"group name, and set their property values accordingly."
},
{
"setPropertyValueSingle",
&luascriptfunctions::property_setValueSingle,
"string, *",
"Sets all property(s) identified by the URI in the first argument to the "
"value passed in the second argument. The type of the second argument is "
"arbitrary, but it must agree with the type the denoted Property expects. "
"If the first term (separated by '.') in the uri is bracketed with { }, "
" then this term is treated as a group tag name, and the function will "
"search through all property owners to find those that are tagged with "
"this group name, and set their property values accordingly."
"Sets all property(s) identified by the URI in the first argument to the "
"value passed in the second argument. The type of the second argument is "
"arbitrary, but it must agree with the type the denoted Property expects."
" If the first term (separated by '.') in the uri is bracketed with { }, "
" then this term is treated as a group tag name, and the function will "
"search through all property owners to find those that are tagged with "
"this group name, and set their property values accordingly."
},
{
"getPropertyValue",
+32 -31
View File
@@ -41,13 +41,14 @@ void executePropertySet(properties::Property* prop, lua_State* L) {
template <class T>
properties::PropertyOwner* findPropertyOwnerWithMatchingGroupTag(T* prop,
const std::string tagToMatch) {
const std::string& tagToMatch)
{
properties::PropertyOwner* tagMatchOwner = nullptr;
properties::PropertyOwner* owner = prop->owner();
if (owner != nullptr) {
std::vector<std::string> tags = (std::vector<std::string>)owner->tags();
for (std::string currTag : tags) {
if (owner) {
std::vector<std::string> tags = owner->tags();
for (std::string& currTag : tags) {
if (tagToMatch.compare(currTag) == 0) {
tagMatchOwner = owner;
break;
@@ -64,10 +65,11 @@ const std::string tagToMatch) {
void applyRegularExpression(lua_State* L, std::regex regex,
std::vector<properties::Property*> properties, int type,
std::string groupName = "") {
std::string groupName = "")
{
using ghoul::lua::errorLocation;
using ghoul::lua::luaTypeToString;
bool isGroupMode = (groupName.empty()) ? false : true;
bool isGroupMode = !groupName.empty();
for (properties::Property* prop : properties) {
// Check the regular expression for all properties
@@ -77,10 +79,14 @@ void applyRegularExpression(lua_State* L, std::regex regex,
// If the fully qualified id matches the regular expression, we queue the
// value change if the types agree
if (isGroupMode) {
properties::PropertyOwner* matchingTaggedOwner = findPropertyOwnerWithMatchingGroupTag(prop,
groupName);
if (matchingTaggedOwner == nullptr)
properties::PropertyOwner* matchingTaggedOwner =
findPropertyOwnerWithMatchingGroupTag(
prop,
groupName
);
if (!matchingTaggedOwner) {
continue;
}
}
if (type != prop->typeLua()) {
@@ -97,24 +103,19 @@ void applyRegularExpression(lua_State* L, std::regex regex,
}
}
bool doesUriContainGroupTag(const std::string command) {
//Checks to see if URI contains a group tag (with { } around the first term). If so,
// returns true and sets groupName with the tag
bool doesUriContainGroupTag(const std::string& command, std::string& groupName) {
std::string name = command.substr(0, command.find_first_of("."));
if (name.front() == '{' && name.back() == '}')
if (name.front() == '{' && name.back() == '}') {
groupName = name.substr(1, name.length() - 2);
return true;
else
return false;
}
std::string extractGroupNameFromUri(const std::string command) {
if (doesUriContainGroupTag(command)) {
std::string name = command.substr(0, command.find_first_of("."));
return name.substr(1, name.length() - 2);
} else {
return command;
return false;
}
}
std::string replaceUriGroupNameWith(std::string uri, std::string ownerName) {
std::string replaceUriWithGroupName(std::string uri, std::string ownerName) {
size_t pos = uri.find_first_of(".");
return ownerName + "." + uri.substr(pos);
}
@@ -123,13 +124,15 @@ std::string extractUriWithoutGroupName(std::string uri) {
size_t pos = uri.find_first_of(".");
return uri.substr(pos);
}
}
namespace luascriptfunctions {
int setPropertyCall_single(properties::Property* prop, std::string uri, lua_State* L,
const int type) {
const int type)
{
using ghoul::lua::errorLocation;
using ghoul::lua::luaTypeToString;
@@ -169,9 +172,9 @@ int property_setValueSingle(lua_State* L) {
std::string uri = luaL_checkstring(L, -2);
const int type = lua_type(L, -1);
std::string tagToMatch;
if (doesUriContainGroupTag(uri)) {
std::string tagToMatch = extractGroupNameFromUri(uri);
if (doesUriContainGroupTag(uri, tagToMatch)) {
std::string pathRemainderToMatch = extractUriWithoutGroupName(uri);
for (properties::Property* prop : allProperties()) {
std::string propFullId = prop->fullyQualifiedIdentifier();
@@ -184,7 +187,7 @@ int property_setValueSingle(lua_State* L) {
if (pathRemainderToMatch.compare(thisPropMatchId) == 0) {
properties::PropertyOwner* matchingTaggedOwner
= findPropertyOwnerWithMatchingGroupTag(prop, tagToMatch);
if (matchingTaggedOwner != nullptr) {
if (matchingTaggedOwner) {
setPropertyCall_single(prop, uri, L, type);
}
}
@@ -232,11 +235,10 @@ int property_setValue(lua_State* L) {
startPos = regex.find("*", startPos);
}
if (doesUriContainGroupTag(regex)) {
groupName = extractGroupNameFromUri(regex);
if (doesUriContainGroupTag(regex, groupName)) {
std::string pathRemainderToMatch = extractUriWithoutGroupName(regex);
//Remove group name from start of regex and replace with '.*'
regex = replaceUriGroupNameWith(regex, ".*");
regex = replaceUriWithGroupName(regex, ".*");
}
applyRegularExpression(
@@ -270,11 +272,10 @@ int property_setValueRegex(lua_State* L) {
std::string regex = luaL_checkstring(L, -2);
std::string groupName;
if (doesUriContainGroupTag(regex)) {
groupName = extractGroupNameFromUri(regex);
if (doesUriContainGroupTag(regex, groupName)) {
std::string pathRemainderToMatch = extractUriWithoutGroupName(regex);
//Remove group name from start of regex and replace with '.*'
regex = replaceUriGroupNameWith(regex, ".*");
regex = replaceUriWithGroupName(regex, ".*");
}
try {
+13 -12
View File
@@ -141,20 +141,21 @@ SceneGraphNode* SceneGraphNode::createFromDictionary(const ghoul::Dictionary& di
}
if (dictionary.hasKey(KeyTag)) {
std::string tagName;
ghoul::Dictionary tagNames;
if (dictionary.hasKeyAndValue<std::string>(KeyTag)) {
dictionary.getValue(KeyTag, tagName);
if (! tagName.empty())
result->addTag(tagName);
std::string tagName = dictionary.value<std::string>(KeyTag);
if (!tagName.empty()) {
result->addTag(std::move(tagName));
}
} else if (dictionary.hasKeyAndValue<ghoul::Dictionary>(KeyTag)) {
dictionary.getValue(KeyTag, tagNames);
std::vector<std::string> keys = tagNames.keys();
for (const std::string key : keys) {
tagNames.getValue(key, tagName);
if (! tagName.empty())
result->addTag(tagName);
}
ghoul::Dictionary tagNames = dictionary.value<ghoul::Dictionary>(KeyTag);
std::vector<std::string> keys = tagNames.keys();
std::string tagName;
for (const std::string& key : keys) {
tagName = tagNames.value<std::string>(key);
if (!tagName.empty()) {
result->addTag(std::move(tagName));
}
}
}
}