diff options
author | Matthew Newhook <matthew@zeroc.com> | 2002-01-23 16:40:37 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2002-01-23 16:40:37 +0000 |
commit | cbddb4bb5eb52699fe267f75032b44c68e2532eb (patch) | |
tree | ab01c420bc5f6c1a9b6fe39817e3717386a44e7e /cpp/src/IceXML/Output.cpp | |
parent | Initial commit of generic marshaling. (diff) | |
download | ice-cbddb4bb5eb52699fe267f75032b44c68e2532eb.tar.bz2 ice-cbddb4bb5eb52699fe267f75032b44c68e2532eb.tar.xz ice-cbddb4bb5eb52699fe267f75032b44c68e2532eb.zip |
added missing files. Renamed XMLStream to StreamI. Renamed XMLOutput to
Output.
Diffstat (limited to 'cpp/src/IceXML/Output.cpp')
-rw-r--r-- | cpp/src/IceXML/Output.cpp | 235 |
1 files changed, 235 insertions, 0 deletions
diff --git a/cpp/src/IceXML/Output.cpp b/cpp/src/IceXML/Output.cpp new file mode 100644 index 00000000000..8646d34fcee --- /dev/null +++ b/cpp/src/IceXML/Output.cpp @@ -0,0 +1,235 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <IceXML/Output.h> + +using namespace std; +using namespace IceXML; + +namespace IceXML +{ + +NextLine nl; +StartBlock sb; +EndBlock eb; +Separator sp; + +} + +// ---------------------------------------------------------------------- +// Output +// ---------------------------------------------------------------------- + +IceXML::Output::Output() : + _out(_fout), + _pos(0), + _indent(0), + _separator(true), + _blockStart("{"), + _blockEnd("}"), + _useTab(true), + _indentSize(4) +{ +} + +IceXML::Output::Output(ostream& os) : + _out(os), + _pos(0), + _indent(0), + _separator(true), + _blockStart("{"), + _blockEnd("}"), + _useTab(true), + _indentSize(4) +{ +} + +IceXML::Output::Output(const char* s) : + _out(_fout), + _pos(0), + _indent(0), + _separator(true), + _blockStart("{"), + _blockEnd("}"), + _useTab(true), + _indentSize(4) +{ + open(s); +} + +void +IceXML::Output::open(const char* s) +{ + _fout.open(s); +} + +void +IceXML::Output::print(const char* s) +{ + for (unsigned int i = 0; i < strlen(s); ++i) + { + if (s[i] == '\n') + { + _pos = 0; + } + else + { + ++_pos; + } + } + + _out << s; +} + +void +IceXML::Output::inc() +{ + _indent += _indentSize; +} + +void +IceXML::Output::dec() +{ + assert(_indent >= _indentSize); + _indent -= _indentSize; +} + +void +IceXML::Output::useCurrentPosAsIndent() +{ + _indentSave.push(_indent); + _indent = _pos; +} + +void +IceXML::Output::zeroIndent() +{ + _indentSave.push(_indent); + _indent = 0; +} + +void +IceXML::Output::restoreIndent() +{ + assert(!_indentSave.empty()); + _indent = _indentSave.top(); + _indentSave.pop(); +} + +void +IceXML::Output::setBeginBlock(const char *bb) +{ + _blockStart = bb; +} + +void +IceXML::Output::setEndBlock(const char *eb) +{ + _blockEnd = eb; +} + +void +IceXML::Output::setIndent(int indentSize) +{ + _indentSize = indentSize; +} + +void +IceXML::Output::setUseTab(bool useTab) +{ + _useTab = useTab; +} + +void +IceXML::Output::nl() +{ + _out << '\n'; + _pos = 0; + _separator = true; + + int indent = _indent; + + if (_useTab) + { + while (indent >= 8) + { + indent -= 8; + _out << '\t'; + _pos += 8; + } + } + else + { + while (indent >= _indentSize) + { + indent -= _indentSize; + _out << " "; + _pos += _indentSize; + } + } + + while (indent > 0) + { + --indent; + _out << ' '; + ++_pos; + } + + _out.flush(); +} + +void +IceXML::Output::sb() +{ + if (_blockStart.length()) + { + nl(); + _out << _blockStart; + } + ++_pos; + inc(); + _separator = false; +} + +void +IceXML::Output::eb() +{ + dec(); + if (_blockEnd.length()) + { + nl(); + _out << _blockEnd; + } + --_pos; +} + +void +IceXML::Output::sp() +{ + if (_separator) + { + _out << '\n'; + } +} + +bool +IceXML::Output::operator!() const +{ + return !_out; +} + +Output& +IceXML::operator<<(Output& out, ios_base& (*val)(ios_base&)) +{ + ostringstream s; + s << val; + out.print(s.str().c_str()); + return out; +} |