cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmnGenericObject.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Anton Deguet
7  Created on: 2004-08-18
8 
9  (C) Copyright 2004-2012 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 
27 #pragma once
28 
29 #ifndef _cmnGenericObject_h
30 #define _cmnGenericObject_h
31 
34 #include <cisstCommon/cmnLogger.h>
35 #include <cisstCommon/cmnThrow.h>
36 
37 #include <string>
38 #include <iostream>
39 
40 
41 // Always include last
42 #include <cisstCommon/cmnExport.h>
43 
52 public:
53 
55  virtual ~cmnGenericObject(void) {};
56 
69  virtual const cmnClassServicesBase * Services(void) const = 0;
70 
84  bool ReconstructFrom(const cmnGenericObject & other);
85 
88  std::string ToString(void) const;
89 
92  virtual void ToStream(std::ostream & outputStream) const;
93 
99  virtual void ToStreamRaw(std::ostream & outputStream, const char delimiter = ' ',
100  bool headerOnly = false, const std::string & headerPrefix = "") const;
101 
104  virtual bool FromStreamRaw(std::istream & inputStream, const char delimiter = ' ');
105 
109  virtual void SerializeRaw(std::ostream & outputStream) const;
110 
113  virtual void DeSerializeRaw(std::istream & inputStream);
114 
119  virtual cmnLogger::StreamBufType * GetLogMultiplexer(void) const;
120 
127  virtual size_t ScalarNumber(void) const {
128  return 0;
129  }
130 
136  virtual bool ScalarNumberIsFixed(void) const {
137  return false;
138  }
139 
143  virtual double Scalar(const size_t CMN_UNUSED(index)) const throw (std::out_of_range) {
144  cmnThrow(std::out_of_range("cmnGenericObject::Scalar base method called, no scalar"));
145  return 0.0;
146  }
147 
152  virtual std::string ScalarDescription(const size_t CMN_UNUSED(index), const std::string & CMN_UNUSED(userDescription)) const {
153  cmnThrow(std::out_of_range("cmnGenericObject::ScalarDescription base method called, no scalar"));
154  return "index out of range";
155  }
156 };
157 
158 
160 inline
161 std::ostream & operator << (std::ostream & output,
162  const cmnGenericObject & object) {
163  object.ToStream(output);
164  return output;
165 }
166 
167 
168 // the following header files are usually needed with cmnGenericObject
172 
173 
174 #endif // _cmnGenericObject_h
175 
std::ostream & operator<<(std::ostream &output, const cmnGenericObject &object)
Definition: cmnGenericObject.h:161
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
std::string ToString()
Definition: cisstVectorEigenAddons.h:30
Portability across compilers and operating systems tools.
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
Class registration macros.
virtual bool ScalarNumberIsFixed(void) const
Definition: cmnGenericObject.h:136
Base class for high level objects.
Definition: cmnGenericObject.h:51
virtual double Scalar(const size_t CMN_UNUSED(index)) const
Definition: cmnGenericObject.h:143
Class register definitions and log macros.
Declaration of cmnLogger amd macros for human readable logging.
virtual std::string ScalarDescription(const size_t CMN_UNUSED(index), const std::string &CMN_UNUSED(userDescription)) const
Definition: cmnGenericObject.h:152
Macros to export the symbols of cisstCommon (in a Dll).
virtual size_t ScalarNumber(void) const
Definition: cmnGenericObject.h:127
#define cmnThrow(a)
Definition: MinimalCmn.h:4
Defines cmnClassServices.
Base class for class services.
Definition: cmnClassServicesBase.h:45
Declaration of the template function cmnThrow.
virtual ~cmnGenericObject(void)
Definition: cmnGenericObject.h:55