cisst-saw
Loading...
Searching...
No Matches
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 Author(s): Anton Deguet
6 Created on: 2004-08-18
7
8 (C) Copyright 2004-2017 Johns Hopkins University (JHU), All Rights
9 Reserved.
10
11--- begin cisst license - do not edit ---
12
13This software is provided "as is" under an open source license, with
14no warranty. The complete license can be found in license.txt and
15http://www.cisst.org/cisst/license.txt.
16
17--- end cisst license ---
18
19*/
20
21
26#pragma once
27
28#ifndef _cmnGenericObject_h
29#define _cmnGenericObject_h
30
35
36#include <string>
37#include <iostream>
38
39#if CISST_HAS_JSON
40#include <json/json.h>
41#endif // CISST_HAS_JSON
42
43// Always include last
45
54public:
55
57 virtual ~cmnGenericObject(void) {};
58
71 virtual const cmnClassServicesBase * Services(void) const = 0;
72
86 bool ReconstructFrom(const cmnGenericObject & other);
87
90 std::string ToString(void) const;
91
94 virtual void ToStream(std::ostream & outputStream) const;
95
101 virtual void ToStreamRaw(std::ostream & outputStream, const char delimiter = ' ',
102 bool headerOnly = false, const std::string & headerPrefix = "") const;
103
106 virtual bool FromStreamRaw(std::istream & inputStream, const char delimiter = ' ');
107
111 virtual void SerializeRaw(std::ostream & outputStream) const;
112
115 virtual void DeSerializeRaw(std::istream & inputStream);
116
122
126
129 virtual size_t ScalarNumber(void) const {
130 return 0;
131 }
132
138 virtual bool ScalarNumberIsFixed(void) const {
139 return false;
140 }
141
145 virtual double Scalar(const size_t CMN_UNUSED(index)) const CISST_THROW(std::out_of_range) {
146 cmnThrow(std::out_of_range("cmnGenericObject::Scalar base method called, no scalar"));
147 return 0.0;
148 }
149
154 virtual std::string ScalarDescription(const size_t CMN_UNUSED(index), const std::string & CMN_UNUSED(userDescription)) const {
155 cmnThrow(std::out_of_range("cmnGenericObject::ScalarDescription base method called, no scalar"));
156 return "index out of range";
157 }
158
159#if CISST_HAS_JSON
160 virtual void SerializeTextJSON(Json::Value & CMN_UNUSED(jsonValue)) const {};
161 virtual void DeSerializeTextJSON(const Json::Value & CMN_UNUSED(jsonValue))
162 CISST_THROW(std::runtime_error) {};
163#endif // CISST_HAS_JSON
164};
165
166
168inline
169std::ostream & operator << (std::ostream & output,
170 const cmnGenericObject & object) {
171 object.ToStream(output);
172 return output;
173}
174
175
176// the following header files are usually needed with cmnGenericObject
180
181
182#endif // _cmnGenericObject_h
Base class for class services.
Definition cmnClassServicesBase.h:46
Base class for high level objects.
Definition cmnGenericObject.h:53
virtual std::string ScalarDescription(const size_t CMN_UNUSED(index), const std::string &CMN_UNUSED(userDescription)) const
Definition cmnGenericObject.h:154
virtual void DeSerializeRaw(std::istream &inputStream)
virtual double Scalar(const size_t CMN_UNUSED(index)) const CISST_THROW(std
Definition cmnGenericObject.h:145
virtual void ToStreamRaw(std::ostream &outputStream, const char delimiter=' ', bool headerOnly=false, const std::string &headerPrefix="") const
virtual bool FromStreamRaw(std::istream &inputStream, const char delimiter=' ')
bool ReconstructFrom(const cmnGenericObject &other)
virtual size_t ScalarNumber(void) const
Definition cmnGenericObject.h:129
virtual const cmnClassServicesBase * Services(void) const =0
virtual void ToStream(std::ostream &outputStream) const
virtual cmnLogger::StreamBufType * GetLogMultiplexer(void) const
virtual void SerializeRaw(std::ostream &outputStream) const
virtual bool ScalarNumberIsFixed(void) const
Definition cmnGenericObject.h:138
virtual ~cmnGenericObject(void)
Definition cmnGenericObject.h:57
std::string ToString(void) const
cmnLODMultiplexerStreambuf< char > StreamBufType
Definition cmnLogger.h:246
Class register definitions and log macros.
Class registration macros.
Defines cmnClassServices.
Macros to export the symbols of cisstCommon (in a Dll).
#define CISST_EXPORT
Definition cmnExportMacros.h:50
std::ostream & operator<<(std::ostream &output, const cmnGenericObject &object)
Definition cmnGenericObject.h:169
Declaration of cmnLogger amd macros for human readable logging.
Portability across compilers and operating systems tools.
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
Declaration of the template function cmnThrow.
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76