misc.cpp
Go to the documentation of this file.
1 /* $Id: misc.cpp 3675 2010-09-12 05:36:34Z kmartin $ */
17 //#include <cppad/cppad.hpp>
18 #include "OSConfig.h"
19 #include "OSCoinSolver.h"
20 #include "OSIpoptSolver.h"
21 #include "OSResult.h"
22 #include "OSiLReader.h"
23 #include "OSiLWriter.h"
24 #include "OSrLReader.h"
25 #include "OSrLWriter.h"
26 #include "OSInstance.h"
27 #include "OSFileUtil.h"
28 #include "OSDefaultSolver.h"
29 #include "OShL.h"
30 #include "OSErrorClass.h"
31 #include "OSmps2osil.h"
32 #include "OSBase64.h"
33 #include "OSCommonUtil.h"
34 #include "OSErrorClass.h"
35 #include "OSMathUtil.h"
36 #include "CoinFinite.hpp"
37 
38 #include<iostream>
39 #include <ostream>
40 #include <sstream>
41 #include <streambuf>
42 
43 #include<stdio.h>
44 
45 using std::cout;
46 using std::endl;
47 
53 int main(int argC, char* argV[]){
57  FileUtil *fileUtil = NULL;
58  fileUtil = new FileUtil();
59  cout << "Start Building the Model" << endl;
60  std::cout << "Hello World" << std::endl;
61 
62  std::string osilFileName = "../../data/osilFiles/rosenbrockmod.osil";
63  std::cout << "Try to read a sample file" << std::endl;
64  std::cout << "The file is: " ;
65  std::cout << osilFileName << std::endl;
66  std::string osil = fileUtil->getFileAsString( osilFileName.c_str() );
67  OSiLReader *osilreader = NULL;
68  osilreader = new OSiLReader();
70  osinstance = osilreader->readOSiL( osil);
71  std::string theModel;
72 
73 
74  #if 0
75  //WRITE STDOUT TO A FILE -- C LEVEL stuff
76  //http://bytes.com/groups/cpp/133393-usage-rdbuf
77  ostringstream solverOutput;
78  FILE * pFile;
79  FILE * pFile2;
80  pFile2 = freopen("os.log", "w", stdout);
81  //if (pFile==NULL) throw ErrorClass ("Error opening file for stdout");
82  std::cout << "LINE 1 OUTPUT " << std::endl; //cout will get diverted
83  printf("LINE 2 OUTPUT \n"); // printf will get diverted
84  fclose( pFile2);
85  pFile = fopen("os.log", "r");
86  char c;
87  while (!feof( stdout)) {
88  c = fgetc (stdout);
89  if(c !=-1) solverOutput << c;
90  }
91  fileUtil->writeFileFromString("kipp.txt", solverOutput.str() );
92  #endif
93 
94  #if 1
95  //WRITE COUT TO A STRING -- this C++ stuff -- it will NOT write stdout, e.g. printf()
96  ostringstream solverOutput;
97  std::streambuf* save_buffer = cout.rdbuf(solverOutput.rdbuf()); //turn off cout
98  std::cout << "LINE 1 OUTPUT " << std::endl ; //this should get diverted
99  printf("LINE 2 OUTPUT \n") ; //this will not get diverted
100  cout.rdbuf(save_buffer); // turn cout back on
101  std::cout << "LINE 3 OUTPUT " << std::endl;
102  // now the string
103  std::cout << solverOutput.str() << std::endl;
104  #endif
105 
106  //DEMO -- how to empty the string buffer
107  ostringstream outStr;
108  outStr << "Hello";
109  outStr << " World" ;
110  outStr << std::endl;
111  std::cout << outStr.str() << std::endl;
112  outStr.str(""); // here is where we empty the buffer
113  outStr << "New" << std::endl;
114  std::cout << outStr.str() << std::endl;
115 
116 
117  delete fileUtil;
118  fileUtil = NULL;
119  return 0;
120 }// end main
121 
bool writeFileFromString(char *fname, std::string thestring)
write a file from an input string.
Definition: OSFileUtil.cpp:116
int main(int argc, char *argv[])
Definition: BB_tm.cpp:32
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
Definition: OSiLReader.cpp:53
Used to read an OSiL string.
Definition: OSiLReader.h:37
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
Definition: OSFileUtil.cpp:35
The in-memory representation of an OSiL instance..
Definition: OSInstance.h:2262
OSInstance * osinstance
class used to make it easy to read and write files.
Definition: OSFileUtil.h:37
real c