4namespace Odb::Lib::FileModel::Design
12 SymbolName::SymbolName()
14 , m_unitType(UnitType::None)
19 std::string SymbolName::GetName()
const
24 int SymbolName::GetIndex()
const
29 UnitType SymbolName::GetUnitType()
const
34 void SymbolName::ApplyDefaultUnitTypeIfNone(UnitType unitType)
36 if (m_unitType == UnitType::None)
38 m_unitType = unitType;
42 bool SymbolName::Parse(
const std::filesystem::path& path,
const std::string& line,
int lineNumber)
44 std::stringstream lineStream(line);
48 if (!std::getline(lineStream, token,
' '))
50 throw_parse_error(path, line, token, lineNumber);
53 if (!token.empty() && token[0] ==
'$')
57 m_index = std::stoi(token.substr(1));
61 throw_parse_error(path, line, token, lineNumber);
64 catch (
const std::invalid_argument&)
67 throw_parse_error(path, line, token, lineNumber);
69 catch (
const std::out_of_range&)
72 throw_parse_error(path, line, token, lineNumber);
76 if (!std::getline(lineStream, token,
' ') || token.empty())
79 throw_parse_error(path, line, token, lineNumber);
90 if (std::getline(lineStream, token,
' '))
95 m_unitType = UnitType::Metric;
98 m_unitType = UnitType::Imperial;
106 std::unique_ptr<Odb::Lib::Protobuf::SymbolName> SymbolName::to_protobuf()
const
108 auto message = std::make_unique<Odb::Lib::Protobuf::SymbolName>();
109 message->set_name(m_name);
110 message->set_unittype(
static_cast<Odb::Lib::Protobuf::UnitType
>(m_unitType));
114 void SymbolName::from_protobuf(
const Odb::Lib::Protobuf::SymbolName& message)
116 m_name = message.name();
117 m_unitType =
static_cast<UnitType
>(message.unittype());