00001 00004 const int buffer_length = 9000; 00005 00006 00007 class Is_base : public HandleId 00008 00009 { 00010 protected: 00011 Format_type format; 00012 Format_type last_format; 00013 bool command_warnings; 00014 00015 00016 char buffer [buffer_length]; 00017 00018 public: 00019 Is_base (Format_type format = ASCII); 00020 virtual ~Is_base (); 00021 00022 virtual bool ok() const; 00023 00024 void setFormat (Format_type format = ASCII); 00025 void resetFormat (); 00026 Format_type getFormat () { return format; } 00027 00028 00029 virtual bool get (char* word); 00030 virtual bool get (String& word); 00031 virtual bool get (float& a); 00032 virtual bool get (double& a); 00033 virtual bool get (int& i); 00034 virtual bool get (long int& i); 00035 virtual bool get (char& c); 00036 00037 virtual bool get (char* data, int item_size, int nitems); 00038 00039 00040 00041 real getReal () { real a; get(a); return a; } 00042 int getInt () { int a; get(a); return a; } 00043 00044 virtual void putback (char c); 00045 virtual bool eof (); 00046 00047 00048 virtual void return2start (); 00049 00050 00051 virtual long int getPosition (); 00052 virtual void setPosition (long int filepos); 00053 00054 00055 virtual void ignore (char end); 00056 virtual void getline (String& word, char end); 00057 virtual void getline (char* s, int length, char end); 00058 void getline (char end) { getline(buffer,buffer_length-1,end); } 00059 const char* getBuffer () { return buffer; } 00060 00061 00062 virtual void eat (const char* chars); 00063 00064 void getCommand 00065 ( 00066 String& value, 00067 char eqmark = '=', 00068 char endmark = ' ' 00069 ); 00070 00071 00072 CLASS_INFO 00073 00074 DEF_VIRTUAL_CAST(Is_istream) 00075 DEF_VIRTUAL_CAST(Is_ifstream) 00076 DEF_VIRTUAL_CAST(Is_String) 00077 DEF_VIRTUAL_CAST(Is_xdr) 00078 }; 00079 00080 00285 class Is 00286 00287 { 00288 Handle(Is_base) ptr; 00289 char* buffer; 00290 ifstream* file; 00291 00292 void createFileOrStringIs (const String& s); 00293 00294 public: 00295 Is (); 00296 00297 Is (const char* s); 00298 Is (const String& s); 00299 Is (istream& is); 00300 Is (ifstream& ifs); 00301 Is (const Is& is); 00302 00303 00304 Is (const String& filename, enum FileMode mode); 00305 00306 Is (const String& filename, enum Format_type format, enum FileMode mode, 00307 bool xdr_format = true); 00308 00309 ~Is (); 00310 00311 void rebind (const char* s); 00312 void rebind (const String& s); 00313 void rebind (istream& is); 00314 void rebind (ifstream& ifs); 00315 void rebind (const Is& is); 00316 void rebind (const String& filename, enum FileMode mode); 00317 void rebind (const String& filename, enum Format_type format, 00318 enum FileMode mode, bool xdr_format = true); 00319 00320 void operator = (const Is& is); 00321 00322 void init (); 00323 bool ok () const; 00324 00325 Is_base* operator -> (); 00326 00327 Is_base* getPtr () { return ptr.getPtr(); } 00328 Is_base& getRef () { return ptr.getRef(); } 00329 00330 00331 00332 bool isString (); 00333 String getString (); 00334 00335 friend Is& operator >> (Is& is, double& a); 00336 friend Is& operator >> (Is& is, float& a); 00337 friend Is& operator >> (Is& is, int& i); 00338 friend Is& operator >> (Is& is, long int& i); 00339 friend Is& operator >> (Is& is, char& c); 00340 friend Is& operator >> (Is& is, char* s); 00341 friend Is& operator >> (Is& is, String& s); 00342 00343 friend Is& operator >> (Is& is, const char* s); 00344 }; 00345 00346 00347 bool fileExists (String& filename); 00348 00349 00350 00598 class Os_base : public HandleId 00599 00600 { 00601 public: 00602 static int protection; 00603 00604 protected: 00605 bool closed; 00606 Format_type format; 00607 Format_type last_format; 00608 00609 00610 protected: 00611 String real_format; 00612 String int_format; 00613 String long_format; 00614 String char_format; 00615 String string_format; 00616 int width; 00617 String last_real_format; 00618 String last_int_format; 00619 String last_long_format; 00620 String last_char_format; 00621 String last_string_format; 00622 00623 00624 public: 00625 Os_base (Format_type format = ASCII); 00626 virtual ~Os_base (); 00627 virtual bool ok() const; 00628 00629 void setFormat (Format_type format = ASCII); 00630 void resetFormat (); 00631 Format_type getFormat () { return format; } 00632 00633 void setRealFormat (const String& f); 00634 void resetRealFormat (); 00635 String getRealFormat () { return real_format; } 00636 void setIntFormat (const String& f); 00637 void resetIntFormat (); 00638 String getIntFormat () { return int_format; } 00639 void setLongFormat (const String& f); 00640 void resetLongFormat (); 00641 String getLongFormat () { return long_format; } 00642 void setCharFormat (const String& f); 00643 void resetCharFormat (); 00644 String getCharFormat () { return char_format; } 00645 void setStringFormat (const String& f); 00646 void resetStringFormat (); 00647 String getStringFormat () { return string_format; } 00648 00649 int getFormatWidth (const String& f); 00650 int getFormatWidth (float) { return getFormatWidth (getRealFormat()); } 00651 int getFormatWidth (double) { return getFormatWidth (getRealFormat()); } 00652 int getFormatWidth (Complex&) { return getFormatWidth (getRealFormat()); } 00653 int getFormatWidth (char) { return getFormatWidth (getCharFormat()); } 00654 int getFormatWidth (int) { return getFormatWidth (getIntFormat()); } 00655 int getFormatWidth (long int) { return getFormatWidth (getLongFormat()); } 00656 int getFormatWidth (char*) { return getFormatWidth (getStringFormat()); } 00657 00658 int getNoDecimals (const String& f); 00659 00660 00661 00662 virtual bool put (const char* word); 00663 virtual bool put (const String& word); 00664 virtual bool put (float a); 00665 virtual bool put (double a); 00666 virtual bool put (int i); 00667 virtual bool put (long i); 00668 virtual bool put (char c); 00669 00670 virtual bool put (char* data, int item_size, int nitems); 00671 00672 00673 virtual void flush (); 00674 00675 00676 virtual long getPosition (); 00677 virtual void setPosition (long filepos); 00678 00679 00680 virtual void close (); 00681 00682 00683 CLASS_INFO 00684 00685 DEF_VIRTUAL_CAST(Os_ostream) 00686 DEF_VIRTUAL_CAST(Os_ofstream) 00687 DEF_VIRTUAL_CAST(Os_String) 00688 DEF_VIRTUAL_CAST(Os_xdr) 00689 #if defined(WIN32) && defined(MFCDP_MENUS) 00690 DEF_VIRTUAL_CAST(Os_MFCLog) 00691 #endif 00692 00693 #ifdef DP_MATHEMATICA 00694 DEF_VIRTUAL_CAST(Os_MathLink) 00695 #endif 00696 00697 }; 00698 00699 00944 class Os 00945 00946 { 00947 Handle(Os_base) ptr; 00948 ofstream* file; 00949 00950 void createFileOrStringOs (const String& s); 00951 00952 public: 00953 00954 Os (); 00955 00956 Os (const char* s); 00957 Os (const String& s); 00958 Os (ostream& os); 00959 Os (ofstream& ofs); 00960 Os (const Os& os); 00961 00962 #ifdef DP_MATHEMATICA 00963 Os (const MLINK& link); 00964 #endif 00965 00966 00967 00968 Os (const String& filename, enum FileMode mode); 00969 00970 Os (const String& filename, enum Format_type format, enum FileMode mode, 00971 bool xdr_format = true); 00972 00973 ~Os (); 00974 00975 void rebind (const char* s); 00976 void rebind (const String& s); 00977 void rebind (ostream& os); 00978 void rebind (ofstream& ofs); 00979 void rebind (const Os& os); 00980 void rebind (const String& filename, enum FileMode mode); 00981 void rebind (const String& filename, enum Format_type format, 00982 enum FileMode mode, bool xdr_format = true); 00983 00984 #ifdef DP_MATHEMATICA 00985 void rebind (const MLINK& link); 00986 #endif 00987 00988 #if defined(WIN32) && defined(MFCDP_MENUS) 00989 00990 Os (ostream& os, int dummy); 00991 void rebind (ostream& os, int dummy); 00992 #endif 00993 00994 void operator = (const Os& os); 00995 00996 void init (); 00997 bool ok () const; 00998 00999 Os_base* operator -> (); 01000 01001 Os_base* getPtr () { return ptr.getPtr(); } 01002 Os_base& getRef () { return ptr.getRef(); } 01003 01004 void flush () { ptr->flush(); } 01005 01006 01007 01008 bool isString (); 01009 String getString (); 01010 01011 static void describeFile (const String& filename, const String& description); 01012 01013 friend Os& operator << (Os& os, double a); 01014 friend Os& operator << (Os& os, float a); 01015 friend Os& operator << (Os& os, int i); 01016 friend Os& operator << (Os& os, long int i); 01017 friend Os& operator << (Os& os, char c); 01018 friend Os& operator << (Os& os, const char* s); 01019 friend Os& operator << (Os& os, const String& s); 01020 friend Os& operator << (Os& os, void* v); 01021 friend Os& operator << (Os& os, ostream& (*f (ostream&));) 01022 }; 01023 01024