1: 2: 3: /************* 4: * * 5: * SENTINEL * 6: * * 7: *************/ 8: 9: 10: #ifndef WWWI_MIND_FORMAT_H 11: #define WWWI_MIND_FORMAT_H 12: 13: 14: /********************** 15: * * 16: * COMPILER INCLUDES * 17: * * 18: **********************/ 19: 20: 21: #include <sstream> 22: 23: 24: /********************* 25: * * 26: * PROJECT INCLUDES * 27: * * 28: *********************/ 29: 30: 31: using std::stringstream; 32: using std::string; 33: 34: 35: /***************** 36: * * 37: * CLASS FORMAT * 38: * * 39: *****************/ 40: 41: /* 42: * The format class takes a series of as arguments to its constructor 43: * and has a cast to const char *. This means you can use it in a function call 44: * that takes a const char * parameter and the string will be valid for the life 45: * of the call (and no longer). I split this into two classes to avoid any 46: * surprise implicit casts. 47: * 48: * For Example: 49: * 50: * throw tantrum(FOUT("Couldn't alloc ",iBytes," bytes at ",__FILE__,__LINE__)); 51: * 52: * WARNING: Use of these classes is an evil act and may cause your alignment 53: * to shift. 54: * 55: */ 56: 57: class FIN { 58: public: 59: FIN(void) { m_bValid = false; }; 60: template <class T> FIN(const T &ci_tr) { 61: stringstream ss; 62: ss << ci_tr; 63: m_xtr = ss.str(); 64: m_bValid = true; 65: }; 66: inline bool GetValid(void) const { return m_bValid; } 67: inline const char *Out(void) const { return m_xtr.c_str(); } 68: 69: protected: 70: bool m_bValid; 71: string m_xtr; 72: }; 73: 74: static FIN NOFIN; 75: 76: class FOUT { 77: public: 78: FOUT(const FIN &ci_fm1 = NOFIN, 79: const FIN &cm_fm2 = NOFIN, 80: const FIN &cm_fm3 = NOFIN, 81: const FIN &cm_fm4 = NOFIN, 82: const FIN &cm_fm5 = NOFIN, 83: const FIN &cm_fm6 = NOFIN, 84: const FIN &cm_fm7 = NOFIN, 85: const FIN &cm_fm8 = NOFIN, 86: const FIN &cm_fm9 = NOFIN, 87: const FIN &cm_fm10 = NOFIN); 88: operator const char *(void) const { return m_xtr.c_str(); }; 89: 90: protected: 91: string m_xtr; 92: }; 93: 94: 95: /************ 96: * * 97: * THE END * 98: * * 99: ************/ 100: 101: 102: #endif 103: 104: 105: