StringUtilities.cpp
Go to the documentation of this file.
00001 
00006 #include "robot_instance/StringUtilities.h"
00007 
00008 using namespace std;
00009 
00010 
00011 bool StringUtilities::isFullyQualifiedRobonetNode(const std::string& name)
00012 {
00013     return boost::regex_match(name, VALID_ROBONET_NODE);
00014 }
00015 
00016 bool StringUtilities::isFullyQualifiedRobonetElement(const std::string& name)
00017 {
00018     return boost::regex_match(name, VALID_ROBONET_ELEMENT);
00019 }
00020 
00021 std::string StringUtilities::getRobonetChannel(const std::string& name)
00022 {
00023     if (isFullyQualifiedRobonetNode(name) || isFullyQualifiedRobonetElement(name))
00024     {
00025         boost::match_results<std::string::const_iterator> matches;
00026         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBONET_NODE);
00027         return std::string(matches[1].first, matches[1].second);
00028     }
00029     else
00030     {
00031         throw std::runtime_error(name + " is not a valid node or element name.");
00032     }
00033 
00034     return std::string();
00035 }
00036 
00037 std::string StringUtilities::getRobonetNode(const std::string& name)
00038 {
00039     if (isFullyQualifiedRobonetNode(name) || isFullyQualifiedRobonetElement(name))
00040     {
00041         boost::match_results<std::string::const_iterator> matches;
00042         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBONET_NODE);
00043         return std::string(matches[2].first, matches[2].second);
00044     }
00045     else
00046     {
00047         throw std::runtime_error(name + " is not a valid node or element name.");
00048     }
00049 
00050     return std::string();
00051 }
00052 
00053 std::string StringUtilities::getFullyQualifiedRobonetNode(const std::string& name)
00054 {
00055     if (isFullyQualifiedRobonetNode(name) || isFullyQualifiedRobonetElement(name))
00056     {
00057         boost::match_results<std::string::const_iterator> matches;
00058         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBONET_NODE);
00059         return std::string(TOKEN_DELIMITER) + std::string(matches[1].first, matches[2].second);
00060     }
00061     else
00062     {
00063         throw std::runtime_error(name + " is not a valid node or element name.");
00064     }
00065 
00066     return std::string();
00067 }
00068 
00069 std::string StringUtilities::getRobonetElement(const std::string& name)
00070 {
00071     if (isFullyQualifiedRobonetElement(name))
00072     {
00073         boost::match_results<std::string::const_iterator> matches;
00074         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBONET_ELEMENT);
00075         return std::string(matches[3].first, matches[3].second);
00076     }
00077     else
00078     {
00079         throw std::runtime_error(name + " is not a valid element name.");
00080     }
00081 
00082     return std::string();
00083 }
00084 
00085 std::string StringUtilities::makeFullyQualifiedRobonetNode(const std::string& channel, const std::string& node)
00086 {
00087     string output = TOKEN_DELIMITER + channel + TOKEN_DELIMITER + node;
00088 
00089     if (isFullyQualifiedRobonetNode(output))
00090     {
00091         return output;
00092     }
00093     else
00094     {
00095         throw std::runtime_error("Unable to create valid fully qualified Robonet node from inputs [" + channel + "] and [" + node + "]");
00096     }
00097 
00098     return string();
00099 }
00100 
00101 std::string StringUtilities::makeFullyQualifiedRobonetElement(const std::string& fqNode, const std::string& element)
00102 {
00103     string output = fqNode + TOKEN_DELIMITER + element;
00104 
00105     if (isFullyQualifiedRobonetElement(output))
00106     {
00107         return output;
00108     }
00109     else
00110     {
00111         throw std::runtime_error("Unable to create valid fully qualified Robonet node from inputs [" + fqNode + "] and [" + element + "]");
00112     }
00113 
00114     return string();
00115 }
00116 
00117 std::string StringUtilities::makeFullyQualifiedRobonetElement(const std::string& channel, const std::string& node, const std::string& element)
00118 {
00119     string output = TOKEN_DELIMITER + channel + TOKEN_DELIMITER + node + TOKEN_DELIMITER + element;
00120 
00121     if (isFullyQualifiedRobonetElement(output))
00122     {
00123         return output;
00124     }
00125     else
00126     {
00127         throw std::runtime_error("Unable to create valid fully qualified Robonet node from inputs [" + channel + "], [" + node + "], and [" + element + "]");
00128     }
00129 
00130     return string();
00131 }
00132 
00133 bool StringUtilities::isFullyQualifiedRoboDynChain(const std::string& name)
00134 {
00135     return boost::regex_match(name, VALID_ROBODYN_CHAIN);
00136 }
00137 
00138 bool StringUtilities::isFullyQualifiedRoboDynJoint(const std::string& name)
00139 {
00140     return boost::regex_match(name, VALID_ROBODYN_JOINT);
00141 }
00142 
00143 bool StringUtilities::isFullyQualifiedRoboDynJointWithGroup(const std::string& name)
00144 {
00145     return boost::regex_match(name, VALID_ROBODYN_JOINT_WITH_GROUP);
00146 }
00147 
00148 std::string StringUtilities::getRoboDynChain(const std::string& name)
00149 {
00150     if (isFullyQualifiedRoboDynChain(name) || isFullyQualifiedRoboDynJoint(name) || isFullyQualifiedRoboDynJointWithGroup(name))
00151     {
00152         boost::match_results<std::string::const_iterator> matches;
00153         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBODYN_CHAIN);
00154         return std::string(matches[1].first, matches[1].second);
00155     }
00156     else
00157     {
00158         throw std::runtime_error(name + " is not a valid chain or joint name.");
00159     }
00160 
00161     return std::string();
00162 }
00163 
00164 std::string StringUtilities::getFullyQualifiedRoboDynChain(const std::string& name)
00165 {
00166     return string(TOKEN_DELIMITER + ROBODYN_PREFIX + TOKEN_DELIMITER) + getRoboDynChain(name);
00167 }
00168 
00169 std::string StringUtilities::getRoboDynJoint(const std::string& name)
00170 {
00171     if (isFullyQualifiedRoboDynJoint(name))
00172     {
00173         boost::match_results<std::string::const_iterator> matches;
00174         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBODYN_JOINT);
00175         return std::string(matches[2].first, matches[2].second);
00176     }
00177     else if (isFullyQualifiedRoboDynJointWithGroup(name))
00178     {
00179         boost::match_results<std::string::const_iterator> matches;
00180         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBODYN_JOINT_WITH_GROUP);
00181         return std::string(matches[3].first, matches[3].second);
00182     }
00183     else
00184     {
00185         throw std::runtime_error(name + " is not a valid joint or joint-with-group name.");
00186     }
00187 
00188     return std::string();
00189 }
00190 
00191 std::string StringUtilities::getRoboDynJointGroup(const std::string& name)
00192 {
00193     if (isFullyQualifiedRoboDynJointWithGroup(name))
00194     {
00195         boost::match_results<std::string::const_iterator> matches;
00196         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBODYN_JOINT_WITH_GROUP);
00197         return std::string(matches[2].first, matches[2].second);
00198     }
00199     else
00200     {
00201         throw std::runtime_error(name + " is not a valid joint-with-group name.");
00202     }
00203 
00204     return std::string();
00205 }
00206 
00207 std::string StringUtilities::getRoboDynJointWithGroup(const std::string& name)
00208 {
00209     if (isFullyQualifiedRoboDynJointWithGroup(name))
00210     {
00211         boost::match_results<std::string::const_iterator> matches;
00212         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBODYN_JOINT_WITH_GROUP);
00213         return std::string(matches[2].first, matches[3].second);
00214     }
00215     else
00216     {
00217         throw std::runtime_error(name + " is not a valid joint-with-group name.");
00218     }
00219 
00220     return std::string();
00221 }
00222 
00223 std::string StringUtilities::getRoboDynEverythingButJoint(const std::string& name)
00224 {
00225     if (isFullyQualifiedRoboDynJoint(name))
00226     {
00227         boost::match_results<std::string::const_iterator> matches;
00228         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBODYN_JOINT);
00229         return ROBODYN_PREFIX + TOKEN_DELIMITER + std::string(matches[1].first, matches[1].second);
00230     }
00231     else if (isFullyQualifiedRoboDynJointWithGroup(name))
00232     {
00233         boost::match_results<std::string::const_iterator> matches;
00234         boost::regex_search(name.begin(), name.end(), matches, VALID_ROBODYN_JOINT_WITH_GROUP);
00235         return ROBODYN_PREFIX + TOKEN_DELIMITER + std::string(matches[1].first, matches[2].second);
00236     }
00237     else
00238     {
00239         throw std::runtime_error(name + " is not a valid joint or joint-with-group name.");
00240     }
00241 
00242     return std::string();
00243 }
00244 
00245 std::string StringUtilities::makeFullyQualifiedRoboDynChain(const std::string& chain)
00246 {
00247     string output = ROBODYN_PREFIX + TOKEN_DELIMITER + chain;
00248 
00249     if (isFullyQualifiedRoboDynChain(output))
00250     {
00251         return output;
00252     }
00253     else
00254     {
00255         throw std::runtime_error("Unable to create valid fully qualified RoboDyn chain from input [" + chain + "]");
00256     }
00257 
00258     return string();
00259 }
00260 
00261 std::string StringUtilities::makeFullyQualifiedRoboDynJoint(const std::string& chain, const std::string& joint)
00262 {
00263     string output = ROBODYN_PREFIX + TOKEN_DELIMITER + chain + TOKEN_DELIMITER + joint;
00264 
00265     if (isFullyQualifiedRoboDynJoint(output))
00266     {
00267         return output;
00268     }
00269     else
00270     {
00271         throw std::runtime_error("Unable to create valid fully qualified RoboDyn joint from input [" + chain + "] and [" + joint + "]");
00272     }
00273 
00274     return string();
00275 }
00276 
00277 std::string StringUtilities::makeFullyQualifiedRoboDynJointGroup(const std::string& chain, const std::string& group)
00278 {
00279     string output = ROBODYN_PREFIX + TOKEN_DELIMITER + chain + TOKEN_DELIMITER + group;
00280 
00281     if (isFullyQualifiedRoboDynJointWithGroup(output) || isFullyQualifiedRoboDynJoint(output))
00282     {
00283         return output;
00284     }
00285     else
00286     {
00287         throw std::runtime_error("Unable to create valid fully qualified RoboDyn group from input [" + chain + "], [" + group + "]");
00288     }
00289 
00290     return string();
00291 }
00292 
00293 std::string StringUtilities::makeFullyQualifiedRoboDynJointWithGroup(const std::string& chain, const std::string& group, const std::string& joint)
00294 {
00295     string output = ROBODYN_PREFIX + TOKEN_DELIMITER + chain + TOKEN_DELIMITER + group + TOKEN_DELIMITER + joint;
00296 
00297     if (isFullyQualifiedRoboDynJointWithGroup(output))
00298     {
00299         return output;
00300     }
00301     else
00302     {
00303         throw std::runtime_error("Unable to create valid fully qualified RoboDyn joint-with-group from input [" + chain + "], [" + group + "], and [" + joint + "]");
00304     }
00305 
00306     return string();
00307 }
00308 
00309 std::string StringUtilities::makeFullyQualifiedRoboDynElement(const std::string& fqJoint, const std::string& element)
00310 {
00311     string output = fqJoint + TOKEN_DELIMITER + element;
00312 
00313     if (isFullyQualifiedRoboDynJointWithGroup(output))
00314     {
00315         return output;
00316     }
00317     else
00318     {
00319         throw std::runtime_error("Unable to create valid fully qualified RoboDyn element from input [" + fqJoint + "] and [" + element + "]");
00320     }
00321 
00322     return string();
00323 }
00324 
00325 bool StringUtilities::isItemWithNumber(const std::string& name)
00326 {
00327     return boost::regex_match(name, ITEM_WITH_NUMBER);
00328 }
00329 
00330 std::string StringUtilities::getItem(const std::string& name)
00331 {
00332     if (isItemWithNumber(name))
00333     {
00334         boost::match_results<std::string::const_iterator> matches;
00335         boost::regex_search(name.begin(), name.end(), matches, ITEM_WITH_NUMBER);
00336         return std::string(matches[1].first, matches[1].second);
00337     }
00338     else
00339     {
00340         throw std::runtime_error(name + " is not a valid item with number.");
00341     }
00342 
00343     return std::string();
00344 }
00345 
00346 std::string StringUtilities::getNumber(const std::string& name)
00347 {
00348     if (isItemWithNumber(name))
00349     {
00350         boost::match_results<std::string::const_iterator> matches;
00351         boost::regex_search(name.begin(), name.end(), matches, ITEM_WITH_NUMBER);
00352         return std::string(matches[2].first, matches[2].second);
00353     }
00354     else
00355     {
00356         throw std::runtime_error(name + " is not a valid item with number.");
00357     }
00358 
00359     return std::string();
00360 }


robot_instance
Author(s):
autogenerated on Sat Jun 8 2019 20:43:12