Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <bwi_tools/common/Enum.h>
00010 #include <cassert>
00011
00012 std::string EnumName::trim(const std::string& s)
00013 {
00014 std::string::size_type pos = s.find_first_not_of(' ');
00015 if(pos != std::string::npos)
00016 return s.substr(pos, s.find_last_not_of(' ') + 1);
00017 else
00018 return s;
00019 }
00020
00021 EnumName::EnumName(const std::string& enums, size_t numOfEnums) : names(numOfEnums)
00022 {
00023 std::string::size_type pBegin = 0;
00024 std::string::size_type pEnd = enums.find(',');
00025 size_t index = 0;
00026 for(;;)
00027 {
00028 std::string name = trim(pEnd == std::string::npos ? enums.substr(pBegin) :enums.substr(pBegin, pEnd - pBegin));
00029 std::string::size_type p = name.find('=');
00030 if(p != std::string::npos)
00031 {
00032 assert(trim(name.substr(p + 1)) == names[index - 1]);
00033 name = trim(name.substr(0, p));
00034 --index;
00035 }
00036 names[index++] = name;
00037 if(pEnd == std::string::npos)
00038 break;
00039 pBegin = pEnd + 1;
00040 pEnd = enums.find(',', pBegin);
00041 }
00042 assert(index == numOfEnums);
00043 }