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);
112 std::string res=rString;
113 std::transform(res.begin(), res.end(), res.begin(),
114 [](
unsigned char c){ return std::tolower(c); });
121 std::string
StringSubstitute(
const std::string& rString,
const std::string& rFrom,
const std::string& rTo) {
126 while(pos<rString.length()) {
127 std::size_t next=rString.find(rFrom,pos);
128 if(next==std::string::npos)
break;
129 res.append(rString.substr(pos, next-pos));
131 pos=next+rFrom.length();
134 if(pos<rString.length())
135 res.append(rString.substr(pos));
142 return std::string(FAUDES_VERSION);
147 return std::string(FAUDES_PLUGINS);
153 "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, Changming Yang, Yang Yi, Jorgos Zaddach, Hao Zhou, Christian Zwick, et al";
156 #define XLITSTR(x) LITSTR(x)
162 #ifdef FAUDES_BUILDENV
163 res = res + std::string(
XLITSTR(FAUDES_BUILDENV));
165 res = res + std::string(
"generic");
167 #ifdef FAUDES_BUILDTIME
168 res = res + std::string(
" ") + std::string(
XLITSTR(FAUDES_BUILDTIME));
170 res = res + std::string(
" ") + std::string(FAUDES_CONFIG_TIMESTAMP);
178 const std::string& rOutFile,
const std::string& rOutFormat,
const std::string& rDotExec)
180 std::string format=rOutFormat;
183 if(rOutFile.rfind(
'.')+1 < rOutFile.size()) {
184 format=rOutFile.substr(rOutFile.rfind(
'.')+1);
188 if (format ==
"canon");
189 else if (format ==
"dot");
190 else if (format ==
"xdot");
191 else if (format ==
"cmap");
192 else if (format ==
"dia");
193 else if (format ==
"fig");
194 else if (format ==
"gd");
195 else if (format ==
"gd2");
196 else if (format ==
"gif");
197 else if (format ==
"hpgl");
198 else if (format ==
"imap");
199 else if (format ==
"cmapx");
200 else if (format ==
"ismap");
201 else if (format ==
"jpg");
202 else if (format ==
"jpeg");
203 else if (format ==
"mif");
204 else if (format ==
"mp");
205 else if (format ==
"pcl");
206 else if (format ==
"pic");
207 else if (format ==
"plain");
208 else if (format ==
"plain-ext");
209 else if (format ==
"png");
210 else if (format ==
"ps");
211 else if (format ==
"ps2");
212 else if (format ==
"svg");
213 else if (format ==
"svgz");
214 else if (format ==
"vrml");
215 else if (format ==
"vtx");
216 else if (format ==
"wbmp");
217 else if (format ==
"eps");
218 else if (format ==
"pdf");
220 std::stringstream errstr;
221 errstr <<
"Dot output format \"" << format <<
"\" unknown";
222 throw Exception(
"faudes::ProcessDot", errstr.str(), 3);
224 std::string dotcommand = rDotExec +
" -T"+format+
" \""+rDotFile+
"\" -o \""+rOutFile+
"\"";
225 if(system(dotcommand.c_str()) != 0) {
227 "Error in running " + dotcommand, 3);
235 static bool ready=
false;
236 static bool known=
false;
237 if(known)
return ready;
239 std::string testdot = rDotExec +
" -V";
240 ready = (system(testdot.c_str()) == 0);
249 char filename[]=
"faudes_temp_XXXXXX";
254 filedes= mkstemp(filename);
256 FD_DF(
"faudes::CreateTempFile(): error");
260 res=std::string(filename);
262 #ifdef FAUDES_WINDOWS
278 char* tmpname = _mktemp(filename);
281 FD_DF(
"faudes::CreateTempFile(): error");
284 fopen_s(&file,tmpname,
"w");
286 FD_DF(
"faudes::CreateTempFile(): error");
290 res=std::string(tmpname);
292 FD_DF(
"faudes::CreateTempFile(): " << res);
300 if(seppos==std::string::npos)
return res;
301 res=rFullPath.substr(0,seppos+1);
307 std::string res=rFullPath;
309 if(seppos==std::string::npos)
return res;
310 res=rFullPath.substr(seppos+1);
316 std::string res=rFullPath;
318 if(seppos!=std::string::npos) {
319 res=res.substr(seppos+1);
321 std::size_t dotpos = res.find_last_of(
".");
322 if(dotpos!=std::string::npos) {
323 res=res.substr(0,dotpos);
330 std::string res=rFullPath;
332 if(seppos!=std::string::npos) {
333 res=res.substr(seppos+1);
335 std::size_t dotpos = res.find_last_of(
".");
336 if(dotpos!=std::string::npos)
337 if(dotpos +1 < res.size()) {
338 return res.substr(dotpos+1,res.size()-dotpos-1);
340 return std::string();
344 std::string
PrependPath(
const std::string& rLeft,
const std::string& rRight) {
347 return std::string(rRight);
349 return std::string(rLeft);
355 if(seppos!=std::string::npos)
356 sepchar=rLeft.at(seppos);
358 std::string res=rLeft;
359 if(res.at(res.length()-1)!=sepchar)
360 res.append(1,sepchar);
361 if(rRight.at(0)!=sepchar){
365 if(rRight.length()<=1) {
368 res.append(rRight,1,std::string::npos);
376 thedir=opendir(rDirectory.c_str());
377 if(thedir) closedir(thedir);
380 #ifdef FAUDES_WINDOWS
381 DWORD fattr = GetFileAttributesA(
faudes_extpath(rDirectory).c_str());
383 (fattr!=INVALID_FILE_ATTRIBUTES) && (fattr & FILE_ATTRIBUTE_DIRECTORY);
390 std::set< std::string > res;
393 struct dirent *theent;
394 thedir=opendir(rDirectory.c_str());
395 if(!thedir)
return res;
396 while((theent=readdir(thedir))) {
397 std::string fname(theent->d_name);
398 if(fname==
".")
continue;
399 if(fname==
"..")
continue;
404 #ifdef FAUDES_WINDOWS
406 WIN32_FIND_DATA data;
407 hf = FindFirstFile((rDirectory+
"\\*.*").c_str(), &data);
408 if (hf != INVALID_HANDLE_VALUE) {
410 std::string fname(data.cFileName);
411 if(fname==
".")
continue;
412 if(fname==
"..")
continue;
414 }
while (FindNextFile(hf, &data));
428 fp.open(rFilename.c_str(), std::ios::in | std::ios::binary);
434 return remove(rFilename.c_str()) == 0;
438 bool FileCopy(
const std::string& rFromFile,
const std::string& rToFile) {
439 std::ifstream froms(rFromFile.c_str(), std::ios::binary);
440 std::ofstream tos(rToFile.c_str(), std::ios::binary);
441 tos << froms.rdbuf();
443 return !(froms.fail() || tos.fail());
475 void ConsoleOut::Write(
const std::string& message,
long int cntnow,
long int cntdone,
int verb) {
476 DoWrite(message,cntnow,cntdone,verb);
479 (void) cntnow; (void) cntdone;
480 if(
mVerb<verb)
return;
482 if(!sout) sout=&std::cout;
491 void Print(
int v,
const std::string& message) {
493 std::ostringstream line;
494 line <<
"FAUDES_PRINT: " << message << std::endl;
499 void Print(
const std::string& message) {
517 mspCount=
new std::map<std::string,long int>();
518 mspMax=
new std::map<std::string,long int>();
526 long int cnt = ((*mspCount)[rTypeName]+=1);
531 (*mspCount)[rTypeName]-=1;
537 #ifdef FAUDES_DEBUG_CODE
545 std::map<std::string,long int>::iterator cit;
555 #ifdef FAUDES_DEBUG_CODE
557 class ExitFunctionInstall {
560 static ExitFunctionInstall mInstance;
561 ExitFunctionInstall(
void) {
569 bool ExitFunctionInstall::mDone=
false;
570 ExitFunctionInstall ExitFunctionInstall::mInstance;
581 std::string filename=rSource;
583 if(filename==
"") filename=
"faudes_dump";
587 std::string::size_type pos=0;
588 for(;pos<filename.length();pos++)
589 if(filename.at(pos)==
'.') filename.at(pos)=
'_';
591 filename.append(
".prot");
595 filename.insert(0,
"tmp_");
621 void TestProtocol(
const std::string& rMessage,
const std::string& rData) {
636 fp.open(prot.c_str(), std::ios::in | std::ios::binary);
644 fr.open(ref.c_str(), std::ios::in | std::ios::binary);
648 fr.open(ref.c_str(), std::ios::in | std::ios::binary);
663 if(fp.eof() && fr.eof()) {
break; }
664 if(!fp.good() || !fr.good()) { dline=cline;
break;}
666 if( cp==
'\r' && cr ==
'\r')
continue;
667 if( cp==
'\r' && fp.eof()){ dline=cline;
break;}
668 if( cp==
'\r') cp = fp.get();
669 if( cr==
'\r' && fr.eof()){ dline=cline;
break;}
670 if( cr==
'\r') cr = fr.get();
672 if( cr==
'\n') cline++;
674 if( cp!= cr ){dline=cline;
break;}
676 }
catch(std::ios::failure&) {
703 throw Exception(
"LoopCallback",
"break on application request", 110);
#define FAUDES_WRITE_CONSOLE(message)
static ConsoleOut * G(void)
static ConsoleOut * smpInstance
virtual void DoWrite(const std::string &message, long int cntnow=0, long int cntdone=0, int verb=1)
virtual ~ConsoleOut(void)
const std::string & Filename(void)
virtual void Write(const std::string &message, long int cntnow=0, long int cntdone=0, int verb=1)
void Redirect(ConsoleOut *out)
void ToFile(const std::string &filename)
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
std::string FileName(void) const
void WriteComment(const std::string &rComment)
void Write(const Type *pContext=0) const
void SWrite(TokenWriter &rTw) const
std::string VersionString()
std::string ExtractDirectory(const std::string &rFullPath)
bool DotReady(const std::string &rDotExec)
void LoopCallback(bool pBreak(void))
std::string PrependPath(const std::string &rLeft, const std::string &rRight)
Idx ToIdx(const std::string &rString)
TokenWriter * gTestProtocolTw
void ProcessDot(const std::string &rDotFile, const std::string &rOutFile, const std::string &rOutFormat, const std::string &rDotExec)
std::string CreateTempFile(void)
bool FileCopy(const std::string &rFromFile, const std::string &rToFile)
std::string PluginsString()
std::string ExpandString(const std::string &rString, unsigned int len)
static bool(* gBreakFnct)(void)=0
std::string BuildString()
bool FileDelete(const std::string &rFilename)
std::string ToStringFloat(Float number)
std::string ExtractFilename(const std::string &rFullPath)
std::string ToStringInteger16(Int number)
std::string ContributorsString()
std::string ToStringInteger(Int number)
std::set< std::string > ReadDirectory(const std::string &rDirectory)
std::string StringSubstitute(const std::string &rString, const std::string &rFrom, const std::string &rTo)
std::string ToLowerCase(const std::string &rString)
void Print(int v, const std::string &message)
std::string gTestProtocolFr
std::string ExtractBasename(const std::string &rFullPath)
bool DirectoryExists(const std::string &rDirectory)
std::string TestProtocol(const std::string &rSource)
bool FileExists(const std::string &rFilename)
std::string ExtractSuffix(const std::string &rFullPath)
std::string CollapsString(const std::string &rString, unsigned int len)