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, 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 char filename[]=
"faudes_temp_XXXXXX";
240 filedes= mkstemp(filename);
242 FD_DF(
"faudes::CreateTempFile(): error");
246 res=std::string(filename);
248 #ifdef FAUDES_WINDOWS
264 char* tmpname = _mktemp(filename);
267 FD_DF(
"faudes::CreateTempFile(): error");
270 fopen_s(&file,tmpname,
"w");
272 FD_DF(
"faudes::CreateTempFile(): error");
276 res=std::string(tmpname);
278 FD_DF(
"faudes::CreateTempFile(): " << res);
286 if(seppos==std::string::npos)
return res;
287 res=rFullPath.substr(0,seppos+1);
293 std::string res=rFullPath;
295 if(seppos==std::string::npos)
return res;
296 res=rFullPath.substr(seppos+1);
302 std::string res=rFullPath;
304 if(seppos!=std::string::npos) {
305 res=res.substr(seppos+1);
307 std::size_t dotpos = res.find_last_of(
".");
308 if(dotpos!=std::string::npos) {
309 res=res.substr(0,dotpos);
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 if(dotpos +1 < res.size()) {
324 return res.substr(dotpos+1,res.size()-dotpos-1);
326 return std::string();
330 std::string
PrependPath(
const std::string& rLeft,
const std::string& rRight) {
333 return std::string(rRight);
335 return std::string(rLeft);
341 if(seppos!=std::string::npos)
342 sepchar=rLeft.at(seppos);
344 std::string res=rLeft;
345 if(res.at(res.length()-1)!=sepchar)
346 res.append(1,sepchar);
347 if(rRight.at(0)!=sepchar){
351 if(rRight.length()<=1) {
354 res.append(rRight,1,std::string::npos);
362 thedir=opendir(rDirectory.c_str());
363 if(thedir) closedir(thedir);
366 #ifdef FAUDES_WINDOWS
367 DWORD fattr = GetFileAttributesA(
faudes_extpath(rDirectory).c_str());
369 (fattr!=INVALID_FILE_ATTRIBUTES) && (fattr & FILE_ATTRIBUTE_DIRECTORY);
376 std::set< std::string > res;
379 struct dirent *theent;
380 thedir=opendir(rDirectory.c_str());
381 if(!thedir)
return res;
382 while((theent=readdir(thedir))) {
383 std::string fname(theent->d_name);
384 if(fname==
".")
continue;
385 if(fname==
"..")
continue;
390 #ifdef FAUDES_WINDOWS
392 WIN32_FIND_DATA data;
393 hf = FindFirstFile((rDirectory+
"\\*.*").c_str(), &data);
394 if (hf != INVALID_HANDLE_VALUE) {
396 std::string fname(data.cFileName);
397 if(fname==
".")
continue;
398 if(fname==
"..")
continue;
400 }
while (FindNextFile(hf, &data));
414 fp.open(rFilename.c_str(), std::ios::in | std::ios::binary);
420 return remove(rFilename.c_str()) == 0;
424 bool FileCopy(
const std::string& rFromFile,
const std::string& rToFile) {
425 std::ifstream froms(rFromFile.c_str(), std::ios::binary);
426 std::ofstream tos(rToFile.c_str(), std::ios::binary);
427 tos << froms.rdbuf();
429 return !(froms.fail() || tos.fail());
461 void ConsoleOut::Write(
const std::string& message,
long int cntnow,
long int cntdone,
int verb) {
462 DoWrite(message,cntnow,cntdone,verb);
465 (void) cntnow; (void) cntdone;
466 if(
mVerb<verb)
return;
468 if(!sout) sout=&std::cout;
477 void Print(
int v,
const std::string& message) {
479 std::ostringstream line;
480 line <<
"FAUDES_PRINT: " << message << std::endl;
485 void Print(
const std::string& message) {
503 mspCount=
new std::map<std::string,long int>();
504 mspMax=
new std::map<std::string,long int>();
512 long int cnt = ((*mspCount)[rTypeName]+=1);
517 (*mspCount)[rTypeName]-=1;
523 #ifdef FAUDES_DEBUG_CODE
531 std::map<std::string,long int>::iterator cit;
541 #ifdef FAUDES_DEBUG_CODE
543 class ExitFunctionInstall {
546 static ExitFunctionInstall mInstance;
547 ExitFunctionInstall(
void) {
555 bool ExitFunctionInstall::mDone=
false;
556 ExitFunctionInstall ExitFunctionInstall::mInstance;
567 std::string filename=rSource;
569 if(filename==
"") filename=
"faudes_dump";
573 std::string::size_type pos=0;
574 for(;pos<filename.length();pos++)
575 if(filename.at(pos)==
'.') filename.at(pos)=
'_';
577 filename.append(
".prot");
581 filename.insert(0,
"tmp_");
607 void TestProtocol(
const std::string& rMessage,
const std::string& rData) {
622 fp.open(prot.c_str(), std::ios::in | std::ios::binary);
630 fr.open(ref.c_str(), std::ios::in | std::ios::binary);
634 fr.open(ref.c_str(), std::ios::in | std::ios::binary);
649 if(fp.eof() && fr.eof()) {
break; }
650 if(!fp.good() || !fr.good()) { dline=cline;
break;}
652 if( cp==
'\r' && cr ==
'\r')
continue;
653 if( cp==
'\r' && fp.eof()){ dline=cline;
break;}
654 if( cp==
'\r') cp = fp.get();
655 if( cr==
'\r' && fr.eof()){ dline=cline;
break;}
656 if( cr==
'\r') cr = fr.get();
658 if( cr==
'\n') cline++;
660 if( cp!= cr ){dline=cline;
break;}
662 }
catch(std::ios::failure&) {
689 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)
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)