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 << " faudes.Build() return libFAUDES build string" << std::endl
106 << std::endl
107 << "Console Commands:" << std::endl
108 << std::endl
109 << " faudes.Verbosity(int) set verbositry level " << std::endl
110 << " faudes.Print(\"message\") print as faudes debugging message" << std::endl
111 << " faudes.Print(int,\"message\") conditional debugging message" << std::endl
112 << " faudes.Error(\"message\") abort script with error message" << std::endl;
113
114 // do print to stderr
115 Print(0,sstr.str()); // verb 0 <> always
116}
117
118// section text
119void faudes_help(const std::string& topic) {
120 std::stringstream sstr;
121
122 // section: intro
123 sstr
124 << std::endl
125 << "libFAUDES help topic: \"" << topic << "\"" << std::endl
126 << std::endl;
127
128 // section: list entries
129 std::map< std::string, std::map< std::string, std::vector<std::string> > >::iterator tit;
130 tit = faudes_dictionary_entries.find(topic);
131 if(tit!=faudes_dictionary_entries.end()) {
132 std::map< std::string, std::vector<std::string> >::iterator kit;
133 for(kit = tit->second.begin(); kit != tit->second.end(); kit++) {
134 if(kit != tit->second.begin()) sstr << std::endl;
135 const std::string& line = kit->first;
136 sstr << " *** " << line << " ***" << std::endl;
137 for(unsigned int i=0; i< kit->second.size(); i++) {
138 const std::string& line = kit->second[i];
139 std::size_t sep = line.find_first_of(' ');
140 if(sep==std::string::npos) sep=0;
141 while(sep<20) { sstr << " "; sep++; };
142 sstr << line << std::endl;
143 }
144 }
145 } else {
146 sstr << " (no entries) " << std::endl;
147 }
148
149 // do print to stderr
150 Print(0,sstr.str()); // verb 0 <> always
151}
152
153// API wrappers
154void faudes_gen_version(const Generator& rGen, const std::string& ver, Generator& rRes) {
155 rGen.Version(ver,rRes);
156}
157void faudes_gen_version(const Generator& rGen, const std::string& pat, const std::string& rep, Generator& rRes) {
158 rGen.Version(pat,rep,rRes);
159}
160void faudes_set_union(const EventSet& rAlph1, const EventSet& rAlph2, EventSet& rRes)
161 { rRes = rAlph1; rRes.InsertSet(rAlph2); }
162void faudes_set_intersection(const EventSet& rAlph1, const EventSet& rAlph2, EventSet& rRes)
163 { rRes = rAlph1; rRes.RestrictSet(rAlph2); }
164void faudes_set_difference(const EventSet& rAlph1, const EventSet& rAlph2, EventSet& rRes)
165 { rRes = rAlph1; rRes.EraseSet(rAlph2); }
166
167
168
169}//namespace
170
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.34d --- 2026.03.11 --- c++ api documentaion by doxygen