Go to the documentation of this file.00001 #include <actasp/AspAtom.h>
00002
00003 using namespace std;
00004
00005 namespace actasp {
00006
00007 AspAtom::AspAtom(const std::string& formula) throw () :atom(formula) {}
00008
00009
00010 unsigned int AspAtom::arity() const throw() {
00011 return getParameters().size();
00012 }
00013
00014 std::string AspAtom::getName() const throw() {
00015 return atom.substr(0,atom.find_first_of('('));
00016 }
00017
00018 std::vector<std::string> AspAtom::getParameters() const throw() {
00019
00020 size_t start = atom.find_first_of('(');
00021 size_t end = atom.find_last_of(')');
00022
00023 if(start == string::npos || end == string::npos)
00024 return vector<string>();
00025
00026 start++;
00027
00028 vector<string> params;
00029
00030 if(start >= end)
00031 return params;
00032
00033 size_t comma = atom.find_first_of(',',start);
00034 size_t end_param = std::min(comma,end);
00035
00036 while(start < end) {
00037 params.push_back(atom.substr(start,end_param-start));
00038 start = end_param+1;
00039 end_param = std::min(atom.find_first_of(',',start),end);
00040 }
00041
00042 return params;
00043 }
00044
00045
00046 }