Source: OmOutputDevice.h


Annotated List
Files
Globals
Hierarchy
Index
#ifndef OM_OUTPUT_DEVICE_H
#define OM_OUTPUT_DEVICE_H

/**
 * Low level output handling for the Standard OpenMath protocol.
 *
 * This class provides a basic light encapsulation of the C library, concerning the output operations.
 * The built-in types in use are strongly compatible with those used in the C library.
 * This layer can be used independently from the object-oriented approach provided by the OmNode hierarchy,
 * and it may be more simple to integrate it in C++ code than directly calling the C library.
 *
 * Any call to writeX() may throw an exception, which should be caught as an OmException & object.
 * All writeX() methods return the current (this) output device.
 */
class OmOutputDevice
{
public:
  /**
   * Write a built-in 32-bits signed integer value.
   */
  virtual OmOutputDevice & writeInteger(int value_in) {
    OmException::checkUnderlying(OMputInt32(device_, value_in));
    return *this; }

  /**
   * Write a big integer number.
   * @li Precondition: ~ NullPointer(digits_in) and ~ EmptyString(digits_in) and ~ UnsupportedBase(base_in)
   */
  virtual OmOutputDevice & writeBigInteger(const char * digits_in, int sign_in, unsigned int base_in) {
    OmException::checkNullPointer(digits_in);
    OmException::checkEmptyString(digits_in);
    OmException::checkUnsupportedBase(base_in);
    OmException::checkUnderlying(OMputBigInt(device_,
					     digits_in,
					     strlen(digits_in),
					     sign_in, base_in==10 ? OMbigIntBase10 : (base_in==16 ? OMbigIntBase16 : OMbigIntUnknown)));
    return *this; }

  /**
   * Write a built-in 64bits float value.
   */
  virtual OmOutputDevice & writeFloat(double value_in) {
    OmException::checkUnderlying(OMputFloat64(device_, &value_in));
    return *this; }

  /**
   * Write a byte array.
   * @li Precondition: ~ NullPointer(buffer_in)
   */
  virtual OmOutputDevice & writeByteArray(const char * buffer_in, unsigned int length_in) {
    OmException::checkNullPointer(buffer_in);
    OmException::checkUnderlying(OMputByteArray(device_, buffer_in, length_in));
    return *this; }

  /**
   * Write a zero-terminated C string of 8 bits characters.
   * @li Precondition: ~ NullPointer(buffer_in) and ~ EmptyString(buffer_in)
   */
  virtual OmOutputDevice & writeString(const char * buffer_in) {
    OmException::checkNullPointer(buffer_in);
    OmException::checkEmptyString(buffer_in);
    OmException::checkUnderlying(OMputString(device_, buffer_in));
    return *this; }

  /**
   * Write a zero-terminated C string of wide characters.
   * @li Precondition: ~ NullPointer(buffer_in) and ~ EmptyString(buffer_in)
   */
  virtual OmOutputDevice & writeWString(const wchar_t * buffer_in) {
    OmException::checkNullPointer(buffer_in);
    OmException::checkEmptyString(buffer_in);
    OmException::checkUnderlying(OMputWCString(device_, (const OMUCS2 *)buffer_in));
    return *this; }

  /**
   * Write a variable as a zero-terminated C string of characters.
   * @li Precondition: ~ NullPointer(name_in) and ~ EmptyString(name_in)
   */
  virtual OmOutputDevice & writeVariable(const char * name_in) {
    OmException::checkNullPointer(name_in);
    OmException::checkEmptyString(name_in);
    OmException::checkUnderlying(OMputVar(device_, name_in));
    return *this; }

  /**
   * Write a symbol as a couple (cd, name) of two zero-terminated strings of characters.
   * @li Precondition: ~ NullPointer(cd_in) and ~ EmptyString(cd_in) and ~ NullPointer(name_in) and ~ EmptyString(name_in)
   */
  virtual OmOutputDevice & writeSymbol(const char * cd_in, const char * name_in) {
    OmException::checkNullPointer(cd_in);
    OmException::checkEmptyString(cd_in);
    OmException::checkNullPointer(name_in);
    OmException::checkEmptyString(name_in);
    OmException::checkUnderlying(OMputSymbol(device_, cd_in, name_in));
    return *this; }

  /**
   * Write an application begin tag.
   */
  virtual OmOutputDevice & writeApplication() {
    OmException::checkUnderlying(OMputApp(device_));
    return *this; }

  /**
   * Write an application end tag.
   */
  virtual OmOutputDevice & writeEndApplication() {
    OmException::checkUnderlying(OMputEndApp(device_));
    return *this; }

  /**
   * Write an attribute begin tag.
   */
  virtual OmOutputDevice & writeAttribute() {
    OmException::checkUnderlying(OMputAttr(device_));
    return *this; }

  /**
   * Write an attribute end tag.
   */
  virtual OmOutputDevice & writeEndAttribute() {
    OmException::checkUnderlying(OMputEndAttr(device_));
    return *this; }

  /**
   * Write an attribute parameter begin tag.
   */
  virtual OmOutputDevice & writeAttributeParameter() {
    OmException::checkUnderlying(OMputAtp(device_));
    return *this; }

  /**
   * Write an attribute parameter end tag.
   */
  virtual OmOutputDevice & writeEndAttributeParameter() {
    OmException::checkUnderlying(OMputEndAtp(device_));
    return *this; }

  /**
   * Write a binding begin tag.
   */
  virtual OmOutputDevice & writeBinding() {
    OmException::checkUnderlying(OMputBind(device_));
    return *this; }

  /**
   * Write a binding end tag.
   */
  virtual OmOutputDevice & writeEndBinding() {
    OmException::checkUnderlying(OMputEndBind(device_));
    return *this; }

  /**
   * Write a binding variable begin tag.
   */
  virtual OmOutputDevice & writeBindingVariable() {
    OmException::checkUnderlying(OMputBVar(device_));
    return *this; }

  /**
   * Write a binding variable end tag.
   */
  virtual OmOutputDevice & writeEndBindingVariable() {
    OmException::checkUnderlying(OMputEndBVar(device_));
    return *this; }

  /**
   * Write an object begin tag.
   */
  virtual OmOutputDevice & writeObject() {
    OmException::checkUnderlying(OMputObject(device_));
    return *this; }

  /**
   * Write an object end tag.
   */
  virtual OmOutputDevice & writeEndObject() {
    OmException::checkUnderlying(OMputEndObject(device_));
    return *this; }

  /**
   * Write an error begin tag.
   */
  virtual OmOutputDevice & writeError() {
    OmException::checkUnderlying(OMputError(device_));
    return *this; }

  /**
   * Write an error end tag.
   */
  virtual OmOutputDevice & writeEndError() {
    OmException::checkUnderlying(OMputEndError(device_));
    return *this; }

  /**
   * Write a processing instruction.
   * @li Precondition: ~ NullPointer(buffer_in)
   */
  virtual OmOutputDevice & writePInstruction(const char * buffer_in) {
    OmException::checkNullPointer(buffer_in);
    OmException::checkUnderlying(OMputPInstruction(device_, buffer_in));
    return *this; }

  /**
   * Write a comment.
   * @li Precondition: ~ NullPointer(buffer_in)
   */
  virtual OmOutputDevice & writeComment(const char * buffer_in) {
    OmException::checkNullPointer(buffer_in);
    OmException::checkUnderlying(OMputComment(device_, buffer_in));
    return *this; }

public:
  /**
   * Constructor. The output stream and the encoding must be given in arguments, they cannot change later.
   * Also it is strongly recommended not to share an output stream with another output device (undefined behavior).
   */
  OmOutputDevice(OmOutputStream & stream_in, OmEncoding encoding_in, bool ignoreComment_in=true) {
    device_ = OMmakeDevice((OMencodingType)encoding_in, stream_in.getIO());
    OMignoreComment(device_, ignoreComment_in);
    OMsetVerbosityLevel(0); }

  /**
   * Destructor.
   */
  virtual ~OmOutputDevice() {
    OMcloseDevice(device_); }

  /**
   * Get the encoding.
   */
  virtual OmEncoding getEncoding() const {
    return OmEncoding(OMgetDeviceEncoding(device_)); }

private:
  OmOutputDevice(const OmOutputDevice &) {}
  void operator =(const OmOutputDevice &) {}
  
private:
  OMdev device_;
};

#endif // OM_OUTPUT_DEVICE_H

Generated by: root@localhost.localdomain on Tue Oct 12 21:02:30 199.