00001 00002 /* 00003 | Author: Michael Schmidt; 00004 | Gunnar Jehl 00005 | 00006 | ************************* SOFTWARE LICENSE AGREEMENT *********************** 00007 | This source code is published under the BSD License. 00008 | 00009 | See file 'LICENSE.txt' that comes with this distribution or 00010 | http://dbis.informatik.uni-freiburg.de/index.php?project=GCX/license.php 00011 | for the full license agreement. 00012 | 00013 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00014 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00015 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00016 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00017 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00018 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00019 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00020 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00021 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00022 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00023 | POSSIBILITY OF SUCH DAMAGE. 00024 | **************************************************************************** 00025 */ 00026 00035 #ifndef OUTPUTSTREAM_H 00036 #define OUTPUTSTREAM_H 00037 00038 #include <sstream> 00039 #include <iostream> 00040 #include "typeenums.h" 00041 #include "expression.h" 00042 #include "role.h" 00043 #include "pathstepattribute.h" 00044 #include "pathstepexpression.h" 00045 #include "iostreamexception.h" 00046 00047 #if defined(LINUX) || defined(linux) || defined(_LINUX) || defined(_linux) || defined(__LINUX__) || defined(__linux__) 00048 00053 #define NEWLINE "\n" 00054 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__) 00055 00060 #define NEWLINE "\n" 00061 #else 00062 00067 #define NEWLINE "\n" 00068 #endif 00069 00074 #define INDENT_TOKEN " " 00075 00080 #define INDENT_MULTIPLICATOR 2 00081 00086 #define INDENT_SINGLE 1 00087 00092 #define INDENT_DOUBLE 2 00093 00095 using namespace std; 00096 00105 class OutputStream { 00106 00107 public: 00113 OutputStream(OSTREAM_TYPE _type, const char *_arg); 00114 00118 virtual ~ OutputStream(); 00119 00126 virtual void open() = 0; 00127 00133 virtual void close() = 0; 00134 00141 inline void decrementIndents(int n = INDENT_SINGLE) { 00142 indents = ((indents - n) > 0) ? (indents - n) : 0; 00143 } inline void incrementIndents(int n = INDENT_SINGLE) { 00150 indents = indents + n; 00151 } 00152 00158 inline void resetIndents() { 00159 indents = 0; 00160 } 00161 00168 virtual void writeIndents(); 00169 00176 virtual void write(const char *str) = 0; 00177 00184 virtual void writeln(const char *str) = 0; 00185 00192 virtual bool isWriteable() = 0; 00193 00199 virtual void flush() = 0; 00200 00206 inline const OSTREAM_TYPE getType() { 00207 return type; 00208 } 00209 00215 inline const char *getArg() { 00216 return arg; 00217 } 00218 00219 private: 00224 int indents; 00225 00226 protected: 00231 OSTREAM_TYPE type; 00232 00237 const char *arg; 00238 }; 00239 00247 inline OutputStream & operator<<(OutputStream & out, const char *str) { 00248 out.write(str); 00249 return out; 00250 } 00251 00259 inline OutputStream & operator<<(OutputStream & out, const long double i) { 00260 std::ostringstream o; 00261 o << i; 00262 out.write(o.str().c_str()); 00263 return out; 00264 } 00265 00273 inline OutputStream & operator<<(OutputStream & out, const Expression & exp) { 00274 exp.print(out); 00275 return out; 00276 } 00277 00285 inline OutputStream & operator<<(OutputStream & out, 00286 const PathStepAttribute & pstepattr) { 00287 pstepattr.print(out); 00288 return out; 00289 } 00290 00298 inline OutputStream & operator<<(OutputStream & out, const Role & role) { 00299 role.print(out); 00300 return out; 00301 } 00302 00303 #endif // OUTPUTSTREAM_H