diff options
author | Marc Laukien <marc@zeroc.com> | 2001-06-20 17:44:57 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-06-20 17:44:57 +0000 |
commit | 9ca70e09a26818c757fca4d3bd6bc8ab41e47aee (patch) | |
tree | bcd207e23a0ba9e64bd80fa2198bd46a1f998b53 /cpp/src/Slice/OutputUtil.h | |
parent | fix (diff) | |
download | ice-9ca70e09a26818c757fca4d3bd6bc8ab41e47aee.tar.bz2 ice-9ca70e09a26818c757fca4d3bd6bc8ab41e47aee.tar.xz ice-9ca70e09a26818c757fca4d3bd6bc8ab41e47aee.zip |
slice
Diffstat (limited to 'cpp/src/Slice/OutputUtil.h')
-rw-r--r-- | cpp/src/Slice/OutputUtil.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/cpp/src/Slice/OutputUtil.h b/cpp/src/Slice/OutputUtil.h new file mode 100644 index 00000000000..52250c2ecee --- /dev/null +++ b/cpp/src/Slice/OutputUtil.h @@ -0,0 +1,83 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef OUTPUT_UTIL_H +#define OUTPUT_UTIL_H + +#include <fstream> +#include <sstream> + +namespace IceLang +{ + +class NextLine { }; +class StartBlock { }; +class EndBlock { }; +class Separator { }; + +extern NextLine nl; +extern StartBlock sb; +extern EndBlock eb; +extern Separator sp; + +// ---------------------------------------------------------------------- +// Indent +// ---------------------------------------------------------------------- + +class Output : ::__Ice::noncopyable +{ +public: + + Output(); + + void open(const char*); // Open output stream + + void print(const char*); // Print a string + + void inc(); // Increment indentation level + void dec(); // Decrement indentation level + + void useCurrentPosAsIndent(); // Save the current position as indentation + void zeroIndent(); // Use zero identation + void restoreIndent(); // Restore indentation + + void nl(); // Print newline + void sb(); // Start a block + void eb(); // End a block + void sp(); // Print separator + + bool operator!() const; // Check whether the output state is ok + +private: + + std::ofstream out_; + int pos_; + int indent_; + int indentSave_; + bool separator_; +}; + +template<typename T> +Output& operator<<(Output& out, const T& val) +{ + std::ostringstream s; + s << val; + out.print(s.str().c_str()); + return out; +} + +Output& operator<<(Output&, const NextLine&); +Output& operator<<(Output&, const StartBlock&); +Output& operator<<(Output&, const EndBlock&); +Output& operator<<(Output&, const Separator&); + +} + +#endif |