14 typedef unsigned long long ull;
16 /***********************************************************************/
18 // snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
19 // works for now, but there should be a way to do it without killing the whole program
21 class BadConversion : public runtime_error {
23 BadConversion(const string& s) : runtime_error(s){ }
26 //**********************************************************************************************************************
29 inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
32 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
33 throw BadConversion(s);
36 //**********************************************************************************************************************
39 string toString(const T&x){
45 //**********************************************************************************************************************
48 string toString(const T&x, int i){
58 /***********************************************************************/
60 inline void gobble(ifstream& f){
63 while(isspace(d=f.get())) {;}
68 /***********************************************************************/
70 inline float roundDist(float dist, int precision){
72 return int(dist * precision + 0.5)/float(precision);
76 /***********************************************************************/
78 inline int getNumNames(string names){
84 for(int i=0;i<names.size();i++){
95 /**************************************************************************************************/
97 inline vector<vector<double> > binomial(int maxOrder){
99 vector<vector<double> > binomial(maxOrder+1);
101 for(int i=0;i<=maxOrder;i++){
102 binomial[i].resize(maxOrder+1);
111 for(int i=2;i<=maxOrder;i++){
115 for(int i=2;i<=maxOrder;i++){
116 for(int j=1;j<=maxOrder;j++){
117 if(i==j){ binomial[i][j]=1; }
118 if(j>i) { binomial[i][j]=0; }
119 else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; }
126 /***********************************************************************/
128 inline string getRootName(string longName){
130 string rootName = longName;
132 if(longName.find_last_of(".") != longName.npos){
133 int pos = longName.find_last_of('.')+1;
134 rootName = longName.substr(0, pos);
139 /***********************************************************************/
141 inline string getSimpleName(string longName){
143 string simpleName = longName;
145 if(longName.find_last_of("/") != longName.npos){
146 int pos = longName.find_last_of('/')+1;
147 simpleName = longName.substr(pos, longName.length());
153 /***********************************************************************/
155 inline string getPathName(string longName){
157 string rootPathName = longName;
159 if(longName.find_last_of("/") != longName.npos){
160 int pos = longName.find_last_of('/')+1;
161 rootPathName = longName.substr(0, pos);
167 /***********************************************************************/
169 inline int openInputFile(string fileName, ifstream& fileHandle){
171 fileHandle.open(fileName.c_str());
173 cerr << "Error: Could not open " << fileName << endl;
182 /***********************************************************************/
184 inline int openOutputFile(string fileName, ofstream& fileHandle){
186 fileHandle.open(fileName.c_str(), ios::trunc);
188 cerr << "Error: Could not open " << fileName << endl;
197 /***********************************************************************/