12#ifndef _EXPORT_ALG_LINE_H_
13#define _EXPORT_ALG_LINE_H_
77 const std::string&
func() const noexcept;
123 const std::
string& operator[](const std::
string key) const;
130 const std::
string&
rawStr() const;
141 bool hasKey(const std::
string& key) const noexcept;
150 bool hasUnknownKey(const std::vector<std::
string>& keys) const noexcept;
152 bool hasUnknownKey(const std::vector<std::
string>& keys, std::
string& unknown_key) const noexcept;
177 bool isValidKey(const std::
string& key, const std::vector<std::
string>& keys) const noexcept;
187 bool setKey(std::vector<
Param_Type>::size_type index, const std::
string& key);
203 bool isEnd() const noexcept;
221 std::ostream&
print(std::ostream& out = std::cout, std::
string prefix = "") const;
231 std::
string::size_type
_findChars(const std::
string& s, std::
string cs) const noexcept;
240 std::
string::size_type
_findChar(const std::
string& s,
char c) const noexcept;
279 assert(index <
_returns.size() &&
"Alg_Line check returns index size within bound.");
286 assert((index <
_params.size() &&
"Alg_Line check params index size within bound."));
292 if (elem.key == key)
return elem;
294 throw std::runtime_error(
"No key '" + key +
"'!");
303 if (elem.key == key)
return true;
310 if (!
contains(keys, elem.key))
return true;
318 unkown_key = elem.key;
327 std::vector<std::string> keys(
_params.size());
329 std::sort(keys.begin(), keys.end());
330 return std::adjacent_find(keys.begin(), keys.end()) != keys.end();
334 if (!
hasKey(key))
return false;
335 std::vector<bool> exists(keys.size(),
false);
337 auto&& the_key = elem.key;
338 for (
decltype(keys.size()) i = 0; i != keys.size(); ++i) {
339 if (keys[i] == the_key) exists[i] =
true;
342 for (
auto&& ck : exists) {
343 if (!ck)
return false;
348inline bool Alg_Line::setKey(std::vector<Param_Type>::size_type index,
const std::string& key) {
349 assert(index <
_params.size() &&
"Alg_Line check params index size within bound when setting key.");
350 if (
_params[index].key ==
"") {
365 out << prefix <<
"$ " <<
_raw_str <<
'\n';
366 if (
_func.empty())
return out;
367 out << prefix <<
"* FUNCTION: " <<
_func <<
'\n';
369 out << prefix <<
"* PARAMS:\n";
370 for (
auto&& p :
_params) out << prefix <<
" > {" << p.key <<
"}={" << p.value <<
"}::{" << p.type <<
"}\n";
373 out << prefix <<
"* RETURN:\n";
374 for (
auto&& r :
_returns) out << prefix <<
" > {" << r.name <<
"}::{" << r.type <<
"}\n";
385 return std::regex_replace(s, std::regex(R
"(\\:\\:)"), "::");
static std::ostream & operator<<(std::ostream &out, const Alg_Line &line)
Print Alg_Line contents (including return values, function names and parameters).
Definition: alg_line.h:396
ALG_Opt
ALG export options.
Definition: alg_opt.h:20
@ FUNCTION_DECLARATION
Definition: alg_opt.h:20
@ NONE
Definition: alg_opt.h:20
Process line of Alg into standard formats.
Definition: alg_line.h:36
void _processFuncParams(const std::vector< std::string > &v)
Process function name and parameter variables.
Definition: alg_line.cpp:184
std::string::size_type _findChar(const std::string &s, char c) const noexcept
Find the first occupance of character in string that is not an escape or within quotes.
Definition: alg_line.h:380
const std::string & operator[](const std::string key) const
Get the parameter value with the key.
Definition: alg_line.h:297
bool hasRepeatedKey() const noexcept
Check if parameters have repeated keys.
Definition: alg_line.h:326
std::vector< Return_Type > _returns
Definition: alg_line.h:268
bool hasKey(const std::string &key) const noexcept
Check whether parameters contain the key.
Definition: alg_line.h:301
const std::vector< Param_Type > & params() const noexcept
Parameter variables.
Definition: alg_line.h:283
bool needsEnd() const noexcept
Test whether the function name needs an 'end'.
Definition: alg_line.h:358
bool hasUnknownKey(const std::vector< std::string > &keys) const noexcept
Check if parameters have unknown keys.
Definition: alg_line.h:308
bool setKey(std::vector< Param_Type >::size_type index, const std::string &key)
Set parameter variable key.
Definition: alg_line.h:348
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
Print Alg_Line contents (including return values, function names and parameters).
Definition: alg_line.h:364
std::vector< Param_Type > _params
Definition: alg_line.h:269
void _removeComment(std::string &s) const noexcept
Remove the comment from the string.
Definition: alg_line.cpp:155
const std::vector< Return_Type > & returns() const noexcept
Return variables.
Definition: alg_line.h:276
std::string::size_type _findChars(const std::string &s, std::string cs) const noexcept
Find the first occupance of substring in string that is not an escape or within quotes.
Definition: alg_line.cpp:135
std::string _decodeEscape(const std::string &s) const
Definition: alg_line.h:384
void _processReturns(const std::vector< std::string > &v)
Process returns variables.
Definition: alg_line.cpp:157
std::string _func
Definition: alg_line.h:267
ALG_Opt _opt
Definition: alg_line.h:271
bool isFunctionDeclaration() const noexcept
Check whether the line is for function declaration.
Definition: alg_line.h:362
const std::string & rawStr() const
Return the raw string of the line.
Definition: alg_line.h:299
bool isEnd() const noexcept
Test whether the function name serves as an 'end'.
Definition: alg_line.h:360
bool isValidKey(const std::string &key, const std::vector< std::string > &keys) const noexcept
Check is the key is valid. (not violating the needed sequence.)
Definition: alg_line.h:333
std::string _raw_str
Definition: alg_line.h:270
const std::string & func() const noexcept
Get the function name.
Definition: alg_line.h:274
static bool isFuncNeedsEnd(const std::string &str) noexcept
Definition: functions.h:35
static bool isFuncIsEnd(const std::string &str) noexcept
Definition: functions.h:37
static bool isFuncNoEnd(const std::string &str) noexcept
Definition: functions.h:33
str
Definition: version_bump.py:14
Parameter type.
Definition: alg_line.h:53
std::string type
Definition: alg_line.h:56
std::string value
Definition: alg_line.h:55
std::string key
Definition: alg_line.h:54
Return type.
Definition: alg_line.h:43
std::string name
Definition: alg_line.h:44
std::string type
Definition: alg_line.h:45
static bool contains(const T &container, const typename T::value_type value)
Definition: utils.h:133