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);
257 return std::remove(rFileName.c_str()) == 0;
265 if(seppos==std::string::npos)
return res;
266 res=rFullPath.substr(0,seppos+1);
272 std::string res=rFullPath;
274 if(seppos==std::string::npos)
return res;
275 res=rFullPath.substr(seppos+1);
281 std::string res=rFullPath;
283 if(seppos!=std::string::npos) {
284 res=res.substr(seppos+1);
286 std::size_t dotpos = res.find_last_of(
".");
287 if(dotpos!=std::string::npos) {
288 res=res.substr(0,dotpos);
295 std::string res=rFullPath;
297 if(seppos!=std::string::npos) {
298 res=res.substr(seppos+1);
300 std::size_t dotpos = res.find_last_of(
".");
301 if(dotpos!=std::string::npos)
302 if(dotpos +1 < res.size()) {
303 return res.substr(dotpos+1,res.size()-dotpos-1);
305 return std::string();
309 std::string
PrependDirectory(
const std::string& rDirectory,
const std::string& rFileName) {
310 std::string res=rDirectory;
313 if(res.at(res.length()-1)!=sepchar)
314 res.append(1,sepchar);
315 res.append(rFileName);
323 thedir=opendir(rDirectory.c_str());
324 if(thedir) closedir(thedir);
327 #ifdef FAUDES_WINDOWS
328 DWORD fattr = GetFileAttributesA(rDirectory.c_str());
330 (fattr!=INVALID_FILE_ATTRIBUTES) && (fattr & FILE_ATTRIBUTE_DIRECTORY);
337 std::set< std::string > res;
340 struct dirent *theent;
341 thedir=opendir(rDirectory.c_str());
342 if(!thedir)
return res;
343 while((theent=readdir(thedir))) {
344 std::string fname(theent->d_name);
345 if(fname==
".")
continue;
346 if(fname==
"..")
continue;
351 #ifdef FAUDES_WINDOWS
353 WIN32_FIND_DATA data;
354 hf = FindFirstFile((rDirectory+
"\\*.*").c_str(), &data);
355 if (hf != INVALID_HANDLE_VALUE) {
357 std::string fname(data.cFileName);
358 if(fname==
".")
continue;
359 if(fname==
"..")
continue;
361 }
while (FindNextFile(hf, &data));
375 fp.open(rFilename.c_str(), std::ios::in | std::ios::binary);
381 return remove(rFilename.c_str()) == 0;
385 bool FileCopy(
const std::string& rFromFile,
const std::string& rToFile) {
386 std::ifstream froms(rFromFile.c_str(), std::ios::binary);
387 std::ofstream tos(rToFile.c_str(), std::ios::binary);
388 tos << froms.rdbuf();
390 return !(froms.fail() || tos.fail());
422 void ConsoleOut::Write(
const std::string& message,
long int cntnow,
long int cntdone,
int verb) {
424 if(
mVerb<verb)
return;
425 DoWrite(message,cntnow,cntdone,verb);
428 (void) cntnow; (void) cntdone; (void) verb;
430 if(!sout) sout=&std::cout;
445 mspCount=
new std::map<std::string,long int>();
446 mspMax=
new std::map<std::string,long int>();
454 long int cnt = ((*mspCount)[rTypeName]+=1);
459 (*mspCount)[rTypeName]-=1;
465 #ifdef FAUDES_DEBUG_CODE
473 std::map<std::string,long int>::iterator cit;
483 #ifdef FAUDES_DEBUG_CODE
485 class ExitFunctionInstall {
488 static ExitFunctionInstall mInstance;
489 ExitFunctionInstall(
void) {
497 bool ExitFunctionInstall::mDone=
false;
498 ExitFunctionInstall ExitFunctionInstall::mInstance;
509 std::string filename=rSource;
511 if(filename==
"") filename=
"faudes_dump";
515 std::string::size_type pos=0;
516 for(;pos<filename.length();pos++)
517 if(filename.at(pos)==
'.') filename.at(pos)=
'_';
519 filename.append(
".prot");
523 filename.insert(0,
"tmp_");
549 void TestProtocol(
const std::string& rMessage,
const std::string& rData) {
564 fp.open(prot.c_str(), std::ios::in | std::ios::binary);
572 fr.open(ref.c_str(), std::ios::in | std::ios::binary);
576 fr.open(ref.c_str(), std::ios::in | std::ios::binary);
591 if(fp.eof() && fr.eof()) {
break; }
592 if(!fp.good() || !fr.good()) { dline=cline;
break;}
594 if( cp==
'\r' && cr ==
'\r')
continue;
595 if( cp==
'\r' && fp.eof()){ dline=cline;
break;}
596 if( cp==
'\r') cp = fp.get();
597 if( cr==
'\r' && fr.eof()){ dline=cline;
break;}
598 if( cr==
'\r') cr = fr.get();
600 if( cr==
'\n') cline++;
602 if( cp!= cr ){dline=cline;
break;}
604 }
catch(std::ios::failure&) {
631 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.
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.
bool RemoveFile(const std::string &rFileName)
Delete a file.
void LoopCallback(bool pBreak(void))
std::string ExtractExtension(const std::string &rFullPath)
Extract file name from full path.
std::string ExtractBasename(const std::string &rFullPath)
Extract file name 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...
std::string PrependDirectory(const std::string &rDirectory, const std::string &rFileName)
Construct full path from directory and filename.
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 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 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)