44 if(number>= std::numeric_limits<Int>::max())
return "inf";
45 if(number<= std::numeric_limits<Int>::min()+1)
return "-inf";
47 std::stringstream sstr;
56 std::stringstream sstr;
57 sstr <<
"0x" << std::setbase(16) << number;
65 if(number>= std::numeric_limits<Float>::max())
return "inf";
66 if(number<= -1*std::numeric_limits<Float>::max())
return "-inf";
67 std::stringstream sstr;
68 if(number ==
static_cast<Float>(
static_cast<Int>(number) )) {
69 sstr << static_cast<Int>(number);
80 std::string
ExpandString(
const std::string& rString,
unsigned int len) {
83 std::string::size_type xtra = (std::string::size_type) len - rString.length();
84 if ((xtra > 0) && (xtra < 10000)) {
85 res.append(xtra,
' ');
91 std::string
CollapsString(
const std::string& rString,
unsigned int len) {
92 if(len <=1)
return rString;
93 if(rString.length() <= len)
return rString;
95 int ctail = len-chead;
96 return rString.substr(0,chead) +
"..." + rString.substr(rString.length()-ctail,ctail);
102 unsigned long ul = strtoul (rString.c_str(), &end, 0);
103 unsigned long idxmax = std::numeric_limits<Idx>::max();
105 throw Exception(
"atoidx",
"Idx overflow", 600);
111 std::string
StringSubstitute(
const std::string& rString,
const std::string& rFrom,
const std::string& rTo) {
116 while(pos<rString.length()) {
117 std::size_t next=rString.find(rFrom,pos);
118 if(next==std::string::npos)
break;
119 res.append(rString.substr(pos, next-pos));
121 pos=next+rFrom.length();
124 if(pos<rString.length())
125 res.append(rString.substr(pos));
132 return std::string(FAUDES_VERSION);
137 return std::string(FAUDES_PLUGINS);
143 "Ramon Barakat, Ruediger Berndt, Christian Breindl, Christine Baier, Tobias Barthel, Christoph Doerr, Marc Duevel, Norman Franchi, Stefan Goetz, Rainer Hartmann, Jochen Hellenschmidt, Stefan Jacobi, Matthias Leinfelder, Tomas Masopust, Michael Meyer, Andreas Mohr, Thomas Moor, Mihai Musunoi, Bernd Opitz, Katja Pelaic, Irmgard Petzoldt, Sebastian Perk, Thomas Rempel, Daniel Ritter, Berno Schlein, Ece Schmidt, Klaus Schmidt, Anne-Kathrin Schmuck, Sven Schneider, Matthias Singer, Yiheng Tang, Ulas Turan, Christian Wamser, Zhengying Wang, Thomas Wittmann, Shi Xiaoxun, Yang Yi, Jorgos Zaddach, Hao Zhou, Christian Zwick, et al";
149 const std::string& rOutFile,
const std::string& rOutFormat,
const std::string& rDotExec)
151 std::string format=rOutFormat;
154 if(rOutFile.rfind(
'.')+1 < rOutFile.size()) {
155 format=rOutFile.substr(rOutFile.rfind(
'.')+1);
159 if (format ==
"canon");
160 else if (format ==
"dot");
161 else if (format ==
"xdot");
162 else if (format ==
"cmap");
163 else if (format ==
"dia");
164 else if (format ==
"fig");
165 else if (format ==
"gd");
166 else if (format ==
"gd2");
167 else if (format ==
"gif");
168 else if (format ==
"hpgl");
169 else if (format ==
"imap");
170 else if (format ==
"cmapx");
171 else if (format ==
"ismap");
172 else if (format ==
"jpg");
173 else if (format ==
"jpeg");
174 else if (format ==
"mif");
175 else if (format ==
"mp");
176 else if (format ==
"pcl");
177 else if (format ==
"pic");
178 else if (format ==
"plain");
179 else if (format ==
"plain-ext");
180 else if (format ==
"png");
181 else if (format ==
"ps");
182 else if (format ==
"ps2");
183 else if (format ==
"svg");
184 else if (format ==
"svgz");
185 else if (format ==
"vrml");
186 else if (format ==
"vtx");
187 else if (format ==
"wbmp");
188 else if (format ==
"eps");
189 else if (format ==
"pdf");
191 std::stringstream errstr;
192 errstr <<
"Dot output format \"" << format <<
"\" unknown";
193 throw Exception(
"faudes::ProcessDot", errstr.str(), 3);
195 std::string dotcommand = rDotExec +
" -T"+format+
" \""+rDotFile+
"\" -o \""+rOutFile+
"\"";
196 if(system(dotcommand.c_str()) != 0) {
198 "Error in running " + dotcommand, 3);
206 char filename[]=
"faudes_temp_XXXXXX";
211 filedes= mkstemp(filename);
213 FD_DF(
"faudes::CreateTempFile(): error");
217 res=std::string(filename);
219 #ifdef FAUDES_WINDOWS
235 char* tmpname = _mktemp(filename);
238 FD_DF(
"faudes::CreateTempFile(): error");
241 fopen_s(&file,tmpname,
"w");
243 FD_DF(
"faudes::CreateTempFile(): error");
247 res=std::string(tmpname);
249 FD_DF(
"faudes::CreateTempFile(): " << res);
259 if(seppos==std::string::npos)
return res;
260 res=rFullPath.substr(0,seppos+1);
266 std::string res=rFullPath;
268 if(seppos==std::string::npos)
return res;
269 res=rFullPath.substr(seppos+1);
275 std::string res=rFullPath;
277 if(seppos!=std::string::npos) {
278 res=res.substr(seppos+1);
280 std::size_t dotpos = res.find_last_of(
".");
281 if(dotpos!=std::string::npos) {
282 res=res.substr(0,dotpos);
289 std::string res=rFullPath;
291 if(seppos!=std::string::npos) {
292 res=res.substr(seppos+1);
294 std::size_t dotpos = res.find_last_of(
".");
295 if(dotpos!=std::string::npos)
296 if(dotpos +1 < res.size()) {
297 return res.substr(dotpos+1,res.size()-dotpos-1);
299 return std::string();
303 std::string
PrependPath(
const std::string& rLeft,
const std::string& rRight) {
306 return std::string(rRight);
308 return std::string(rLeft);
314 if(seppos!=std::string::npos)
315 sepchar=rLeft.at(seppos);
317 std::string res=rLeft;
318 if(res.at(res.length()-1)!=sepchar)
319 res.append(1,sepchar);
320 if(rRight.at(0)!=sepchar){
324 if(rRight.length()<=1) {
327 res.append(rRight,1,std::string::npos);
335 thedir=opendir(rDirectory.c_str());
336 if(thedir) closedir(thedir);
339 #ifdef FAUDES_WINDOWS
340 DWORD fattr = GetFileAttributesA(rDirectory.c_str());
342 (fattr!=INVALID_FILE_ATTRIBUTES) && (fattr & FILE_ATTRIBUTE_DIRECTORY);
349 std::set< std::string > res;
352 struct dirent *theent;
353 thedir=opendir(rDirectory.c_str());
354 if(!thedir)
return res;
355 while((theent=readdir(thedir))) {
356 std::string fname(theent->d_name);
357 if(fname==
".")
continue;
358 if(fname==
"..")
continue;
363 #ifdef FAUDES_WINDOWS
365 WIN32_FIND_DATA data;
366 hf = FindFirstFile((rDirectory+
"\\*.*").c_str(), &data);
367 if (hf != INVALID_HANDLE_VALUE) {
369 std::string fname(data.cFileName);
370 if(fname==
".")
continue;
371 if(fname==
"..")
continue;
373 }
while (FindNextFile(hf, &data));
387 fp.open(rFilename.c_str(), std::ios::in | std::ios::binary);
393 return remove(rFilename.c_str()) == 0;
397 bool FileCopy(
const std::string& rFromFile,
const std::string& rToFile) {
398 std::ifstream froms(rFromFile.c_str(), std::ios::binary);
399 std::ofstream tos(rToFile.c_str(), std::ios::binary);
400 tos << froms.rdbuf();
402 return !(froms.fail() || tos.fail());
434 void ConsoleOut::Write(
const std::string& message,
long int cntnow,
long int cntdone,
int verb) {
436 if(
mVerb<verb)
return;
437 DoWrite(message,cntnow,cntdone,verb);
440 (void) cntnow; (void) cntdone; (void) verb;
442 if(!sout) sout=&std::cout;
457 mspCount=
new std::map<std::string,long int>();
458 mspMax=
new std::map<std::string,long int>();
466 long int cnt = ((*mspCount)[rTypeName]+=1);
471 (*mspCount)[rTypeName]-=1;
477 #ifdef FAUDES_DEBUG_CODE
485 std::map<std::string,long int>::iterator cit;
495 #ifdef FAUDES_DEBUG_CODE
497 class ExitFunctionInstall {
500 static ExitFunctionInstall mInstance;
501 ExitFunctionInstall(
void) {
509 bool ExitFunctionInstall::mDone=
false;
510 ExitFunctionInstall ExitFunctionInstall::mInstance;
521 std::string filename=rSource;
523 if(filename==
"") filename=
"faudes_dump";
527 std::string::size_type pos=0;
528 for(;pos<filename.length();pos++)
529 if(filename.at(pos)==
'.') filename.at(pos)=
'_';
531 filename.append(
".prot");
535 filename.insert(0,
"tmp_");
561 void TestProtocol(
const std::string& rMessage,
const std::string& rData) {
576 fp.open(prot.c_str(), std::ios::in | std::ios::binary);
584 fr.open(ref.c_str(), std::ios::in | std::ios::binary);
588 fr.open(ref.c_str(), std::ios::in | std::ios::binary);
603 if(fp.eof() && fr.eof()) {
break; }
604 if(!fp.good() || !fr.good()) { dline=cline;
break;}
606 if( cp==
'\r' && cr ==
'\r')
continue;
607 if( cp==
'\r' && fp.eof()){ dline=cline;
break;}
608 if( cp==
'\r') cp = fp.get();
609 if( cr==
'\r' && fr.eof()){ dline=cline;
break;}
610 if( cr==
'\r') cr = fr.get();
612 if( cr==
'\n') cline++;
614 if( cp!= cr ){dline=cline;
break;}
616 }
catch(std::ios::failure&) {
643 throw Exception(
"LoopCallback",
"break on application request", 110);
Classes AttributeVoid and AttributeFlags
#define FAUDES_WRITE_CONSOLE(message)
Debug: output macro for optional redirection of all console output.
#define FD_DF(message)
Debug: optional report on user functions.
Runtime interface, elementary types.
Runtime interface, registry for faudes-types and functions.
Runtime interface, faudes types.
C-level utilities functions.
static ConsoleOut * G(void)
Acess static instance.
ConsoleOut * pInstance
Redirect.
std::ofstream * pStream
Private output stream.
virtual void DoWrite(const std::string &message, long int cntnow=0, long int cntdone=0, int verb=0)
Writing hook.
virtual void Write(const std::string &message, long int cntnow=0, long int cntdone=0, int verb=0)
Write a std::string message (optional progress report and verbosity)
static ConsoleOut * smpInstance
Private static instance.
virtual ~ConsoleOut(void)
Destructor.
const std::string & Filename(void)
Query filename.
ConsoleOut(void)
Constructor.
std::string mFilename
Private record file name.
void Redirect(ConsoleOut *out)
Redirect.
void ToFile(const std::string &filename)
Redirect to file.
static void Inc(const std::string &rTypeName)
static void Dec(const std::string &rTypeName)
static std::map< std::string, long int > * mspCount
static std::map< std::string, long int > * mspMax
A TokenWriter writes sequential tokens to a file, a string or stdout.
std::string FileName(void) const
Get the filename.
void WriteComment(const std::string &rComment)
Write comment in faudes format.
Base class of all libFAUDES objects that participate in the run-time interface.
void Write(const Type *pContext=0) const
Write configuration data to console.
void SWrite(TokenWriter &rTw) const
Write statistics comment to TokenWriter.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
void ProcessDot(const std::string &rDotFile, const std::string &rOutFile, const std::string &rOutFormat, const std::string &rDotExec)
Convenience function: process dot file to graphics output.
std::string VersionString()
Return FAUDES_VERSION as std::string.
std::string ExtractDirectory(const std::string &rFullPath)
Extract directory from (full) path; i.e., remove the last separator and anything thereafer.
void LoopCallback(bool pBreak(void))
std::string PrependPath(const std::string &rLeft, const std::string &rRight)
Prepend one path before another.
std::string ExtractBasename(const std::string &rFullPath)
Extract file basename from full path.
Idx ToIdx(const std::string &rString)
Convert a string to Idx.
TokenWriter * gTestProtocolTw
std::string CreateTempFile(void)
Create a temp file, length 0.
bool FileCopy(const std::string &rFromFile, const std::string &rToFile)
Copy file.
std::string PluginsString()
Return FAUDES_PLUGINS as std::string.
std::string ExpandString(const std::string &rString, unsigned int len)
Fill string with spaces up to a given length if length of the string is smaller than given length par...
static bool(* gBreakFnct)(void)=0
std::string ExtractFilename(const std::string &rFullPath)
Extract file name from full path.
bool FileDelete(const std::string &rFilename)
Delete file.
std::string ToStringFloat(Float number)
float to string
std::string CollapsString(const std::string &rString, unsigned int len)
Limit length of string, return head and tail of string.
std::string ToStringInteger16(Int number)
integer to string base 16
double Float
Type definition for real type.
std::string ExtractSuffix(const std::string &rFullPath)
Extract extension from full path, i.e.
std::string ContributorsString()
Return contributors as std::string.
std::string ToStringInteger(Int number)
integer to string
std::set< std::string > ReadDirectory(const std::string &rDirectory)
Read the contents of the specified directors.
std::string StringSubstitute(const std::string &rString, const std::string &rFrom, const std::string &rTo)
Substitute globally in string.
std::string gTestProtocolFr
bool DirectoryExists(const std::string &rDirectory)
Test existence of directory.
std::string TestProtocol(const std::string &rSource)
Test Protocol.
bool FileExists(const std::string &rFilename)
Test existence of file.
long int Int
Type definition for integer type (let target system decide, minimum 32bit)