My Project
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
45using std::cout;
46using std::endl;
47
53int 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();
69 OSInstance *osinstance;
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
class used to make it easy to read and write files.
Definition OSFileUtil.h:38
bool writeFileFromString(char *fname, std::string thestring)
write a file from an input string.
std::string getFileAsString(const char *fname)
read a file and return contents as a string.
The in-memory representation of an OSiL instance..
Used to read an OSiL string.
Definition OSiLReader.h:38
OSInstance * readOSiL(const std::string &osil)
parse the OSiL model instance.
int main(int argC, char *argV[])
this is demo code – illustrate things that I may wish to use
Definition misc.cpp:53