xlat-i/xi-util.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * $Source: /cvsroot/charm/src/xlat-i/xi-util.h,v $
00003  * $Author: gioachin $
00004  * $Date: 2008-06-11 02:37:36 $
00005  * $Revision: 1.19 $
00006  *****************************************************************************/
00007 
00008 #ifndef _XI_UTIL_H
00009 #define _XI_UTIL_H
00010 
00011 #include <string.h>
00012 #include <stdlib.h>
00013 #include <stdio.h>
00014 #include "conv-config.h"
00015 
00016 #if CMK_STL_USE_DOT_H /* Pre-standard C++ */
00017 #  include <iostream.h>
00018 #else /* ISO C++ */
00019 #  include <iostream>
00020    using namespace std;
00021 #endif
00022 
00023 
00024 #define SZ 1024
00025 
00026 class XStr {
00027   private:
00028     char *s;
00029     unsigned int len, blklen;
00030     void initTo(const char *_s);
00031     void operator=(const XStr &str); //<- don't use this
00032   public:
00033     // MAB: following append methods were earlier private. However,
00034     // in order to minimize changes to sdag translator, they have been made
00035     // public. Once the sdag translator is fully embedded in charmxi,
00036     // they will be made private again.
00037     void append(const char *_s);
00038     void append(char c);
00039     // MAB: the print method is needed for debugging sdag translator.
00040     // this too will go away later.
00041     void print(int indent) { 
00042       for (int i=0; i<indent; i++) cout << "  ";
00043       cout << get_string();
00044     }
00045     // MAB: this method appends character c to every line
00046     // basically substitutes every \n with a "c\n"
00047     void line_append(const char c);
00048     // Replace all occurences of character "a" in string with character "b"
00049     void replace (const char a, const char b);
00050   public:
00051     XStr();
00052     XStr(const char *_s);
00053     XStr(const XStr &_s); //Copy constructor
00054     ~XStr() { delete[] s; }
00055     char *get_string(void) { return s; }
00056     const char *get_string_const(void) const { return s; }
00057     // this is to allow XStr to be substituted for CString in
00058     // structured dagger translator without a lot of changes
00059     char *charstar(void) { return get_string(); }
00060     //This operator allows us to use XStr's interchangably with char *'s:
00061     operator char *() {return get_string();}
00062     //Comparison operators
00063     int operator==(XStr &s2) const {return 0==strcmp(s,s2.s);}
00064     int operator!=(XStr &s2) const {return 0!=strcmp(s,s2.s);}
00065     int operator==(const char *s2) const {return 0==strcmp(s,s2);}
00066     int operator!=(const char *s2) const {return 0!=strcmp(s,s2);}
00067     //Addition operator
00068     XStr operator+ (const XStr &s2) const {XStr ret(*this);ret.append(s2.s); return ret;}
00069     //Insertion operators
00070     XStr& operator << (const char *_s) { append(_s); return *this;}
00071 //      XStr& operator << (const string & _s) { append(_s.c_str()); return *this;}
00072     XStr& operator << (char c) { append(c); return *this;}
00073     XStr& operator << (int i) ;
00074     XStr& operator << (const XStr& x) { append(x.get_string_const()); return *this; }
00075     void spew(const char*b, const char *a1 = 0, const char *a2 = 0, 
00076               const char *a3 = 0, const char *a4 = 0, const char *a5 = 0);
00077 };
00078 
00079 #define endx "\n"
00080 
00081 class Printable {
00082   public:
00083     virtual void print(XStr& str) = 0;
00084     //This lets us cast printables to XStr
00085     operator XStr () {XStr ret;print(ret);return ret;}
00086     //These let us stream Printables to XStr.
00087     friend XStr & operator << (XStr &str,Printable &p) {p.print(str);return str;}
00088     friend XStr & operator << (XStr &str,Printable *p) {p->print(str);return str;}
00089 };
00090 
00091 #endif

Generated on Sun Jun 29 13:29:27 2008 for Charm++ by  doxygen 1.5.1