PeriDyno 1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DeclareEnum.cpp
Go to the documentation of this file.
1#include "DeclareEnum.h"
2#include <vector>
3#include <string>
4
5namespace dyno
6{
7 std::string earse_spacing(const std::string& str)
8 {
9 if (str.empty())
10 return std::string("");
11 std::string tmpStr;
12 for (int i = 0; i < str.length(); i++)
13 if (str[i] != ' ')
14 tmpStr += str[i];
15
16 return tmpStr;
17 }
18
19
20 bool parse_enum_string(const std::string& enum_str, EnumMap& enumKeyValueList)
21 {
22 std::vector<std::string> enum_value_list;
23
24 size_t npos = enum_str.find(",");
25 size_t nlastpos = 0;
26 while (npos != std::string::npos)
27 {
28 enum_value_list.push_back(enum_str.substr(nlastpos, npos - nlastpos));
29 nlastpos = npos + 1;
30 npos = enum_str.find(",", static_cast<unsigned int>(nlastpos));
31 }
32 if (nlastpos != enum_str.length())
33 {
34 enum_value_list.push_back(enum_str.substr(nlastpos, enum_str.length() - nlastpos));
35 }
36 if (enum_value_list.size() == 0)
37 return false;
38
39 enumKeyValueList.clear();
40 int nDefaultValue = 0;
41 for (std::vector<std::string>::iterator itor = enum_value_list.begin(); itor != enum_value_list.end(); itor++)
42 {
43 std::string str_enum_field = earse_spacing(*itor);
44 long nEnumValue;
45 std::string str_enum_field_name;
46
47 int nPos = str_enum_field.find("=");
48 if (nPos != std::string::npos)
49 {
50 char tmpKeyValue[64] = { '\0' };
51 std::string tmpValue_;
52 str_enum_field_name = str_enum_field.substr(0, nPos);
53
54 tmpValue_ = str_enum_field.substr(nPos + 1, (*itor).length());
55 sscanf(tmpValue_.c_str(), "%[^LlUu]", tmpKeyValue);
56 tmpValue_ = tmpKeyValue;
57 if (tmpValue_.find("0x") != std::string::npos)
58 nEnumValue = strtol(tmpKeyValue, NULL, 16);
59 else if (tmpValue_[0] == '0')
60 nEnumValue = strtol(tmpKeyValue, NULL, 8);
61 else
62 nEnumValue = strtol(tmpKeyValue, NULL, 10);
63 }
64 else
65 {
66 str_enum_field_name = str_enum_field;
67 nEnumValue = nDefaultValue;
68 }
69 nDefaultValue = nEnumValue + 1;
70
71 enumKeyValueList[nEnumValue] = str_enum_field_name;
72 }
73
74 enum_value_list.clear();
75
76 if (enumKeyValueList.size() == 0)
77 return false;
78
79
80 return true;
81 }
82
83 void PEnum::setCurrentKey(int index)
84 {
85 if (m_enum_map.find(index) == m_enum_map.end())
86 return;
87
88 m_enum_value = index;
89 m_enum_name = m_enum_map[index];
90 }
91}
EnumMap m_enum_map
Definition DeclareEnum.h:77
std::string m_enum_name
Definition DeclareEnum.h:74
void setCurrentKey(int index)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
bool parse_enum_string(const std::string &enum_str, EnumMap &enumKeyValueList)
std::string earse_spacing(const std::string &str)
std::map< int, std::string > EnumMap
Definition DeclareEnum.h:25