PCB Environment: /home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/Loaders/DSNParserBase.hpp Source File

PCB Environment 2

Loading...
Searching...
No Matches
DSNParserBase.hpp
1
2#ifndef GYM_PCB_LOADERS_DSNPARSERBASE_H
3#define GYM_PCB_LOADERS_DSNPARSERBASE_H
4
5#include "Loaders/DSN.hpp"
6#include <cassert>
7#include <iostream>
8#include <iterator>
9#include <regex>
10
11 class Token
12{
13public:
14 Token(const std::string &s) : _s(s) { }
15 size_t length() const { return _s.size(); }
16 const std::string& String() const { return _s; }
17 int64_t Int64() const { return std::stol(_s); }
18 int AngleDeg() const;
19 double Float64() const;
20 bool Bool() const;
21private:
22 const std::string _s;
23};
24inline double Token::Float64() const
25{
26 double d;
27 std::from_chars(_s.data(), _s.data() + _s.size(), d);
28 return d;
29}
30
31 class DSNParserBase
32{
33public:
34 DSNParserBase(dsn::Data&);
35 virtual bool parse(const std::string&) = 0;
36protected:
37 dsn::Data &mData;
38 char mStringQuote{0};
39 char mEscapeChar{0};
40 bool mQuoteOpen{false};
41 bool mEscapeActive{false};
42protected:
43 bool checkQuote(char c);
44 void resetQuote();
45 int isBracket(char c) const;
46 int checkBracket(char c);
47 size_t nextBracket(const std::string&, int dir);
48 size_t skipspace(const std::string&, size_t pos) const;
49 size_t skipspaceRev(const std::string&, size_t minPos, size_t pos) const;
50 std::vector<std::string> gather(const std::string&, const char *name, const int depth = 1);
51 std::vector<std::string> gatherArray(const std::string&);
52 std::vector<Token> tokenize(const std::string&);
53 Token firstToken(const std::string&, size_t *from = 0);
54 std::string unquote(const std::string&) const;
55 std::string unquotePin(const std::string&);
56 std::string noHyphen(std::string) const;
57
58 int unitToExp10(const std::string&) const;
59 char parseSide(const std::string&) const;
60};
61
62inline std::string DSNParserBase::noHyphen(std::string s) const
63{
64 for (auto &c : s)
65 if (c == '-')
66 c = '_';
67 return s;
68}
69
70#endif // GYM_PCB_LOADERS_DSNPARSERBASE_H
Token
Definition DSNParserBase.hpp:12
dsn::Data
Definition DSN.hpp:211