swg_utils.cpp
Go to the documentation of this file.
1/** @file swg_utils.cpp utility functions for bindings*/
2
3/* FAU Discrete Event Systems Library (libfaudes)
4
5 Copyright (C) 2008-2025 Thomas Moor
6 Exclusive copyright is granted to Klaus Schmidt
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
22*/
23
24#include "swg_utils.h"
25
26
27namespace faudes {
28
29// programatically throw exceptions
30void faudes_throw_exception(const std::string& msg) {
31 throw Exception("faudes script", msg, 49);
32}
33
34
35// global switches
37std::string faudes_dotpath = "dot";
38
39// access functions
42void faudes_dotexecpath(const std::string& filename) { faudes_dotpath=filename; }
43std::string faudes_dotexecpath() { return faudes_dotpath; }
44std::string faudes_version(void) { return VersionString()+" "+PluginsString(); }
45std::string faudes_build(void) { return BuildString(); }
46
47// helper: run dot for test
48bool faudes_dotready(void) {
50}
51
52//global help dictionary topic -> key -> text
53std::map< std::string, std::string > faudes_dictionary_topics;
54std::map< std::string, std::map<std::string, std::vector<std::string> > > faudes_dictionary_entries;
55
56// insert topic to dictionary
57void faudes_dict_insert_topic(const std::string& topic, const std::string& text) {
58 faudes_dictionary_topics[topic]=text;
59}
60
61// insert entry to dictionary
62void faudes_dict_insert_entry(const std::string& topic, const std::string& key, const std::string& entry) {
63 std::string k=key;
64 if(k.length()>0)
65 k.at(0)=toupper(k.at(0));
66 faudes_dictionary_entries[topic][k].push_back(entry);
67 if(topic!="")
68 if(faudes_dictionary_topics[topic]=="")
69 faudes_dictionary_topics[topic]=topic;
70}
71
72
73// main help text
74void faudes_help(void) {
75 std::stringstream sstr;
76
77 // section: intro
78 sstr << std::endl
79 << "libFAUDES bindings provide access to libFAUDES data structures and functions. " << std::endl
80 << "For detailed information, please consult the libFAUDES documentation."<< std::endl
81 << std::endl
82 << "All libFAUDES bindings are in the module 'faudes', ie access is via 'faudes.*'." << std::endl
83 << std::endl
84 << "Interface:" << std::endl
85 << std::endl;
86
87 // section: topics
88 std::map< std::string, std::string >::iterator tit;
89 for(tit=faudes_dictionary_topics.begin(); tit!=faudes_dictionary_topics.end();tit++) {
90 std::string left = " faudes.Help(\"" + tit->first +"\")";
91 std::string right = tit->second;
92 while(left.length()<37) left+=" ";
93 sstr << left << right << std::endl;
94 }
95 sstr << std::endl;
96
97 // section: behavioural
98 sstr
99 << "Configuration:" << std::endl
100 << std::endl
101 << " faudes.StateNamesOn() enable automatic state names" << std::endl
102 << " faudes.StateNamesOff() disable automatic state names" << std::endl
103 << " faudes.DotExecPath(\"filename\") path of dot executable" << std::endl
104 << " faudes.Version() return libfaudes version string" << std::endl
105 << std::endl
106 << "Console Commands:" << std::endl
107 << std::endl
108 << " faudes.Print(\"message\") print as faudes debugging message" << std::endl
109 << " faudes.Error(\"message\") abort script with error message" << std::endl
110 << " faudes.Verbosity(int) set verbositry level " << std::endl;
111
112 // do print to stderr
113 Print(0,sstr.str()); // verb 0 <> always
114}
115
116// section text
117void faudes_help(const std::string& topic) {
118 std::stringstream sstr;
119
120 // section: intro
121 sstr
122 << std::endl
123 << "libFAUDES help topic: \"" << topic << "\"" << std::endl
124 << std::endl;
125
126 // section: list entries
127 std::map< std::string, std::map< std::string, std::vector<std::string> > >::iterator tit;
128 tit = faudes_dictionary_entries.find(topic);
129 if(tit!=faudes_dictionary_entries.end()) {
130 std::map< std::string, std::vector<std::string> >::iterator kit;
131 for(kit = tit->second.begin(); kit != tit->second.end(); kit++) {
132 if(kit != tit->second.begin()) sstr << std::endl;
133 const std::string& line = kit->first;
134 sstr << " *** " << line << " ***" << std::endl;
135 for(unsigned int i=0; i< kit->second.size(); i++) {
136 const std::string& line = kit->second[i];
137 std::size_t sep = line.find_first_of(' ');
138 if(sep==std::string::npos) sep=0;
139 while(sep<20) { sstr << " "; sep++; };
140 sstr << line << std::endl;
141 }
142 }
143 } else {
144 sstr << " (no entries) " << std::endl;
145 }
146
147 // do print to stderr
148 Print(0,sstr.str()); // verb 0 <> always
149}
150
151// API wrappers
152void faudes_gen_version(const Generator& rGen, const std::string& ver, Generator& rRes) {
153 rGen.Version(ver,rRes);
154}
155void faudes_gen_version(const Generator& rGen, const std::string& pat, const std::string& rep, Generator& rRes) {
156 rGen.Version(pat,rep,rRes);
157}
158void faudes_set_union(const EventSet& rAlph1, const EventSet& rAlph2, EventSet& rRes)
159 { rRes = rAlph1; rRes.InsertSet(rAlph2); }
160void faudes_set_intersection(const EventSet& rAlph1, const EventSet& rAlph2, EventSet& rRes)
161 { rRes = rAlph1; rRes.RestrictSet(rAlph2); }
162void faudes_set_difference(const EventSet& rAlph1, const EventSet& rAlph2, EventSet& rRes)
163 { rRes = rAlph1; rRes.EraseSet(rAlph2); }
164
165
166
167}//namespace
168
virtual void InsertSet(const NameSet &rOtherSet)
void EraseSet(const NameSet &rOtherSet)
void RestrictSet(const NameSet &rOtherSet)
static void StateNamesEnabledDefault(bool flag)
virtual void Version(const std::string &rVersion, vGenerator &rResGen) const
std::string VersionString()
void faudes_gen_version(const Generator &rGen, const std::string &ver, Generator &rRes)
std::string faudes_dotexecpath()
Definition swg_utils.cpp:43
void faudes_help(void)
Definition swg_utils.cpp:74
bool faudes_statenames
Definition swg_utils.cpp:36
bool DotReady(const std::string &rDotExec)
void faudes_set_union(const EventSet &rAlph1, const EventSet &rAlph2, EventSet &rRes)
std::string faudes_version(void)
Definition swg_utils.cpp:44
std::map< std::string, std::map< std::string, std::vector< std::string > > > faudes_dictionary_entries
Definition swg_utils.cpp:54
void faudes_set_intersection(const EventSet &rAlph1, const EventSet &rAlph2, EventSet &rRes)
std::string PluginsString()
void faudes_statenames_on(void)
Definition swg_utils.cpp:40
std::string BuildString()
void faudes_dict_insert_topic(const std::string &topic, const std::string &text)
Definition swg_utils.cpp:57
std::string faudes_build(void)
Definition swg_utils.cpp:45
void faudes_statenames_off(void)
Definition swg_utils.cpp:41
std::map< std::string, std::string > faudes_dictionary_topics
Definition swg_utils.cpp:53
void faudes_dict_insert_entry(const std::string &topic, const std::string &key, const std::string &entry)
Definition swg_utils.cpp:62
bool faudes_dotready(void)
Definition swg_utils.cpp:48
void Print(int v, const std::string &message)
void faudes_throw_exception(const std::string &msg)
Definition swg_utils.cpp:30
void faudes_set_difference(const EventSet &rAlph1, const EventSet &rAlph2, EventSet &rRes)
std::string faudes_dotpath
Definition swg_utils.cpp:37

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen