Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
The input/output of ELM is a merge of the C++ standard library system and of the Java standard library. From the former, it uses the "<<" and ">>" operators overload. From the latter, it implements the two IO access: low-level classes manage streams of bytes and the high-level provides formatting facilities. More...
Classes | |
class | ANSIManager |
class | BlockInStream |
class | BlockOutStream |
class | InFileStream |
class | Input |
class | StringInput |
class | FileInput |
class | InStream |
class | IOException |
class | Monitor |
class | OutFileStreal |
class | Output |
class | IntFormat |
class | StringFormat |
class | Tag< P > |
class | FloatFormat |
class | Printable< T, M > |
class | StringOutput |
class | FileOutput |
class | OutStream |
class | StreamPipe |
class | TeeOutStream |
Functions | |
IntFormat | pointer (const void *p) |
IntFormat | byte (t::uint8 b) |
io::Output | cout (buf_out) |
io::Output | cerr (buf_err) |
StringInput | read (const char *s) |
FileInput | read (sys::Path path) |
FileOutput | write (sys::Path path) |
FileOutput | append (sys::Path path) |
IntFormat | base (int base, IntFormat fmt) |
IntFormat | bin (IntFormat fmt) |
IntFormat | hex (IntFormat fmt) |
IntFormat | width (int width, IntFormat fmt) |
IntFormat | align (alignment_t align, IntFormat fmt) |
IntFormat | left (IntFormat fmt) |
IntFormat | right (IntFormat fmt) |
IntFormat | center (IntFormat fmt) |
IntFormat | pad (char pad, IntFormat fmt) |
IntFormat | uppercase (IntFormat fmt) |
IntFormat | lowercase (IntFormat fmt) |
IntFormat | fmt (t::int8 i) |
IntFormat | fmt (t::uint8 i) |
IntFormat | fmt (t::int16 i) |
IntFormat | fmt (t::uint16 i) |
IntFormat | fmt (t::int32 i) |
IntFormat | fmt (t::uint32 i) |
IntFormat | fmt (t::int64 i) |
IntFormat | fmt (t::uint64 i) |
template<class T , class M > | |
Printable< T, M > | p (const T &data, const M &man) |
Variables | |
io::Input | cin |
const EOL | endl |
FloatFormat | percent = FloatFormat().width(5, 2).decimal().right() |
io::Output | cout |
io::Output | cerr |
sys::SystemInStream & | in = sys::stdin_object |
sys::SystemOutStream & | out = sys::stdout_object |
sys::SystemOutStream & | err = sys::stderr_object |
The input/output of ELM is a merge of the C++ standard library system and of the Java standard library. From the former, it uses the "<<" and ">>" operators overload. From the latter, it implements the two IO access: low-level classes manage streams of bytes and the high-level provides formatting facilities.
This level provides formatted input/output as in C++ standard library, that is, through the "<<" and ">>" operators. The formatted output class is Output and the formatted input class is Input.
Three global variables give access to the standard input/output:
Most basic types are supported (including String and CString). Some constants are provided for special output:
Unlike the C++ standard library, the output format is managed through special formatting objects. For integer, the work is performed by IntFormat that provides display features like representation base, field width, alignment, uppercase letters for base greater than 10, signess, padding. For float values, it exists the class FloatFormat and for strings, StringFormat can be used.
This format objects may easily be built using io::fmt() primitives and using internal constructors as in the example below:
A format can be built and used latter:
The errors are managed here using exception objects derived from the IOException class.
As with streams of the STL, the operators "<<" and ">>" can be overload to be adapted to custom types:
To group together input, output and error stream, the Monitor class provides the base of a configurable monitoring system with error and warning display support.
The class IntFormat embeds the value of an integer and its format configuration. These objects are usually passed to Output object and is built from a list of usual inline functions (described below):
The basic to display a formatted integer is to use a constructor inline function as io::fmt(). This builds an IntFormat object to display the passed integer. The format can then be modified by calling specific functions as listed below:
One way to implement the pointer of the above example is to define an inline function as this:
Notice the function io::f() that is a shortcut to create an IntFormat object.
Another way to define this format is to declare an IntFormat variable and to benefit from the overlaod of operator() of this class to pass the actual value to the format:
A last facility to specialize the way a data is formatted is the use of Tag class. This template class takes a class as parameter that will be called to perform the actual display. Using tags, it is possible to specialize the display of particular object inside the usual flow of "<<" operators. The example below displays a string escaping the special characters "<", ">" and "&" in order, for example, to output HTML text:
ELM proposes some predefined formats:
On OS's supporting them (Linux and MacOSX), ANSI codes allows to change the look of displayed text. ANSI codes are supported by io::Output class and can be used if the header file <elm/io/ansi.h> is include. The look change is implemented by sending special values to the output.
The text color can be changed using io::BLACK, io::RED, io::GREEN, io::YELLOW, io::BLUE, io::MAGENTA, io::CYAN or io::WHITE. Bright colors equivalent colors exists and are name by prefixing the color with "BRIGHT_": io::BRIGHT_XXX. Background color can also be customize by prefixing the color name with "BACK_": io::BACK_XXX.
Style of the characters can also be changed by displaying special values as io::BOLD, io::ITALIC, io::UNDERLINE, io::BLINK, ... To reset the display of the characters, one can use the value io::PLAIN.
The low-level IO system is only responsible for exchanging streams of bytes.
All input streams must inherit from the InStream class and defines the following functions:
The errors are returned by the called functions. Either a positive value, or a value of InStream::FAILED (error on the media), or InStream::ENDED (end of the media reached). Information about the errors may be obtained by the InStream::lastErrorMessage() method.
All output streams must inherit from the OutStream class and defines the following functions:
The errors are returned as negative value by this functions. Information about the errors may be obtained by the OutStream::lastErrorMessage() method.
Byte-stream level of IO provides also some convenient classes:
Some classes provides shortcut to perform input / output on files or on strings:
The class io::Tag can be used to display an object in a different as usual (that is not using the default overload of operator <<). This class takes a class P as generic parameter that must implement a static print function. It will be called with, as parameters, the output to use and the object to display.
The example below display integers in a special way, surrounded by "!". The display is handled by the class SpecInt. A tag for SpecInt is defined using a typedef and the integer is display in this special way using the tag type SPEC_INT.
The class io::Printable and the function io::p() allows to perform a display requiring a third-party object (often called a manager). This means that the third-party object must define a function named print() and taking as parameter the object to display and the output.
In the example below, there is a special manager named IntManager that provides some integers as text. The print() function of this class is invoked using the function io::p().
The list printer can be used to display easily and conveniently a list of values inside an output << operator sequence. The class ListPrinter records the list and the separator. The display of the resulting object can be displayed directly using operator <<. A faster way to do this is to use the function io::list() as in the example below:
The output will be:
|
inline |
#include <include/elm/io/Output.h>
Used the given alignment to display the integer in its field.
align | Alignment. |
fmt | Displayed integer. |
References IntFormat::align(), and elm::io::fmt().
Referenced by Debug::debugPrefixWrapped().
|
inline |
#include <include/elm/io/io.h>
Shortcut to append an output to a file.
p | Path to the file to append to. @raise io::IOException If the file cannot be opened. |
Referenced by FileOutput::FileOutput().
#include <include/elm/io/Output.h>
Format an integer with the given base.
base | Numeric base. |
fmt | Displayed integer. |
References IntFormat::base(), and elm::io::fmt().
Referenced by make::extend(), elm::serial2::operator&(), elm::serial2::operator<<(), elm::serial2::operator>>(), Path::relativeTo(), Input::scanLLong(), Input::scanLong(), Input::scanULLong(), Input::scanULong(), and elm::io::test_base().
#include <include/elm/io/Output.h>
Used a binary base to display an integer.
fmt | Displayed integer. |
References IntFormat::bin(), and elm::io::fmt().
#include <include/elm/io/Output.h>
Format an integer to display it as an hexadecimal byte.
b | Byte to format. |
References elm::io::fmt(), IntFormat::hex(), IntFormat::pad(), IntFormat::right(), and IntFormat::width().
Referenced by OutStream::write(), VarExpander::write(), and BufferedOutStream::write().
#include <include/elm/io/Output.h>
Center the integer in its field.
fmt | Displayed integer. |
References IntFormat::center(), and elm::io::fmt().
io::Output elm::cerr | ( | buf_err | ) |
#include <src/system_SystemIO.cpp>
Standard error output.
io::Output elm::cout | ( | buf_out | ) |
#include <src/system_SystemIO.cpp>
Standard output.
#include <include/elm/io/Output.h>
Build a formatted signed 16-bit integer.
#include <include/elm/io/Output.h>
Build a formatted signed 32-bit integer.
#include <include/elm/io/Output.h>
Build a formatted signed 64-bit integer.
#include <include/elm/io/Output.h>
Build a formatted signed 8-bit integer.
Referenced by elm::io::align(), elm::io::base(), elm::io::bin(), elm::io::byte(), elm::io::center(), Output::format(), elm::io::hex(), elm::io::left(), elm::io::lowercase(), elm::io::oct(), elm::io::pad(), elm::io::pointer(), Output::print(), elm::io::right(), elm::io::sign(), elm::io::uppercase(), and elm::io::width().
#include <include/elm/io/Output.h>
Build a formatted unsigned 16-bit integer.
#include <include/elm/io/Output.h>
Build a formatted unsigned 32-bit integer.
#include <include/elm/io/Output.h>
Build a formatted unsigned 64-bit integer.
#include <include/elm/io/Output.h>
Build a formatted unsigned 8-bit integer.
#include <include/elm/io/Output.h>
Used an hexadecimal base to display an integer.
fmt | Displayed integer. |
References elm::io::fmt(), and IntFormat::hex().
Referenced by WAHVector::__dump(), GroupedGC::mark(), SimpleGC::mark(), and MD5::print().
#include <include/elm/io/Output.h>
Align the integer to the left in its field.
fmt | Displayed integer. |
References elm::io::fmt(), and IntFormat::left().
Referenced by Tree::Node::_left(), GenTree< T, K, C, A >::VisitStack::copyLeft(), and TreeBag< value_t, AssocComparator< K, T, Comparator< K > > >::remove().
#include <include/elm/io/Output.h>
Select lowercase characters for digits bigger than 10.
fmt | Displayed integer. |
References elm::io::fmt(), and IntFormat::lower().
|
inline |
#include <include/elm/io/Output.h>
Fast building of a managed printable. Look to Printable for more details.
data | Data to print. |
man | Manager of the data. |
Referenced by inst< T >::_free(), CleanList::add(), ListGC::allocate(), ListGC::block_t::block(), ListGC::clean(), HashTable< Pair< const void *, bool >, AssocHashKey< const void *, bool, HashKey< const void * > >, DefaultAlloc >::copy(), Buffer::copyFrom(), Buffer::copyTo(), elm::count(), BlockAllocatorWithGC< node_t >::destroy(), Path::PathIter::ended(), Path::PathIter::equals(), String::escape(), elm::sys::evaluate(), GenTree< T, IdAdapter< T >, elm::Comparator< T > >::exchange(), elm::exists(), elm::find(), Vector< elm::dtd::AbstractAttribute * >::find(), GenTree< T, IdAdapter< T >, elm::Comparator< T > >::find(), elm::forall(), DefaultAllocatorDelegate::free(), AllocatorDelegate< A >::free(), EquivManager< T >::free(), BlockAllocator< T >::free(), CompareManager< T, C, E, A >::free(), HashManager< K, H, A >::free(), BinomialQueue< T, C, A >::get(), HashMap< elm::CString, void * >::get(), Map< Pair< K, K >, T, segment_comparator_t >::get(), Section::getList(), HashKey< Pair< T1, T2 > >::hash(), elm::hash_jenkins(), elm::hash_ptr(), Map< Pair< K, K >, T, segment_comparator_t >::hasKey(), CString::indexOf(), String::indexOf(), Vector< elm::dtd::AbstractAttribute * >::indexOf(), Plugger::isPlugged(), Path::PathIter::item(), CString::lastIndexOf(), String::lastIndexOf(), Vector< elm::dtd::AbstractAttribute * >::lastIndexOf(), File::load(), GenTree< T, IdAdapter< T >, elm::Comparator< T > >::lookup(), Builder< K, T, Comparator< K > >::make(), SegmentBuilder< K, T, C >::make(), GroupedGC::mark(), SimpleGC::mark(), elm::mismatch(), Path::PathIter::next(), Bag< T >::operator delete(), SharedPtr< T >::operator!=(), elm::operator<<(), elm::io::operator<<(), LockPtr< elm::sys::FileItem >::operator=(), SharedPtr< T >::operator=(), RefPair< T1, T2 >::operator=(), SharedPtr< T >::operator==(), elm::operator>>(), IntFormat::pad(), FloatFormat::pad(), StringFormat::pad(), Manager::parse(), elm::io::pointer(), Output::print(), elm::product(), HashMap< elm::CString, void * >::putAll(), Parser::recordID(), Parser::recordPatch(), AbstractTree::remove(), HashTable< Pair< const void *, bool >, AssocHashKey< const void *, bool, HashKey< const void * > >, DefaultAlloc >::remove(), GenTree< T, IdAdapter< T >, elm::Comparator< T > >::remove(), String::replace(), ListGC::runGC(), elm::select(), elm::select_iter(), InstanceType::typeFor(), elm::unique(), and VarExpander::write().
#include <include/elm/io/Output.h>
Select the padding character.
pad | Padding character. |
fmt | Displayed integer. |
References elm::io::fmt(), and IntFormat::pad().
Referenced by MD5::print().
#include <include/elm/io/Output.h>
Format a pointer for display.
p | Pointer to format. |
References elm::io::fmt(), IntFormat::hex(), elm::io::p(), IntFormat::pad(), and IntFormat::width().
Referenced by Method0< T, C >::Method0(), Method0Const< T, C >::Method0Const(), Method1< T, C, T1 >::Method1(), Method1Const< T, C, T1 >::Method1Const(), Method2< T, C, T1, T2 >::Method2(), and Method2Const< T, C, T1, T2 >::Method2Const().
|
inline |
#include <include/elm/io/io.h>
Shortcut to perform an input from a string.
s | String to use as input. |
#include <include/elm/io/io.h>
Shortcut to perform an input from a file.
p | Path to the file to read from. @raise io::IOException If the file cannot be opened. |
Referenced by UnixInStream::read(), elm::xom::read_callback(), Saver::setReadable(), and Input::swallow().
#include <include/elm/io/Output.h>
Align the integer to the right in its field.
fmt | Displayed integer. |
References elm::io::fmt(), and IntFormat::right().
Referenced by Tree::Node::_right(), GenTree< T, K, C, A >::VisitStack::copyRight(), Tree< K, T, C >::find(), MD5::print(), and TreeBag< value_t, AssocComparator< K, T, Comparator< K > > >::remove().
#include <include/elm/io/Output.h>
Select uppercase characters for digits bigger than 10.
fmt | Displayed integer. |
References elm::io::fmt(), and IntFormat::upper().
#include <include/elm/io/Output.h>
Select the width of field where the integer will be displayed to.
width | Field width. |
fmt | Displayed integer. |
References elm::io::fmt(), and IntFormat::width().
Referenced by Debug::debugPrefixWrapped(), and MD5::print().
|
inline |
#include <include/elm/io/io.h>
Shortcut to perform an output to a file.
p | Path to the file to write to. @raise io::IOException If the file cannot be created. |
Referenced by UnixOutStream::write().
io::Output cerr(buf_err) |
#include <include/elm/io/io.h>
Standard error output.
Referenced by Manager::displayHelp(), elm::elm_spy(), GroupedGC::endGC(), Tuple1< T, A >::make(), Manager::manage(), ErrorHandler::onError(), Plugger::onError(), Plugger::onWarning(), ProcessBuilder::run(), and elm::trace().
io::Input cin |
#include <include/elm/io/io.h>
Formatted input.
io::Output cout(buf_out) |
#include <include/elm/io/io.h>
Standard output.
Referenced by GroupedGC::allocate(), XOMElementSerializer::beginObject(), TestCase::check_equal(), TestCase::complete(), Manager::displayVersion(), GroupedGC::doGC(), elm::avl::dump(), TestCase::failed(), GroupedGC::mark(), TestCase::prepare(), TestCase::require(), ProcessBuilder::run(), TestCase::succeeded(), and TestCase::test().
const EOL endl |
#include <include/elm/io/Output.h>
Displaying this object causes a newline display and a flush.
Referenced by GroupedGC::allocate(), TestCase::complete(), Manager::displayHelp(), Manager::displayVersion(), GroupedGC::doGC(), elm::avl::dump(), elm::elm_spy(), GroupedGC::endGC(), Monitor::error(), TestCase::failed(), Monitor::info(), Tuple1< T, A >::make(), Manager::manage(), GroupedGC::mark(), ErrorHandler::onError(), Plugger::onError(), Plugger::onWarning(), TestCase::prepare(), TestCase::require(), ProcessBuilder::run(), TestCase::succeeded(), and Monitor::warn().
sys::SystemOutStream & err = sys::stderr_object |
#include <include/elm/sys/SystemIO.h>
Standard error stream.
Referenced by SystemException::error(), Plugger::getLastError(), Plugger::lastError(), Plugger::plugFile(), ProcessBuilder::run(), and WinOutStream::write().
sys::SystemInStream & in = sys::stdin_object |
#include <include/elm/sys/SystemIO.h>
Standard input stream.
Referenced by ProcessBuilder::run(), Input::def_scanner< T >::scan(), and Input::enum_scanner< T >::scan().
sys::SystemOutStream & out = sys::stdout_object |
#include <include/elm/sys/SystemIO.h>
Standard output stream.
Referenced by ListPrinter< T >::asis(), elm::operator<<(), elm::io::operator<<(), ANSIManager::print(), def_printer< T >::print(), enum_printer< T >::print(), Tag< P >::print(), ListPrinter< T >::print(), ProcessBuilder::run(), and WinOutStream::write().
FloatFormat percent = FloatFormat().width(5, 2).decimal().right() |
#include <include/elm/io/Output.h>
Float format to display a percentage.