OdbDesignLib
OdbDesign ODB++ Parsing Library
 
Loading...
Searching...
No Matches
AttributeLookupTable.cpp
1#include "AttributeLookupTable.h"
2#include <sstream>
3
4namespace Odb::Lib::FileModel::Design
5{
6 const std::map<std::string, std::string>& AttributeLookupTable::GetAttributeLookupTable() const
7 {
8 return m_attributeLookupTable;
9 }
10
11 bool AttributeLookupTable::ParseAttributeLookupTable(const std::string& attributeLookupTableString)
12 {
13 std::stringstream ss(attributeLookupTableString);
14 std::string token;
15
16 // skip the content before the first semicolon
17 if (!std::getline(ss, token, ';'))
18 return false;
19
20 // attributes
21 if (std::getline(ss, token, ';'))
22 {
23 std::stringstream attributesStream(token);
24 std::string attributeAssignment;
25 while (std::getline(attributesStream, attributeAssignment, ','))
26 {
27 if (!attributeAssignment.empty())
28 {
29 std::string name;
30 std::string value;
31
32 std::stringstream aa_ss(attributeAssignment);
33 if (attributeAssignment.find("=") != std::string::npos)
34 {
35 if (!std::getline(aa_ss, name, '=')) return false;
36 if (!std::getline(aa_ss, value)) return false;
37 }
38 else
39 {
40 if (!std::getline(aa_ss, name)) return false;
41 }
42
43 m_attributeLookupTable[name] = value;
44 }
45 }
46 }
47
48 // ID
49 if (std::getline(ss, token, ';'))
50 {
51 std::string name;
52 std::string value;
53
54 std::stringstream token_ss(token);
55 if (token.find("=") != std::string::npos)
56 {
57 if (!std::getline(token_ss, name, '=')) return false;
58 if (!std::getline(token_ss, value)) return false;
59 }
60
61 m_attributeLookupTable[name] = value;
62 }
63
64 return true;
65 }
66}