Structural deformable models
Macros | Functions
utils.h File Reference
#include <iostream>
#include <sstream>
#include <string>
#include <ctype.h>
#include <assert.h>
#include <sys/time.h>
#include "common.h"
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAKE_STRING(msg)   ( ((std::ostringstream&)(std::ostringstream() << msg)).str() )
 
#define MAKE_CSTRING(msg)   ( ((std::ostringstream&)(std::ostringstream() << msg)).str().c_str() )
 
#define COMMENT_CHAR   '#'
 

Functions

std::istream & comment (std::istream &s)
 
unsigned long getMilliSeconds ()
 
template<class T >
std::string toString (T v)
 
template<class T >
T & fromString (const std::string &str, T &v)
 
std::string & replaceAll (std::string &txt, char src, char tar)
 
int matlabCall (const std::string &cmd)
 
const char * getTemp ()
 
const std::string & __set_fnmatchpattern (const std::string &pattern)
 
int __fixed_fnmatch (const struct dirent *dent)
 
template<class T >
int findFiles (const std::string &fmask, T iter)
 

Macro Definition Documentation

#define COMMENT_CHAR   '#'

Definition at line 23 of file utils.h.

Referenced by comment().

#define MAKE_CSTRING (   msg)    ( ((std::ostringstream&)(std::ostringstream() << msg)).str().c_str() )

Definition at line 20 of file utils.h.

#define MAKE_STRING (   msg)    ( ((std::ostringstream&)(std::ostringstream() << msg)).str() )

Definition at line 18 of file utils.h.

Function Documentation

int __fixed_fnmatch ( const struct dirent *  dent)

Definition at line 12 of file ffind.cpp.

References __fnmatchpattern.

Referenced by __set_fnmatchpattern(), FFind::find(), FFind::findFiles(), and fromString().

12  {
13  return !fnmatch(__fnmatchpattern, dent->d_name,0);
14 }
char __fnmatchpattern[2048]
Definition: ffind.cpp:11
const std::string& __set_fnmatchpattern ( const std::string &  pattern)

Definition at line 15 of file utils.cpp.

References __fixed_fnmatch(), and __fnmatchpattern.

Referenced by FFind::find(), and fromString().

16 { return __fnmatchpattern = pattern; }
static string __fnmatchpattern
Definition: utils.cpp:14
std::istream& comment ( std::istream &  s)
inline

Definition at line 25 of file utils.h.

References COMMENT_CHAR.

26 {
27  char c;
28  while (s.get(c)) {
29  if (!isspace(c)) {
30  if (c == COMMENT_CHAR) {
31  while (s.get(c) && c != '\n');
32  } else {
33  s.putback(c);
34  break;
35  }
36  }
37  }
38  return s;
39 }
#define COMMENT_CHAR
Definition: utils.h:23
template<class T >
int findFiles ( const std::string &  fmask,
iter 
)

Definition at line 88 of file utils.h.

Referenced by fromString().

88  {
89  struct _finddata_t ff;
90  int ffhandle;
91  int ffcount=0;
92  if((ffhandle = _findfirst(fmask.c_str(), &ff)) != -1) {
93  do {
94  *iter++ = ff.name;
95  ffcount++;
96  } while(_findnext(ffhandle, &ff) == 0);
97  }
98  return ffcount;
99 }
template<class T >
T& fromString ( const std::string &  str,
T &  v 
)

Definition at line 67 of file utils.h.

References __fixed_fnmatch(), __set_fnmatchpattern(), findFiles(), getTemp(), matlabCall(), and replaceAll().

Referenced by Brain::doCommand(), MStructure::getRefModelIDs(), MStructure::loadRefProp(), SubStructure::read(), MStructure::read(), and SearcherParams::read().

67  {
68  std::istringstream ss(str);
69  ss >> v;
70  return v;
71 }
unsigned long getMilliSeconds ( )
inline

Definition at line 41 of file utils.h.

Referenced by Brain::run().

41  {
42 #ifdef WIN32
43 // typedef unsigned long LONGLONG;
44 // typedef long LARGE_INTEGER;
45 
46  static LONGLONG frequency=0;
47  if(!frequency)
48  QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
49  LONGLONG counter;
50  QueryPerformanceCounter((LARGE_INTEGER*)&counter);
51  return (unsigned long) (counter*1000 / frequency);
52 #else
53  static struct timeval time;
54  gettimeofday(&time, 0);
55  return (unsigned long)time.tv_sec*1000 + (unsigned long)time.tv_usec/1000;
56 #endif
57 }
const char* getTemp ( )

Definition at line 25 of file utils.cpp.

Referenced by fromString().

26 {
27  const char* tc = getenv("TEMP");
28  if(!tc) tc = getenv("TMP");
29  return tc;
30 }
int matlabCall ( const std::string &  cmd)

Definition at line 7 of file matlab.cpp.

References matlabprog.

Referenced by fromString().

8 {
9  return system((matlabprog+cmd+", exit").c_str());
10 }
static string matlabprog
Definition: matlab.cpp:5
std::string& replaceAll ( std::string &  txt,
char  src,
char  tar 
)

Definition at line 32 of file utils.cpp.

Referenced by fromString().

33 {
34  int pos = 0;
35  while((pos = txt.find(src,pos)) != (int)txt.npos) {
36  txt[pos++] = tar;
37  }
38  return txt;
39 }
template<class T >
std::string toString ( v)

Definition at line 60 of file utils.h.

Referenced by MStructure::buildAllStats(), Brain::doCommand(), MStructure::getRefModel(), MStructure::setRefModel(), MStructure::showStats(), and Brain::triggerTest().

60  {
61  std::stringstream ss;
62  ss << v;
63  return ss.str();
64 }