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
38
39// access functions
42void faudes_dotpath(const std::string& filename) { faudes_dotpath_def=filename; }
43std::string faudes_dotpath() { return faudes_dotpath_def; }
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.DotPath(\"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 << "Convenience Functions:" << std::endl
108 << std::endl
109 << " faudes.New(\"type\") instantiate object by class name" << std::endl
110 << " faudes.NewFromString(\"type\",\"str\") instantiate object from string" << std::endl
111 << " faudes.NewFromFile(\"type\",\"file\") instantiate object from file" << std::endl
112 << std::endl
113 << "Console Commands:" << std::endl
114 << std::endl
115 << " faudes.Verbosity(int) set verbositry level " << std::endl
116 << " faudes.Print(\"message\") print as faudes debugging message" << std::endl
117 << " faudes.Print(int,\"message\") conditional debugging message" << std::endl
118 << " faudes.Error(\"message\") abort script with error message" << std::endl;
119
120
121 // do print to stderr
122 Print(0,sstr.str()); // verb 0 <> always
123}
124
125// section text
126void faudes_help(const std::string& topic) {
127
128 // find topic
129 std::string abstract;
130 std::map< std::string, std::string >::iterator tit;
131 tit=faudes_dictionary_topics.find(topic);
132 if(tit!=faudes_dictionary_topics.end())
133 abstract=tit->second;
134
135 // prepare
136 std::stringstream sstr;
137
138 // section: intro
139 sstr
140 << std::endl
141 << "libFAUDES help topic: \"" << topic << "\": " << abstract << std::endl
142 << std::endl;
143
144 // section: list entries
145 std::map< std::string, std::map< std::string, std::vector<std::string> > >::iterator sit;
146 sit = faudes_dictionary_entries.find(topic);
147 if(sit!=faudes_dictionary_entries.end()) {
148 std::map< std::string, std::vector<std::string> >::iterator kit;
149 for(kit = sit->second.begin(); kit != sit->second.end(); kit++) {
150 if(kit != sit->second.begin()) sstr << std::endl;
151 const std::string& line = kit->first;
152 sstr << " *** " << line << " ***" << std::endl;
153 for(unsigned int i=0; i< kit->second.size(); i++) {
154 const std::string& line = kit->second[i];
155 std::size_t sep = line.find_first_of(' ');
156 if(sep==std::string::npos) sep=0;
157 while(sep<20) { sstr << " "; sep++; };
158 sstr << line << std::endl;
159 }
160 }
161 } else {
162 sstr << " (no entries) " << std::endl;
163 }
164
165 // do print to stderr
166 Print(0,sstr.str()); // verb 0 <> always
167}
168
169// API wrappers
170void faudes_gen_version(const Generator& rGen, const std::string& ver, Generator& rRes) {
171 rGen.Version(ver,rRes);
172}
173void faudes_gen_version(const Generator& rGen, const std::string& pat, const std::string& rep, Generator& rRes) {
174 rGen.Version(pat,rep,rRes);
175}
176void faudes_set_union(const EventSet& rAlph1, const EventSet& rAlph2, EventSet& rRes)
177 { rRes = rAlph1; rRes.InsertSet(rAlph2); }
178void faudes_set_intersection(const EventSet& rAlph1, const EventSet& rAlph2, EventSet& rRes)
179 { rRes = rAlph1; rRes.RestrictSet(rAlph2); }
180void faudes_set_difference(const EventSet& rAlph1, const EventSet& rAlph2, EventSet& rRes)
181 { rRes = rAlph1; rRes.EraseSet(rAlph2); }
182
183
184
185}//namespace
186
#define FAUDES_DOTPATH
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)
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
std::string faudes_dotpath()
Definition swg_utils.cpp:43
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
std::string faudes_dotpath_def
Definition swg_utils.cpp:37
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)

libFAUDES 2.34g --- 2026.03.30 --- c++ api documentaion by doxygen