[seiscomp, scanloc] Install, add .gitignore
This commit is contained in:
589
include/seiscomp/core/archive.h
Normal file
589
include/seiscomp/core/archive.h
Normal file
@ -0,0 +1,589 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_ARCHIVE_H
|
||||
#define SEISCOMP_CORE_ARCHIVE_H
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <complex>
|
||||
#include <time.h>
|
||||
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/defs.h>
|
||||
#include <seiscomp/core/optional.h>
|
||||
#include <seiscomp/core/factory.h>
|
||||
#include <seiscomp/core/serialization.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/core/version.h>
|
||||
|
||||
|
||||
#define DECLARE_ROOT_SERIALIZATION(RootClass) \
|
||||
public: \
|
||||
typedef Seiscomp::Core::Generic::Archive<RootClass> Archive; \
|
||||
virtual void serialize(Archive&) {}
|
||||
|
||||
#define DECLARE_SERIALIZATION \
|
||||
public: \
|
||||
virtual void serialize(Archive& ar) override
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
namespace Generic {
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief A template archive interface
|
||||
|
||||
An archive offers an interface to read from and write to datasources.
|
||||
*/
|
||||
template <typename ROOT_TYPE>
|
||||
class Archive {
|
||||
// ------------------------------------------------------------------
|
||||
// Traits
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
typedef ROOT_TYPE RootType;
|
||||
typedef boost::variant<int, double, std::string> PropertyValue;
|
||||
typedef std::map<std::string, PropertyValue> Properties;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public Types
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Serialization hints
|
||||
enum {
|
||||
NONE = 0,
|
||||
STATIC_TYPE = 0x01,
|
||||
//! Objects should not serialize their child elements
|
||||
IGNORE_CHILDS = 0x02,
|
||||
//! Objects are stored as XML nodes not as XML attributes
|
||||
XML_ELEMENT = 0x04,
|
||||
//! Objects are stored as XML cdata not as XML attributes
|
||||
XML_CDATA = 0x08,
|
||||
//! This attribute is mandatory even if empty
|
||||
XML_MANDATORY = 0x10,
|
||||
//! Objects are stored in a seperate database table and
|
||||
//! not in columns of the parent object table
|
||||
DB_TABLE = 0x20,
|
||||
//! The time is stored in two records: time and microseconds
|
||||
SPLIT_TIME = 0x40,
|
||||
//! This is just an informational flag used for database
|
||||
//! access mostly. This flag is the only one that will
|
||||
//! be kept alive when serializing child objects.
|
||||
INDEX_ATTRIBUTE = 0x80
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Constructor
|
||||
Archive();
|
||||
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~Archive() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static int PackVersion(int major, int minor) { return major << 16 | (minor & 0xFFFF); }
|
||||
|
||||
/** Opens an archive.
|
||||
Every archive class interpretes the dataSource parameter
|
||||
in its own way. It can either point to a named dataSource (file)
|
||||
or to a block of memory containing the actual archive data.
|
||||
*/
|
||||
virtual bool open(const char* dataSource);
|
||||
|
||||
//! Creates a new archive
|
||||
virtual bool create(const char* dataSource);
|
||||
|
||||
virtual void close() = 0;
|
||||
|
||||
/**
|
||||
* @brief Sets strict reading mode. In strict mode optional attributes
|
||||
* must be parsed correctly otherwise the archive is not valid.
|
||||
* If strict mode is disabled then invalid optional attributes
|
||||
* or objects are set to None or nullptr.
|
||||
* @param strict Enabled or disabled
|
||||
*/
|
||||
void setStrictMode(bool strict);
|
||||
bool isStrictMode() const;
|
||||
|
||||
//! Queries whether the archive is in reading mode or not
|
||||
bool isReading() const;
|
||||
|
||||
//! Returns whether the last operation was successfull or not
|
||||
bool success() const;
|
||||
|
||||
//! Returns the serialization hints to propose a special
|
||||
//! behaviour to serializable objects.
|
||||
int hint() const;
|
||||
|
||||
//! Sets the current serialization hint
|
||||
void setHint(int);
|
||||
|
||||
//! Sets the validity during serialization if needed
|
||||
void setValidity(bool);
|
||||
|
||||
void setVersion(Version v) { _version = v; }
|
||||
Version version() const { return _version; }
|
||||
|
||||
int versionMajor() const { return _version.majorTag(); }
|
||||
int versionMinor() const { return _version.minorTag(); }
|
||||
|
||||
template <int major, int minor>
|
||||
bool isLowerVersion() const {
|
||||
return _version.majorMinor() < VersionPacker<major,minor,0>::Value;
|
||||
}
|
||||
|
||||
template <int major, int minor>
|
||||
bool isVersion() const {
|
||||
return _version.majorMinor() == VersionPacker<major,minor,0>::Value;
|
||||
}
|
||||
|
||||
template <int major, int minor>
|
||||
bool isHigherVersion() const {
|
||||
return _version.majorMinor() > VersionPacker<major,minor,0>::Value;
|
||||
}
|
||||
|
||||
template <int major, int minor>
|
||||
bool supportsVersion() const {
|
||||
return _version.majorMinor() >= VersionPacker<major,minor,0>::Value;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Property interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the number of user set properties
|
||||
size_t propertyCount() const;
|
||||
|
||||
//! Sets a value for the named property. If the property does not
|
||||
//! yet exist, it will be added and false will be returned. If
|
||||
//! the property exists already, true is returned. The value is
|
||||
//! updated in both cases.
|
||||
bool setProperty(const char *name, const PropertyValue &v);
|
||||
|
||||
//! Returns a property (if set) or nullptr pointer given a property
|
||||
//! name.
|
||||
const PropertyValue *property(const char *name) const;
|
||||
|
||||
const int *propertyInt(const char *name) const;
|
||||
const double *propertyDouble(const char *name) const;
|
||||
const std::string *propertyString(const char *name) const;
|
||||
|
||||
//! Removes all set properties
|
||||
void clearProperties();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Read methods
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Reads an integer
|
||||
virtual void read(std::int8_t &value) = 0;
|
||||
virtual void read(std::int16_t &value) = 0;
|
||||
virtual void read(std::int32_t &value) = 0;
|
||||
virtual void read(std::int64_t &value) = 0;
|
||||
|
||||
//! Reads a float
|
||||
virtual void read(float &value) = 0;
|
||||
//! Reads a double
|
||||
virtual void read(double &value) = 0;
|
||||
//! Reads a float complex
|
||||
virtual void read(std::complex<float> &value) = 0;
|
||||
//! Reads a double complex
|
||||
virtual void read(std::complex<double> &value) = 0;
|
||||
//! Reads a boolean
|
||||
virtual void read(bool &value) = 0;
|
||||
|
||||
//! Reads a vector of chars
|
||||
virtual void read(std::vector<char> &value) = 0;
|
||||
|
||||
//! Reads a vector of ints
|
||||
virtual void read(std::vector<std::int8_t> &value) = 0;
|
||||
virtual void read(std::vector<std::int16_t> &value) = 0;
|
||||
virtual void read(std::vector<std::int32_t> &value) = 0;
|
||||
virtual void read(std::vector<std::int64_t> &value) = 0;
|
||||
|
||||
//! Reads a vector of floats
|
||||
virtual void read(std::vector<float> &value) = 0;
|
||||
|
||||
//! Reads a vector of doubles
|
||||
virtual void read(std::vector<double> &value) = 0;
|
||||
|
||||
//! Reads a vector of complex doubles
|
||||
virtual void read(std::vector<std::complex<double> > &value) = 0;
|
||||
|
||||
//! Reads a vector of strings
|
||||
virtual void read(std::vector<std::string> &value) = 0;
|
||||
|
||||
//! Reads a vector of time
|
||||
virtual void read(std::vector<Time> &value) = 0;
|
||||
|
||||
//! Reads a string
|
||||
virtual void read(std::string &value) = 0;
|
||||
|
||||
//! Reads a time
|
||||
virtual void read(Time &value) = 0;
|
||||
|
||||
template <typename T>
|
||||
void read(T &object);
|
||||
|
||||
void read(ROOT_TYPE &object);
|
||||
|
||||
//! Reads a generic pointer.
|
||||
//! When the referenced type is not registered, nothing will be
|
||||
//! done at all.
|
||||
//! Reading pointer to non class types (int, float, ...) implies
|
||||
//! compiler errors.
|
||||
template <typename T>
|
||||
void read(T *&object);
|
||||
|
||||
template <typename T>
|
||||
void read(::boost::intrusive_ptr<T> &object);
|
||||
|
||||
template <typename T>
|
||||
void read(::boost::optional<T> &object);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Write methods
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Writes an integer
|
||||
virtual void write(std::int8_t value) = 0;
|
||||
virtual void write(std::int16_t value) = 0;
|
||||
virtual void write(std::int32_t value) = 0;
|
||||
virtual void write(std::int64_t value) = 0;
|
||||
|
||||
//! Writes a float
|
||||
virtual void write(float value) = 0;
|
||||
//! Writes a double
|
||||
virtual void write(double value) = 0;
|
||||
//! Writes a float complex
|
||||
virtual void write(std::complex<float> &value) = 0;
|
||||
//! Writes a double complex
|
||||
virtual void write(std::complex<double> &value) = 0;
|
||||
//! Writes a boolean
|
||||
virtual void write(bool value) = 0;
|
||||
|
||||
//! Writes a vector of chars
|
||||
virtual void write(std::vector<char> &value) = 0;
|
||||
|
||||
//! Writes a vector of ints
|
||||
virtual void write(std::vector<std::int8_t> &value) = 0;
|
||||
virtual void write(std::vector<std::int16_t> &value) = 0;
|
||||
virtual void write(std::vector<std::int32_t> &value) = 0;
|
||||
virtual void write(std::vector<std::int64_t> &value) = 0;
|
||||
|
||||
//! Writes a vector of floats
|
||||
virtual void write(std::vector<float> &value) = 0;
|
||||
|
||||
//! Writes a vector of doubles
|
||||
virtual void write(std::vector<double> &value) = 0;
|
||||
|
||||
//! Writes a vector of complex doubles
|
||||
virtual void write(std::vector<std::complex<double> > &value) = 0;
|
||||
|
||||
//! Writes a vector of strings
|
||||
virtual void write(std::vector<std::string> &value) = 0;
|
||||
|
||||
//! Writes a string
|
||||
virtual void write(std::string &value) = 0;
|
||||
|
||||
//! Reads a vector of time
|
||||
virtual void write(std::vector<Time> &value) = 0;
|
||||
|
||||
//! Writes a time
|
||||
virtual void write(Seiscomp::Core::Time &value) = 0;
|
||||
|
||||
//! Writes an object
|
||||
template <typename T>
|
||||
void write(T &object);
|
||||
|
||||
void write(ROOT_TYPE &object);
|
||||
|
||||
//! Entry method for writing object pointers
|
||||
template <typename T>
|
||||
void write(T*);
|
||||
|
||||
template <typename T>
|
||||
void write(::boost::intrusive_ptr<T>&);
|
||||
|
||||
template <typename T>
|
||||
void write(::boost::optional<T>&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Writes a C pointer into the archive
|
||||
template <typename T>
|
||||
Archive& operator<<(T*&);
|
||||
|
||||
//! Writes a smartpointer into the archive
|
||||
template <typename T>
|
||||
Archive& operator<<(::boost::intrusive_ptr<T>&);
|
||||
|
||||
//! Writes a named object into the archive
|
||||
template <typename T>
|
||||
Archive& operator<<(const ObjectNamer<T>&);
|
||||
|
||||
/**
|
||||
\brief Why did you implement different versions for each generic
|
||||
\brief container type instead of using a template template
|
||||
\brief parameter?
|
||||
|
||||
To support container serialization, each container has to be
|
||||
implemented in an own overloaded version, because Microsoft
|
||||
Visual Studio lacks template type parameter deduction for this
|
||||
kind of declaration:
|
||||
|
||||
template <template <typename> class CONTAINER, typename T>
|
||||
Archive& operator<<(const ObjectNamer<CONTAINER<T> >&);
|
||||
|
||||
To support this compiler as well, different operators for each
|
||||
supported container type have been implemented.
|
||||
*/
|
||||
|
||||
//! Writes a named vector into the archive
|
||||
template <typename T>
|
||||
Archive& operator<<(const ObjectNamer<std::vector<T> >&);
|
||||
|
||||
//! Writes a named list into the archive
|
||||
template <typename T>
|
||||
Archive& operator<<(const ObjectNamer<std::list<T> >&);
|
||||
|
||||
//! Reads a C pointer from the archive
|
||||
template <typename T>
|
||||
Archive& operator>>(T*&);
|
||||
|
||||
//! Reads a smartpointer pointer from the archive
|
||||
template <typename T>
|
||||
Archive& operator>>(::boost::intrusive_ptr<T>&);
|
||||
|
||||
//! Reads an object sequence from the archive.
|
||||
template <typename T>
|
||||
Archive& operator>>(const ObjectIterator<T>&);
|
||||
|
||||
//! Reads a named object from the archive.
|
||||
//! The object name will no be read but used for locating
|
||||
//! the data in the archive.
|
||||
template <typename T>
|
||||
Archive& operator>>(const ObjectNamer<T>&);
|
||||
|
||||
//! Reads a vector from the archive
|
||||
template <typename T>
|
||||
Archive& operator>>(const ObjectNamer<std::vector<T> >&);
|
||||
|
||||
//! Reads a list from the archive
|
||||
template <typename T>
|
||||
Archive& operator>>(const ObjectNamer<std::list<T> >&);
|
||||
|
||||
//! Stream operator that decides by means of the _isReading flag
|
||||
//! whether a the object has to be written or to be read.
|
||||
template <typename T>
|
||||
Archive& operator&(ObjectNamer<T>);
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
struct SerializeDispatcher {
|
||||
virtual ~SerializeDispatcher() {}
|
||||
virtual void operator()(Archive&) = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct TypedSerializeDispatcher : SerializeDispatcher {
|
||||
TypedSerializeDispatcher(T* t = nullptr) : target(t) {}
|
||||
|
||||
TypedSerializeDispatcher& operator=(T* t) {
|
||||
target = t;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TypedSerializeDispatcher* operator->() { return this; }
|
||||
|
||||
virtual void operator()(Archive<ROOT_TYPE>& ar) {
|
||||
target->serialize(ar);
|
||||
}
|
||||
|
||||
const char* className() { return nullptr; }
|
||||
|
||||
T *target;
|
||||
};
|
||||
|
||||
bool findObject(const char *name, const char *targetClass, bool nullable);
|
||||
|
||||
//! Locates an object inside the archive. A derived class
|
||||
//! must provide its specific location code.
|
||||
virtual bool locateObjectByName(const char *name, const char *targetClass, bool nullable) = 0;
|
||||
virtual bool locateNextObjectByName(const char *name, const char *targetClass) = 0;
|
||||
|
||||
//! Whenever a nullptr object has to be serialized this method will be called.
|
||||
//! It has a default implementation (which does nothing) and does not need
|
||||
//! to be implemented by derived classes. But sometimes this information
|
||||
//! maybe quite useful. This method gets never called while in read mode.
|
||||
virtual void locateNullObjectByName(const char *name, const char *targetClass, bool first);
|
||||
|
||||
//! When a sequence is to be read this methods gets called
|
||||
virtual void readSequence();
|
||||
|
||||
//! Whenever a sequence is to be written this method gets called with the
|
||||
//! size of the sequence. The default implementation does nothing.
|
||||
virtual void writeSequence(int size);
|
||||
|
||||
/** Whenever a polymorphic object has to be read, its classname
|
||||
must be known to construct the object. A derived class
|
||||
must implement this method to retrieve the current object
|
||||
classname.
|
||||
*/
|
||||
virtual std::string determineClassName() = 0;
|
||||
|
||||
//! Sets the classname to be written
|
||||
virtual void setClassName(const char*) = 0;
|
||||
|
||||
/** Method to serialize an polymorphic object
|
||||
The default implementation simply calls
|
||||
\code
|
||||
object->serialize(*this);
|
||||
\endcode
|
||||
|
||||
Derived classes can override this method to wrap
|
||||
the serialization process.
|
||||
\code
|
||||
Do_something_nifty_before_serialization();
|
||||
Archive<ROOT_TYPE>::serialize(object);
|
||||
Do_really_cool_things_after_serialization();
|
||||
\endcode
|
||||
*/
|
||||
virtual void serialize(ROOT_TYPE *object);
|
||||
virtual void serialize(SerializeDispatcher &);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
template <typename T>
|
||||
void readPtr(ROOT_TYPE *, T *&object);
|
||||
|
||||
template <typename T>
|
||||
void readPtr(void*, T *&object);
|
||||
|
||||
//! Helper function to distinguish between pointer and non pointer
|
||||
//! types to avoid nullptr pointer serialization.
|
||||
template <typename T>
|
||||
void read(const char *name, T &object, const char *targetClass);
|
||||
|
||||
template <typename T>
|
||||
void read(const char *name, T *&object, const char *targetClass);
|
||||
|
||||
template <typename T>
|
||||
void read(const char *name, ::boost::intrusive_ptr<T> &object, const char *targetClass);
|
||||
|
||||
template <typename T>
|
||||
void read(const char *name, ::boost::optional<T> &object, const char *targetClass);
|
||||
|
||||
template <typename T>
|
||||
void write(const char *name, T &object, const char *targetClass);
|
||||
|
||||
//! Helper function to distinguish between C pointer and SmartPointers
|
||||
template <typename T>
|
||||
void write(const char* name, T* object, const char* targetClass);
|
||||
|
||||
//! Helper function to distinguish between C pointer and SmartPointers
|
||||
template <typename T>
|
||||
void write(const char *name, ::boost::intrusive_ptr<T> &object, const char *targetClass);
|
||||
|
||||
//! Helper function to distinguish between C pointer and Optionals
|
||||
template <typename T>
|
||||
void write(const char *name, ::boost::optional<T> &object, const char *targetClass);
|
||||
|
||||
int setChildHint(int h);
|
||||
|
||||
protected:
|
||||
int _hint;
|
||||
bool _isReading;
|
||||
bool _validObject;
|
||||
bool _first;
|
||||
bool _found;
|
||||
bool _strict;
|
||||
Version _version;
|
||||
Properties _properties;
|
||||
|
||||
|
||||
template <typename ROOT, typename T, int CLASS_TYPE>
|
||||
friend struct VectorReader;
|
||||
|
||||
template <typename ROOT, typename T, int CLASS_TYPE>
|
||||
friend struct VectorWriter;
|
||||
|
||||
template <typename ROOT, typename T, int CLASS_TYPE>
|
||||
friend struct ListReader;
|
||||
|
||||
template <typename ROOT, typename T, int CLASS_TYPE>
|
||||
friend struct ListWriter;
|
||||
|
||||
template <typename ROOT, typename T, int CLASS_TYPE>
|
||||
friend struct ContainerReader;
|
||||
|
||||
template <typename ROOT, typename T, int CLASS_TYPE>
|
||||
friend struct ContainerWriter;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#include "archive.inl"
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
903
include/seiscomp/core/archive.inl
Normal file
903
include/seiscomp/core/archive.inl
Normal file
@ -0,0 +1,903 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename T, int CLASS_TYPE>
|
||||
struct VectorReader {};
|
||||
|
||||
template <typename ROOT_TYPE, typename T, int CLASS_TYPE>
|
||||
struct VectorWriter {};
|
||||
|
||||
template <typename ROOT_TYPE, typename T, int CLASS_TYPE>
|
||||
struct ListReader {};
|
||||
|
||||
template <typename ROOT_TYPE, typename T, int CLASS_TYPE>
|
||||
struct ListWriter {};
|
||||
|
||||
template <typename ROOT_TYPE, typename T, int CLASS_TYPE>
|
||||
struct ContainerReader {};
|
||||
|
||||
template <typename ROOT_TYPE, typename T, int CLASS_TYPE>
|
||||
struct ContainerWriter {};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
namespace {
|
||||
|
||||
template <typename DERIVEDCLASS, typename BASECLASS>
|
||||
class IsTypeOf {
|
||||
class No { };
|
||||
class Yes { No no[2]; };
|
||||
|
||||
static Yes Test(BASECLASS*); // declared, but not defined
|
||||
static No Test(...); // declared, but not defined
|
||||
|
||||
public:
|
||||
enum { Value = sizeof(Test(static_cast<DERIVEDCLASS*>(0))) == sizeof(Yes) };
|
||||
};
|
||||
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
inline bool checkRootType(TYPE*&) {
|
||||
return IsTypeOf<TYPE, ROOT_TYPE>::Value;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
inline bool checkRootType(::boost::intrusive_ptr<TYPE>&) {
|
||||
return IsTypeOf<TYPE, ROOT_TYPE>::Value;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
inline bool checkRootType(TYPE&) {
|
||||
return IsTypeOf<TYPE, ROOT_TYPE>::Value;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
inline const char *checkClassName(const ROOT_TYPE**, const TYPE*) {
|
||||
return TYPE::ClassName();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
inline const char *checkClassName(const ROOT_TYPE*, const TYPE&) {
|
||||
return TYPE::ClassName();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
inline const char *checkClassName(const ::boost::intrusive_ptr<TYPE>*, const ::boost::intrusive_ptr<TYPE>&) {
|
||||
return TYPE::ClassName();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
inline const char *checkClassName(const void**, const TYPE*) {
|
||||
return nullptr;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
inline const char *checkClassName(const void*, const TYPE&) {
|
||||
return nullptr;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T, int CLASS_TYPE>
|
||||
struct ClassQuery {};
|
||||
|
||||
template <typename T>
|
||||
struct ClassQuery<T,0> {
|
||||
const char *operator()() const { return nullptr; }
|
||||
};
|
||||
template <typename T>
|
||||
struct ClassQuery<T,1> {
|
||||
const char *operator()() const { return T::ClassName(); }
|
||||
};
|
||||
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
const char *checkClassName(const ::boost::optional<TYPE>*, const ::boost::optional<TYPE>&) {
|
||||
ClassQuery<TYPE, boost::is_base_of<ROOT_TYPE, TYPE>::value> query;
|
||||
return query();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator<<(T*& object) {
|
||||
write(nullptr, object, T::ClassName());
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator<<(::boost::intrusive_ptr<T>& object) {
|
||||
write(nullptr, object.get(), T::ClassName());
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct ContainerWriter<ROOT_TYPE, T,1> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<T>& namedObject) {
|
||||
ar << ObjectNamer<typename T::ContainerType>(namedObject.name(), namedObject.object().container(), namedObject.hint());
|
||||
/*
|
||||
namedObject.object().reset();
|
||||
while ( namedObject.object().next() )
|
||||
ar.write(namedObject.name(), namedObject.object().get(), checkClassName<ROOT_TYPE>(&namedObject.object().get(), namedObject.object().get()));
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct ContainerWriter<ROOT_TYPE, T,0> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<T>& namedObject) {
|
||||
ar.write(namedObject.name(), namedObject.object(), checkClassName<ROOT_TYPE>(&namedObject.object(), namedObject.object()));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator<<(const ObjectNamer<T>& namedObject) {
|
||||
int h = setChildHint(namedObject.hint());
|
||||
//setHint(h | namedObject.hint());
|
||||
ContainerWriter<ROOT_TYPE, T,boost::is_const<T>::value?1:0> writer;
|
||||
writer(*this, namedObject);
|
||||
setHint(h);
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct VectorWriter<ROOT_TYPE, T,1> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<std::vector<T> >& namedObject) {
|
||||
typename std::vector<T>::iterator it;
|
||||
|
||||
ar.writeSequence(namedObject.object().size());
|
||||
|
||||
ar._first = true;
|
||||
for ( it = namedObject.object().begin(); it != namedObject.object().end(); ++it ) {
|
||||
ar.write(namedObject.name(), *it, checkClassName<ROOT_TYPE>(&(*it), *it));
|
||||
ar._first = false;
|
||||
}
|
||||
ar._first = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct VectorWriter<ROOT_TYPE, T,0> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<std::vector<T> >& namedObject) {
|
||||
if ( ar.locateObjectByName(namedObject.name(), nullptr, false) )
|
||||
ar.write(namedObject.object());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator<<(const ObjectNamer<std::vector<T> >& namedObject) {
|
||||
int h = setChildHint(namedObject.hint());
|
||||
|
||||
typedef typename boost::remove_pointer<T>::type RAW_T;
|
||||
|
||||
VectorWriter<ROOT_TYPE,T,
|
||||
boost::is_class<RAW_T>::value?
|
||||
(
|
||||
boost::is_same<std::complex<double>,T>::value?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<std::string,T>::value?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<Seiscomp::Core::Time,T>::value?
|
||||
0
|
||||
:
|
||||
1
|
||||
)
|
||||
)
|
||||
)
|
||||
:
|
||||
0
|
||||
> writer;
|
||||
|
||||
writer(*this, namedObject);
|
||||
|
||||
setHint(h);
|
||||
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct ListWriter<ROOT_TYPE, T,1> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<std::list<T> >& namedObject) {
|
||||
typename std::list<T>::iterator it;
|
||||
|
||||
ar.writeSequence(namedObject.object().size());
|
||||
|
||||
ar._first = true;
|
||||
for ( it = namedObject.object().begin(); it != namedObject.object().end(); ++it ) {
|
||||
ar.write(namedObject.name(), *it, checkClassName<ROOT_TYPE>(&(*it), *it));
|
||||
ar._first = false;
|
||||
}
|
||||
ar._first = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct ListWriter<ROOT_TYPE, T,0> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<std::list<T> >& namedObject) {
|
||||
if ( ar.locateObjectByName(namedObject.name(), nullptr, false) )
|
||||
ar.write(namedObject.object());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator<<(const ObjectNamer<std::list<T> >& namedObject) {
|
||||
int h = setChildHint(namedObject.hint());
|
||||
|
||||
typedef typename boost::remove_pointer<T>::type RAW_T;
|
||||
|
||||
ListWriter<ROOT_TYPE,T,
|
||||
boost::is_class<RAW_T>::value?
|
||||
(
|
||||
boost::is_same<std::complex<double>,T>::value
|
||||
?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<std::string,T>::value?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<Time,T>::value?
|
||||
0
|
||||
:
|
||||
1
|
||||
)
|
||||
)
|
||||
)
|
||||
:
|
||||
0
|
||||
> writer;
|
||||
writer(*this, namedObject);
|
||||
|
||||
setHint(h);
|
||||
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(T*& object) {
|
||||
const char *classname = T::ClassName();
|
||||
if ( !classname )
|
||||
return *this;
|
||||
|
||||
//_validObject = true;
|
||||
|
||||
read(classname, object, classname);
|
||||
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(::boost::intrusive_ptr<T>& object) {
|
||||
//_validObject = true;
|
||||
const char *classname = T::ClassName();
|
||||
if ( !classname )
|
||||
return *this;
|
||||
|
||||
read(classname, object, classname);
|
||||
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct ContainerReader<ROOT_TYPE, T,1> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<T>& namedObject) {
|
||||
const char *objectName = namedObject.name();
|
||||
typename T::Type value;
|
||||
|
||||
bool oldState = ar.success();
|
||||
|
||||
ar.readSequence();
|
||||
|
||||
ObjectNamer<typename T::Type> namedItem = nameObject(objectName, value, namedObject.hint());
|
||||
|
||||
ar._first = true;
|
||||
|
||||
ar >> namedItem;
|
||||
while ( ar._found ) {
|
||||
if ( ar.success() )
|
||||
namedObject.object().add(value);
|
||||
ar._first = false;
|
||||
ar._validObject = true;
|
||||
ar >> namedItem;
|
||||
}
|
||||
|
||||
ar._first = true;
|
||||
|
||||
// Restore old state if not in strict mode otherwise pass it through
|
||||
if ( !ar._strict )
|
||||
ar._validObject = oldState;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct ContainerReader<ROOT_TYPE,T,0> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<T>& namedObject) {
|
||||
// goto the object location in the archive
|
||||
const char *classname = checkClassName<ROOT_TYPE>(&namedObject.object(), namedObject.object());
|
||||
ar.read(namedObject.name(), namedObject.object(), classname);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(const ObjectIterator<T>& it) {
|
||||
//_validObject = true;
|
||||
_first = it.first();
|
||||
*this >> it.object();
|
||||
_first = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(const ObjectNamer<T>& namedObject) {
|
||||
int h = setChildHint(namedObject.hint());
|
||||
//setHint(h | namedObject.hint());
|
||||
|
||||
//_validObject = true;
|
||||
ContainerReader<ROOT_TYPE,T,boost::is_const<T>::value?1:0> reader;
|
||||
reader(*this, namedObject);
|
||||
|
||||
setHint(h);
|
||||
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct VectorReader<ROOT_TYPE, T,1> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<std::vector<T> >& namedObject) {
|
||||
const char *objectName = namedObject.name();
|
||||
T value;
|
||||
|
||||
bool oldState = ar.success();
|
||||
|
||||
ar.readSequence();
|
||||
ar._first = true;
|
||||
|
||||
ObjectNamer<T> namedItem = nameObject(objectName, value, namedObject.hint());
|
||||
|
||||
ar >> namedItem;
|
||||
while ( ar._found ) {
|
||||
if ( ar.success() )
|
||||
namedObject.object().push_back(value);
|
||||
ar._first = false;
|
||||
ar._validObject = true;
|
||||
ar >> namedItem;
|
||||
}
|
||||
|
||||
ar._first = true;
|
||||
|
||||
// Restore old state if not in strict mode otherwise pass it through
|
||||
if ( !ar._strict )
|
||||
ar._validObject = oldState;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct VectorReader<ROOT_TYPE,T,0> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<std::vector<T> >& namedObject) {
|
||||
if ( ar.locateObjectByName(namedObject.name(), nullptr, false) )
|
||||
ar.read(namedObject.object());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(const ObjectNamer<std::vector<T> >& namedObject) {
|
||||
int h = setChildHint(namedObject.hint());
|
||||
//setHint(h | namedObject.hint());
|
||||
|
||||
typedef typename boost::remove_pointer<T>::type RAW_T;
|
||||
|
||||
//_validObject = true;
|
||||
|
||||
VectorReader<ROOT_TYPE,T,
|
||||
boost::is_class<RAW_T>::value?
|
||||
(
|
||||
boost::is_same<std::complex<double>,T>::value?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<std::string,T>::value?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<Seiscomp::Core::Time,T>::value?
|
||||
0
|
||||
:
|
||||
1
|
||||
)
|
||||
)
|
||||
)
|
||||
:
|
||||
0
|
||||
> reader;
|
||||
|
||||
reader(*this, namedObject);
|
||||
|
||||
setHint(h);
|
||||
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct ListReader<ROOT_TYPE, T,1> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<std::list<T> >& namedObject) {
|
||||
const char *objectName = namedObject.name();
|
||||
T value;
|
||||
|
||||
bool oldState = ar.success();
|
||||
|
||||
ar.readSequence();
|
||||
ar._first = true;
|
||||
|
||||
ObjectNamer<T> namedItem = nameObject(objectName, value, namedObject.hint());
|
||||
|
||||
ar >> namedItem;
|
||||
while ( ar._found ) {
|
||||
if ( ar.success() )
|
||||
namedObject.object().push_back(value);
|
||||
ar._first = false;
|
||||
ar._validObject = true;
|
||||
ar >> namedItem;
|
||||
}
|
||||
|
||||
ar._first = true;
|
||||
|
||||
// Restore old state if not in strict mode otherwise pass it through
|
||||
if ( !ar._strict )
|
||||
ar._validObject = oldState;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE, typename T>
|
||||
struct ListReader<ROOT_TYPE,T,0> {
|
||||
void operator()(Archive<ROOT_TYPE>& ar, const ObjectNamer<std::list<T> >& namedObject) {
|
||||
if ( ar.locateObjectByName(namedObject.name(), nullptr, false) )
|
||||
ar.read(namedObject.object());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator>>(const ObjectNamer<std::list<T> >& namedObject) {
|
||||
int h = setChildHint(namedObject.hint());
|
||||
//setHint(h | namedObject.hint());
|
||||
|
||||
typedef typename boost::remove_pointer<T>::type RAW_T;
|
||||
|
||||
//_validObject = true;
|
||||
ListReader<ROOT_TYPE,T,
|
||||
boost::is_class<RAW_T>::value?
|
||||
(
|
||||
boost::is_same<std::complex<double>,T>::value?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<std::string,T>::value?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<Seiscomp::Core::Time,T>::value?
|
||||
0
|
||||
:
|
||||
1
|
||||
)
|
||||
)
|
||||
)
|
||||
:
|
||||
0
|
||||
> reader;
|
||||
reader(*this, namedObject);
|
||||
|
||||
setHint(h);
|
||||
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline Archive<ROOT_TYPE>& Archive<ROOT_TYPE>::operator&(ObjectNamer<T> namedObject) {
|
||||
isReading() ? *this >> namedObject : *this << namedObject;
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::read(T*& object) {
|
||||
readPtr(object, object);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::read(::boost::intrusive_ptr<T>& object) {
|
||||
T *ref = nullptr;
|
||||
read(ref);
|
||||
object = ref;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::read(::boost::optional<T>& object) {
|
||||
bool oldState = success();
|
||||
|
||||
object = T();
|
||||
|
||||
read(*object);
|
||||
if ( !success() )
|
||||
object = boost::none;
|
||||
|
||||
// Restore old state if not in strict mode otherwise pass it through
|
||||
if ( !_strict )
|
||||
_validObject = oldState;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::readPtr(ROOT_TYPE*, T*& object) {
|
||||
if ( (hint() & STATIC_TYPE) == 0 ) {
|
||||
std::string className = determineClassName();
|
||||
if ( className.empty() ) return;
|
||||
|
||||
if ( !ClassFactoryInterface<ROOT_TYPE>::IsTypeOf(T::ClassName(), className.c_str()) ) {
|
||||
_validObject = false;
|
||||
return;
|
||||
}
|
||||
object = static_cast<T*>(ClassFactoryInterface<ROOT_TYPE>::Create(className.c_str()));
|
||||
if ( !object )
|
||||
throw ClassNotFound(className);
|
||||
}
|
||||
else {
|
||||
object = static_cast<T*>(ClassFactoryInterface<ROOT_TYPE>::Create(T::ClassName()));
|
||||
if ( !object )
|
||||
throw ClassNotFound(T::ClassName());
|
||||
}
|
||||
|
||||
if ( object )
|
||||
read(*object);
|
||||
else
|
||||
_validObject = false;
|
||||
|
||||
if ( !success() && object ) {
|
||||
delete object;
|
||||
object = nullptr;
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::readPtr(void*, T*& object) {
|
||||
object = new T;
|
||||
read(*object);
|
||||
if ( !success() ) {
|
||||
delete object;
|
||||
object = nullptr;
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::read(T& object) {
|
||||
typename boost::mpl::if_c<boost::is_base_of<ROOT_TYPE, T>::value,
|
||||
ROOT_TYPE*,
|
||||
TypedSerializeDispatcher<T> >::type t;
|
||||
t = &object;
|
||||
serialize(t);
|
||||
//_validObject = true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::read(const char *name, T &object, const char *targetClass) {
|
||||
if ( findObject(name, targetClass, false) )
|
||||
read(object);
|
||||
else if ( !(boost::is_base_of<std::string, T>::value || boost::is_same<std::string, T>::value) )
|
||||
_validObject = false;
|
||||
else
|
||||
object = T();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::read(const char *name, T *&object, const char *targetClass) {
|
||||
if ( findObject(name, targetClass, true) )
|
||||
read(object);
|
||||
else {
|
||||
//_validObject = false;
|
||||
object = nullptr;
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::read(const char *name, ::boost::intrusive_ptr<T> &object, const char *targetClass) {
|
||||
if ( findObject(name, targetClass, true) )
|
||||
read(object);
|
||||
else {
|
||||
//_validObject = false;
|
||||
object = nullptr;
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::read(const char *name, ::boost::optional<T> &object, const char *targetClass) {
|
||||
if ( findObject(name, targetClass, true) )
|
||||
read(object);
|
||||
else {
|
||||
//_validObject = false;
|
||||
object = boost::none;
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::write(T& object) {
|
||||
typename boost::mpl::if_c<boost::is_base_of<ROOT_TYPE, T>::value,
|
||||
ROOT_TYPE*,
|
||||
TypedSerializeDispatcher<T> >::type t;
|
||||
|
||||
t = &object;
|
||||
setClassName(hint() & STATIC_TYPE?nullptr:t->className());
|
||||
serialize(t);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::write(T *object) {
|
||||
write(*object);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::write(const char *name, T &object, const char *targetClass) {
|
||||
// goto the object location in the archive
|
||||
findObject(name, targetClass, false);
|
||||
// write the object data
|
||||
write(object);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::write(const char *name, T *object, const char *targetClass) {
|
||||
if ( !object ) {
|
||||
locateNullObjectByName(name, targetClass, _first);
|
||||
return;
|
||||
}
|
||||
findObject(name, targetClass, true);
|
||||
// write the object data
|
||||
write(*object);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::write(const char *name, ::boost::intrusive_ptr<T> &object, const char *targetClass) {
|
||||
write(name, object.get(), targetClass);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
template <typename T>
|
||||
inline void Archive<ROOT_TYPE>::write(const char *name, ::boost::optional<T> &object, const char *targetClass) {
|
||||
write(name, object.get_ptr(), targetClass);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
331
include/seiscomp/core/archive.ipp
Normal file
331
include/seiscomp/core/archive.ipp
Normal file
@ -0,0 +1,331 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
namespace Generic {
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
Archive<ROOT_TYPE>::Archive()
|
||||
: _hint(NONE), _isReading(true)
|
||||
, _validObject(true), _first(true)
|
||||
, _strict(false) {
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool Archive<ROOT_TYPE>::open(const char *dataSource) {
|
||||
_isReading = true;
|
||||
_validObject = true;
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool Archive<ROOT_TYPE>::create(const char *dataSource) {
|
||||
_isReading = false;
|
||||
_validObject = true;
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
int Archive<ROOT_TYPE>::setChildHint(int h) {
|
||||
int tmp = hint();
|
||||
// The INDEX_ATTRIBUTE flag will passed to child objects
|
||||
setHint((tmp & INDEX_ATTRIBUTE) | h);
|
||||
return tmp;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
void Archive<ROOT_TYPE>::read(ROOT_TYPE& object) {
|
||||
serialize(&object);
|
||||
//_validObject = true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
void Archive<ROOT_TYPE>::write(ROOT_TYPE& object) {
|
||||
setClassName(object.className());
|
||||
serialize(&object);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
void Archive<ROOT_TYPE>::locateNullObjectByName(const char*, const char*, bool) {
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
void Archive<ROOT_TYPE>::writeSequence(int /*size*/) {
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
void Archive<ROOT_TYPE>::readSequence() {
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool Archive<ROOT_TYPE>::findObject(const char *name, const char *targetClass, bool nullable) {
|
||||
_found = _first ? locateObjectByName(name, targetClass, nullable)
|
||||
: locateNextObjectByName(name, targetClass);
|
||||
return _found;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
void Archive<ROOT_TYPE>::serialize(ROOT_TYPE *object) {
|
||||
bool iterFlag = _first;
|
||||
bool oldFound = _found;
|
||||
_first = true;
|
||||
object->serialize(*this);
|
||||
_first = iterFlag;
|
||||
_found = oldFound;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
void Archive<ROOT_TYPE>::serialize(SerializeDispatcher& disp) {
|
||||
bool iterFlag = _first;
|
||||
bool oldFound = _found;
|
||||
_first = true;
|
||||
disp(*this);
|
||||
_first = iterFlag;
|
||||
_found = oldFound;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
void Archive<ROOT_TYPE>::setStrictMode(bool strict) {
|
||||
_strict = strict;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool Archive<ROOT_TYPE>::isStrictMode() const {
|
||||
return _strict;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool Archive<ROOT_TYPE>::isReading() const {
|
||||
return _isReading;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool Archive<ROOT_TYPE>::success() const {
|
||||
return _validObject;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
int Archive<ROOT_TYPE>::hint() const {
|
||||
return _hint;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
void Archive<ROOT_TYPE>::setHint(int h) {
|
||||
_hint = h;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
inline void Archive<ROOT_TYPE>::setValidity(bool v) {
|
||||
if ( !v )
|
||||
_validObject = false;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
inline size_t Archive<ROOT_TYPE>::propertyCount() const {
|
||||
return _properties.size();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool Archive<ROOT_TYPE>::setProperty(const char *name, const PropertyValue &v) {
|
||||
Properties::iterator it = _properties.find(name);
|
||||
if ( it == _properties.end() ) {
|
||||
_properties[name] = v;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
it->second = v;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
inline const typename Archive<ROOT_TYPE>::PropertyValue *
|
||||
Archive<ROOT_TYPE>::property(const char *name) const {
|
||||
Properties::const_iterator it = _properties.find(name);
|
||||
if ( it == _properties.end() )
|
||||
return nullptr;
|
||||
|
||||
return &it->second;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
inline void Archive<ROOT_TYPE>::clearProperties() {
|
||||
_properties.clear();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
const int *Archive<ROOT_TYPE>::propertyInt(const char *name) const {
|
||||
const PropertyValue *p = property(name);
|
||||
if ( !p ) return nullptr;
|
||||
return boost::get<int>(p);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
const double *Archive<ROOT_TYPE>::propertyDouble(const char *name) const {
|
||||
const PropertyValue *p = property(name);
|
||||
if ( !p ) return nullptr;
|
||||
return boost::get<double>(p);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
const std::string *Archive<ROOT_TYPE>::propertyString(const char *name) const {
|
||||
const PropertyValue *p = property(name);
|
||||
if ( !p ) return nullptr;
|
||||
return boost::get<std::string>(p);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
}
|
105
include/seiscomp/core/array.h
Normal file
105
include/seiscomp/core/array.h
Normal file
@ -0,0 +1,105 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_ARRAY_H
|
||||
#define SEISCOMP_CORE_ARRAY_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
DEFINE_SMARTPOINTER(Array);
|
||||
|
||||
/**
|
||||
* Generic abstract base class of certain array types.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API Array : public Seiscomp::Core::BaseObject {
|
||||
DECLARE_SC_CLASS(Array);
|
||||
|
||||
public:
|
||||
//! Specifies the supported array data types.
|
||||
enum DataType {
|
||||
CHAR,
|
||||
INT,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
DATETIME,
|
||||
STRING,
|
||||
COMPLEX_FLOAT,
|
||||
COMPLEX_DOUBLE,
|
||||
DT_QUANTITY
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
//! Initializing Constructor
|
||||
Array(DataType dt);
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~Array();
|
||||
|
||||
//! Returns the data type of the array
|
||||
DataType dataType() const { return _datatype; }
|
||||
|
||||
//! Returns a clone of the array
|
||||
Array* clone() const;
|
||||
|
||||
//! Returns a copy of the array of the specified data type.
|
||||
virtual Array* copy(DataType dt) const = 0;
|
||||
|
||||
//! Returns the data address pointer.
|
||||
virtual const void *data() const = 0;
|
||||
|
||||
//! Returns the size of the array.
|
||||
virtual int size() const = 0;
|
||||
|
||||
//! Resizes the array
|
||||
virtual void resize(int size) = 0;
|
||||
|
||||
//! Drops all elements.
|
||||
virtual void clear() = 0;
|
||||
|
||||
//! Returns the number of bytes of an array element.
|
||||
virtual int elementSize() const = 0;
|
||||
|
||||
//! Appends the given array to this array.
|
||||
virtual void append(const Array*) = 0;
|
||||
|
||||
//! Concatenates the given array to this array.
|
||||
// virtual void concatenate(Array*) = 0;
|
||||
|
||||
//! Returns the slice m...n-1 of the array
|
||||
virtual Array* slice(int m, int n) const = 0;
|
||||
|
||||
//! Converts the array into a binary stream of
|
||||
//! chars
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
DataType _datatype;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
41
include/seiscomp/core/arrayfactory.h
Normal file
41
include/seiscomp/core/arrayfactory.h
Normal file
@ -0,0 +1,41 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_ARRAYFACTORY_H
|
||||
#define SEISCOMP_CORE_ARRAYFACTORY_H
|
||||
|
||||
#include <seiscomp/core/array.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
/**
|
||||
* Factory class for the different array classes.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API ArrayFactory {
|
||||
public:
|
||||
//! Creates an array object specified by the given data type
|
||||
static Array* Create(Array::DataType toCreate, Array::DataType caller, int size, const void *data);
|
||||
static Array* Create(Array::DataType toCreate, const Array *source);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
246
include/seiscomp/core/baseobject.h
Normal file
246
include/seiscomp/core/baseobject.h
Normal file
@ -0,0 +1,246 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_BASEOBJECT_H
|
||||
#define SEISCOMP_CORE_BASEOBJECT_H
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
class BaseObject;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include <seiscomp/core/defs.h>
|
||||
#include <seiscomp/core/rtti.h>
|
||||
#include <seiscomp/core/metaobject.h>
|
||||
#include <seiscomp/core/archive.h>
|
||||
#include <seiscomp/core/factory.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
#define DECLARE_CASTS(CLASS) \
|
||||
public: \
|
||||
static CLASS* Cast(Seiscomp::Core::BaseObject* o) { \
|
||||
return dynamic_cast<CLASS*>(o); \
|
||||
} \
|
||||
\
|
||||
static const CLASS* ConstCast(const Seiscomp::Core::BaseObject* o) { \
|
||||
return dynamic_cast<const CLASS*>(o); \
|
||||
} \
|
||||
\
|
||||
static CLASS* Cast(Seiscomp::Core::BaseObjectPtr o) { \
|
||||
return dynamic_cast<CLASS*>(o.get()); \
|
||||
} \
|
||||
static const CLASS* ConstCast(Seiscomp::Core::BaseObjectCPtr o) { \
|
||||
return dynamic_cast<const CLASS*>(o.get()); \
|
||||
}
|
||||
|
||||
#define DECLARE_SC_CLASS(CLASS) \
|
||||
DECLARE_RTTI; \
|
||||
DECLARE_CASTS(CLASS)
|
||||
|
||||
|
||||
#define IMPLEMENT_SC_CLASS(CLASS, CLASSNAME) \
|
||||
IMPLEMENT_RTTI(CLASS, CLASSNAME, Seiscomp::Core::BaseObject) \
|
||||
IMPLEMENT_RTTI_METHODS(CLASS) \
|
||||
REGISTER_CLASS(Seiscomp::Core::BaseObject, CLASS)
|
||||
|
||||
#define IMPLEMENT_SC_CLASS_DERIVED(CLASS, BASECLASS, CLASSNAME) \
|
||||
IMPLEMENT_RTTI(CLASS, CLASSNAME, BASECLASS) \
|
||||
IMPLEMENT_RTTI_METHODS(CLASS) \
|
||||
REGISTER_CLASS(Seiscomp::Core::BaseObject, CLASS)
|
||||
|
||||
#define IMPLEMENT_SC_CLASS_DERIVED_OVERWRITE(CLASS, BASECLASS, CLASSNAME) \
|
||||
IMPLEMENT_RTTI(CLASS, CLASSNAME, BASECLASS) \
|
||||
IMPLEMENT_RTTI_METHODS(CLASS) \
|
||||
REREGISTER_CLASS(Seiscomp::Core::BaseObject, CLASS)
|
||||
|
||||
|
||||
#define IMPLEMENT_SC_ABSTRACT_CLASS(CLASS, CLASSNAME) \
|
||||
IMPLEMENT_RTTI(CLASS, CLASSNAME, Seiscomp::Core::BaseObject) \
|
||||
IMPLEMENT_RTTI_METHODS(CLASS) \
|
||||
REGISTER_ABSTRACT_CLASS(Seiscomp::Core::BaseObject, CLASS)
|
||||
|
||||
#define IMPLEMENT_SC_ABSTRACT_CLASS_DERIVED(CLASS, BASECLASS, CLASSNAME) \
|
||||
IMPLEMENT_RTTI(CLASS, CLASSNAME, BASECLASS) \
|
||||
IMPLEMENT_RTTI_METHODS(CLASS) \
|
||||
REGISTER_ABSTRACT_CLASS(Seiscomp::Core::BaseObject, CLASS)
|
||||
|
||||
#define DECLARE_SC_CLASSFACTORY_FRIEND(CLASS) \
|
||||
DECLARE_CLASSFACTORY_FRIEND(Seiscomp::Core::BaseObject, CLASS)
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(BaseObject);
|
||||
typedef Generic::ClassFactoryInterface<BaseObject> ClassFactory;
|
||||
|
||||
|
||||
/**
|
||||
* \brief BaseObject has to be used for all classes that want to use
|
||||
* the provided serialization mechanism and reference counting.
|
||||
*
|
||||
* To derive from BaseObject the following basic steps are necessary:
|
||||
* 1. Create a class that derives from BaseObject
|
||||
* \code
|
||||
* class MyClass : public BaseObject
|
||||
* \endcode
|
||||
*
|
||||
* 2. Add the DECLARE_SC_CLASS macro to add the RTTI interface among other things
|
||||
* \code
|
||||
* class MyClass : public BaseObject {
|
||||
* DECLARE_SC_CLASS(MyClass);
|
||||
* public:
|
||||
* MyClass();
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* Implement the class RTTI data in the .cpp file
|
||||
* \code
|
||||
* // First parameter is the classname, second parameter is the name inside RTTI
|
||||
* IMPLEMENT_SC_CLASS(MyClass, "MyClass");
|
||||
* \endcode
|
||||
*
|
||||
* If the class is abstract (it has some pure virtual methods) another macro
|
||||
* must be used:
|
||||
* \code
|
||||
* // First parameter is the classname, second parameter is the name inside RTTI
|
||||
* IMPLEMENT_SC_ABSTRACR_CLASS(MyClass, "MyClass");
|
||||
* \endcode
|
||||
*
|
||||
* 3. If you want your class to be serialized add the appropriate declaration
|
||||
* \code
|
||||
* class MyClass : public BaseObject {
|
||||
* DECLARE_SC_CLASS(MyClass);
|
||||
*
|
||||
* // Add serialization interface
|
||||
* DECLARE_SERIALIZATION;
|
||||
*
|
||||
* public:
|
||||
* MyClass();
|
||||
*
|
||||
* private:
|
||||
* int _myMember;
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* The serialization method has to be implemented the following way:
|
||||
* \code
|
||||
* void MyClass::serialize(Archive& ar) {
|
||||
* // the archive will bind the name 'var1' to the member variable
|
||||
* // _myMember
|
||||
* ar & NAMED_OBJECT("var1", _myMember);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API BaseObject {
|
||||
DECLARE_BASE_RTTI;
|
||||
DECLARE_CASTS(BaseObject)
|
||||
DECLARE_ROOT_SERIALIZATION(BaseObject)
|
||||
DECLARE_METAOBJECT_INTERFACE;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
//! Constructor
|
||||
BaseObject();
|
||||
BaseObject(const BaseObject&);
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~BaseObject();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns a shallow copy of this instance
|
||||
virtual BaseObject *clone() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Operators
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
BaseObject &operator=(const BaseObject&);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Reference counting
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Increment the reference counter
|
||||
void incrementReferenceCount() const;
|
||||
|
||||
//! Decrement the reference counter and deletes the object
|
||||
//! when reaching 0
|
||||
void decrementReferenceCount() const;
|
||||
|
||||
/**
|
||||
* Returns the number of references to this object when using smartpointers
|
||||
* @return current reference count
|
||||
*/
|
||||
unsigned int referenceCount() const;
|
||||
|
||||
/**
|
||||
* Returns the number of created objects of type BaseObject at the time
|
||||
* of calling this function.
|
||||
* @return number of objects created
|
||||
*/
|
||||
static unsigned int ObjectCount();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
mutable volatile unsigned int _referenceCount;
|
||||
static volatile unsigned int _objectCount;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#include <seiscomp/core/baseobject.inl>
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
using Seiscomp::Core::intrusive_ptr_add_ref;
|
||||
using Seiscomp::Core::intrusive_ptr_release;
|
||||
|
||||
|
||||
#endif
|
71
include/seiscomp/core/baseobject.inl
Normal file
71
include/seiscomp/core/baseobject.inl
Normal file
@ -0,0 +1,71 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline void intrusive_ptr_add_ref(const BaseObject *p) {
|
||||
p->incrementReferenceCount();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline void intrusive_ptr_release(const BaseObject *p) {
|
||||
p->decrementReferenceCount();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline void BaseObject::incrementReferenceCount() const {
|
||||
++_referenceCount;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline void BaseObject::decrementReferenceCount() const {
|
||||
if ( --_referenceCount == 0 )
|
||||
delete this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline unsigned int BaseObject::referenceCount() const {
|
||||
return _referenceCount;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline unsigned int BaseObject::ObjectCount() {
|
||||
return _objectCount;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
226
include/seiscomp/core/bitset.h
Normal file
226
include/seiscomp/core/bitset.h
Normal file
@ -0,0 +1,226 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_BITSET_H
|
||||
#define SEISCOMP_CORE_BITSET_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(BitSet);
|
||||
|
||||
|
||||
/**
|
||||
* @brief The BitSet class represents a set of bits. It provides accesses to
|
||||
* the value of individual bits via an operator[] and provides all of
|
||||
* the bitwise operators that one can apply to builtin integers, such as
|
||||
* operator& and operator<<. The number of bits in the set is specified
|
||||
* at runtime via a parameter to the constructor of the BitSet.
|
||||
*
|
||||
* The implementation actually wraps the boost::dynamic_bitset [1]
|
||||
* implementation. That has been done to avoid multiple inheritance for the
|
||||
* Python wrappers and to have a consistent naming scheme of the class.
|
||||
*
|
||||
* [1] http://www.boost.org/doc/libs/1_33_1/libs/dynamic_bitset/dynamic_bitset.html
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API BitSet : public Seiscomp::Core::BaseObject {
|
||||
DECLARE_SC_CLASS(BitSet);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Type traits
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
typedef boost::dynamic_bitset<> ImplType;
|
||||
typedef ImplType::reference ReferenceType;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
BitSet();
|
||||
|
||||
//! Constructs a bitset with n bits
|
||||
BitSet(int n);
|
||||
|
||||
//! Copy constructor
|
||||
BitSet(const BitSet &other);
|
||||
|
||||
//! Construct from implementation type
|
||||
BitSet(const ImplType &impl);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Operators
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
BitSet &operator=(const BitSet &other);
|
||||
|
||||
operator ImplType&();
|
||||
operator const ImplType&() const;
|
||||
|
||||
ReferenceType operator[](size_t pos);
|
||||
bool operator[](size_t pos) const;
|
||||
|
||||
//! Bitwise-AND all the bits in rhs with the bits in this bitset.
|
||||
//! Requires this->size() == rhs.size().
|
||||
BitSet &operator&=(const BitSet &b);
|
||||
|
||||
//! Bitwise-OR's all the bits in rhs with the bits in this bitset.
|
||||
//! Requires this->size() == rhs.size().
|
||||
BitSet &operator|=(const BitSet &b);
|
||||
|
||||
//! Bitwise-XOR's all the bits in rhs with the bits in this bitset.
|
||||
//! Requires this->size() == rhs.size().
|
||||
BitSet &operator^=(const BitSet &b);
|
||||
|
||||
//! Computes the set difference of this bitset and the rhs bitset.
|
||||
//! Requires this->size() == rhs.size().
|
||||
BitSet &operator-=(const BitSet &b);
|
||||
|
||||
//! Shifts the bits in this bitset to the left by n bits. For each bit
|
||||
//! in the bitset, the bit at position pos takes on the previous value
|
||||
//! of the bit at position pos - n, or zero if no such bit exists.
|
||||
BitSet &operator<<=(size_t n);
|
||||
|
||||
//! Shifts the bits in this bitset to the right by n bits. For each bit
|
||||
//! in the bitset, the bit at position pos takes on the previous value
|
||||
//! of bit pos + n, or zero if no such bit exists.
|
||||
BitSet &operator>>=(size_t n);
|
||||
|
||||
//! Returns s copy of *this shifted to the left by n bits. For each bit
|
||||
//! in the returned bitset, the bit at position pos takes on the value
|
||||
//! of the bit at position pos - n of this bitset, or zero if no such
|
||||
//! bit exists.
|
||||
BitSet operator<<(size_t n) const;
|
||||
|
||||
//! Returns a copy of *this shifted to the right by n bits. For each bit
|
||||
//! in the returned bitset, the bit at position pos takes on the value
|
||||
//! of the bit at position pos + n of this bitset, or zero if no such
|
||||
//! bit exists.
|
||||
BitSet operator>>(size_t n) const;
|
||||
|
||||
//! Returns a copy of *this with all of its bits flipped.
|
||||
BitSet operator~() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Changes the number of bits of the bitset to num_bits. If
|
||||
//! num_bits > size() then the bits in the range [0,size()) remain the
|
||||
//! same, and the bits in [size(),num_bits) are all set to value. If
|
||||
//! num_bits < size() then the bits in the range [0,num_bits) stay the
|
||||
//! same (and the remaining bits are discarded).
|
||||
void resize(size_t num_bits, bool value = false);
|
||||
|
||||
//! The size of the bitset becomes zero.
|
||||
void clear();
|
||||
void append(bool bit);
|
||||
|
||||
//! Sets bit n if val is true, and clears bit n if val is false.
|
||||
BitSet &set(size_t n, bool val = true);
|
||||
|
||||
//! Sets every bit in this bitset to 1.
|
||||
BitSet &set();
|
||||
|
||||
//! Clears bit n.
|
||||
BitSet &reset(size_t n);
|
||||
|
||||
//! Clears every bit in this bitset.
|
||||
BitSet &reset();
|
||||
|
||||
//! Flips bit n.
|
||||
BitSet &flip(size_t n);
|
||||
|
||||
//! Flips the value of every bit in this bitset.
|
||||
BitSet &flip();
|
||||
|
||||
//! Returns true if bit n is set and false is bit n is 0.
|
||||
bool test(size_t n) const;
|
||||
|
||||
//! Returns true if any bits in this bitset are set, and otherwise
|
||||
//! returns false.
|
||||
bool any() const;
|
||||
|
||||
//! Returns true if no bits are set, and otherwise returns false.
|
||||
bool none() const;
|
||||
|
||||
//! Returns the number of bits in this bitset that are set.
|
||||
size_t numberOfBitsSet() const;
|
||||
|
||||
//! Returns the numeric value corresponding to the bits in *this.
|
||||
//! Throws std::overflow_error if that value is too large to be
|
||||
//! represented in an unsigned long, i.e. if *this has any non-zero bit
|
||||
//! at a position >= std::numeric_limits<unsigned long>::digits.
|
||||
unsigned long toUlong() const;
|
||||
|
||||
//! Returns the number of bits in this bitset.
|
||||
size_t size() const;
|
||||
|
||||
//! Returns the number of blocks in this bitset.
|
||||
size_t numberOfBlocks() const;
|
||||
|
||||
//! Returns the maximum size of a BitSet object having the same type
|
||||
//! as *this. Note that if any BitSet operation causes size() to exceed
|
||||
//! maxSize() then the behavior is undefined.
|
||||
size_t maximumSize() const;
|
||||
|
||||
//! Returns true if this->size() == 0, false otherwise. Note: not to be
|
||||
//! confused with none(), that has different semantics.
|
||||
bool empty() const;
|
||||
|
||||
//! Returns the lowest index i such as bit i is set, or npos if *this
|
||||
//! has no on bits.
|
||||
size_t findFirst() const;
|
||||
|
||||
//! Returns the lowest index i greater than pos such as bit i is set,
|
||||
//! or npos if no such index exists.
|
||||
size_t findNext(size_t pos) const;
|
||||
|
||||
//! Returns the boost::dynamic_bitset implementation instance
|
||||
const ImplType &impl() const;
|
||||
|
||||
//! Returns the boost::dynamic_bitset implementation instance
|
||||
ImplType &impl();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
ImplType _impl;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#include <seiscomp/core/bitset.ipp>
|
||||
|
||||
|
||||
#endif
|
268
include/seiscomp/core/bitset.ipp
Normal file
268
include/seiscomp/core/bitset.ipp
Normal file
@ -0,0 +1,268 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline BitSet::BitSet() {}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline BitSet::BitSet(int n) : _impl(n) {}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline BitSet::BitSet(const BitSet &other) : _impl(other._impl) {}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline BitSet::BitSet(const ImplType &impl) : _impl(impl) {}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline BitSet &BitSet::operator=(const BitSet &other) {
|
||||
_impl = other._impl;
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline BitSet::operator boost::dynamic_bitset<>&() {
|
||||
return _impl;
|
||||
}
|
||||
|
||||
inline BitSet::operator const boost::dynamic_bitset<>&() const {
|
||||
return _impl;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline BitSet::ReferenceType BitSet::operator[](size_t pos) {
|
||||
return _impl[pos];
|
||||
}
|
||||
|
||||
inline bool BitSet::operator[](size_t pos) const {
|
||||
return _impl[pos];
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::operator&=(const BitSet &b) {
|
||||
_impl &= b._impl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::operator|=(const BitSet &b) {
|
||||
_impl |= b._impl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::operator^=(const BitSet &b) {
|
||||
_impl ^= b._impl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::operator-=(const BitSet &b) {
|
||||
_impl -= b._impl;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::operator<<=(size_t n) {
|
||||
_impl <<= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::operator>>=(size_t n) {
|
||||
_impl >>= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet BitSet::operator<<(size_t n) const {
|
||||
return BitSet(_impl << n);
|
||||
}
|
||||
|
||||
inline BitSet BitSet::operator>>(size_t n) const {
|
||||
return BitSet(_impl >> n);
|
||||
}
|
||||
|
||||
inline BitSet BitSet::operator~() const {
|
||||
return BitSet(~_impl);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline void BitSet::resize(size_t num_bits, bool value) {
|
||||
_impl.resize(num_bits, value);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline void BitSet::clear() {
|
||||
_impl.clear();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline void BitSet::append(bool bit) {
|
||||
_impl.append(bit);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline BitSet &BitSet::set(size_t n, bool val) {
|
||||
_impl.set(n, val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::set() {
|
||||
_impl.set();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::reset(size_t n) {
|
||||
_impl.reset(n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::reset() {
|
||||
_impl.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::flip(size_t n) {
|
||||
_impl.flip(n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet &BitSet::flip() {
|
||||
_impl.flip();
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline bool BitSet::test(size_t n) const {
|
||||
return _impl.test(n);
|
||||
}
|
||||
|
||||
inline bool BitSet::any() const {
|
||||
return _impl.any();
|
||||
}
|
||||
|
||||
inline bool BitSet::none() const {
|
||||
return _impl.none();
|
||||
}
|
||||
|
||||
inline size_t BitSet::numberOfBitsSet() const {
|
||||
return _impl.count();
|
||||
}
|
||||
|
||||
inline unsigned long BitSet::toUlong() const {
|
||||
return _impl.to_ulong();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline size_t BitSet::size() const {
|
||||
return _impl.size();
|
||||
}
|
||||
|
||||
inline size_t BitSet::numberOfBlocks() const {
|
||||
return _impl.num_blocks();
|
||||
}
|
||||
|
||||
inline size_t BitSet::maximumSize() const {
|
||||
return _impl.max_size();
|
||||
}
|
||||
|
||||
inline bool BitSet::empty() const {
|
||||
return _impl.empty();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline size_t BitSet::findFirst() const {
|
||||
return _impl.find_first();
|
||||
}
|
||||
|
||||
inline size_t BitSet::findNext(size_t pos) const {
|
||||
return _impl.find_next(pos);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const BitSet::ImplType &BitSet::impl() const {
|
||||
return _impl;
|
||||
}
|
||||
|
||||
inline BitSet::ImplType &BitSet::impl() {
|
||||
return _impl;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
41
include/seiscomp/core/datamessage.h
Normal file
41
include/seiscomp/core/datamessage.h
Normal file
@ -0,0 +1,41 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_DATAMESSAGE_H
|
||||
#define SEISCOMP_CORE_DATAMESSAGE_H
|
||||
|
||||
#include <seiscomp/core/genericmessage.h>
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
DEFINE_MESSAGE_FOR(Seiscomp::Core::BaseObject, DataMessage, SC_SYSTEM_CORE_API);
|
||||
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#endif
|
312
include/seiscomp/core/datetime.h
Normal file
312
include/seiscomp/core/datetime.h
Normal file
@ -0,0 +1,312 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef SEISCOMP_CORE_DATETIME_H
|
||||
#define SEISCOMP_CORE_DATETIME_H
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/optional.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include <string>
|
||||
|
||||
|
||||
struct tm;
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API TimeSpan {
|
||||
public:
|
||||
static const double MinTime;
|
||||
static const double MaxTime;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
TimeSpan();
|
||||
TimeSpan(struct timeval*);
|
||||
TimeSpan(const struct timeval&);
|
||||
TimeSpan(double);
|
||||
TimeSpan(long secs, long usecs);
|
||||
|
||||
//! Copy constructor
|
||||
TimeSpan(const TimeSpan&);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Operators
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Comparison
|
||||
bool operator==(const TimeSpan&) const;
|
||||
bool operator!=(const TimeSpan&) const;
|
||||
bool operator< (const TimeSpan&) const;
|
||||
bool operator<=(const TimeSpan&) const;
|
||||
bool operator> (const TimeSpan&) const;
|
||||
bool operator>=(const TimeSpan&) const;
|
||||
|
||||
//! Conversion
|
||||
operator double() const;
|
||||
operator const timeval&() const;
|
||||
|
||||
//! Assignment
|
||||
TimeSpan& operator=(long t);
|
||||
TimeSpan& operator=(double t);
|
||||
TimeSpan& operator=(const TimeSpan& t);
|
||||
|
||||
//! Arithmetic
|
||||
TimeSpan operator+(const TimeSpan&) const;
|
||||
TimeSpan operator-(const TimeSpan&) const;
|
||||
|
||||
TimeSpan& operator+=(const TimeSpan&);
|
||||
TimeSpan& operator-=(const TimeSpan&);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the absolute value of time
|
||||
TimeSpan abs() const;
|
||||
|
||||
//! Returns the seconds of the timespan
|
||||
long seconds() const;
|
||||
//! Returns the microseconds of the timespan
|
||||
long microseconds() const;
|
||||
|
||||
//! Returns the (possibly negative) length of the timespan in seconds
|
||||
double length() const;
|
||||
|
||||
//! Sets the seconds
|
||||
TimeSpan& set(long seconds);
|
||||
|
||||
//! Sets the microseconds
|
||||
TimeSpan& setUSecs(long);
|
||||
|
||||
//! Assigns the elapsed time to the passed out parameters
|
||||
void elapsedTime(int* days, int* hours = nullptr,
|
||||
int* minutes = nullptr, int* seconds = nullptr) const;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
struct timeval _timeval;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Time : public TimeSpan {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public static data members
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
static const Time Null;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
Time();
|
||||
Time(long secs, long usecs);
|
||||
|
||||
explicit Time(const TimeSpan&);
|
||||
explicit Time(const struct timeval&);
|
||||
explicit Time(struct timeval*);
|
||||
explicit Time(double);
|
||||
|
||||
Time(int year, int month, int day,
|
||||
int hour = 0, int min = 0, int sec = 0,
|
||||
int usec = 0);
|
||||
|
||||
//! Copy constructor
|
||||
Time(const Time&);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Operators
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Conversion
|
||||
operator bool() const;
|
||||
operator time_t() const;
|
||||
|
||||
//! Assignment
|
||||
Time& operator=(const struct timeval& t);
|
||||
Time& operator=(struct timeval* t);
|
||||
Time& operator=(time_t t);
|
||||
Time& operator=(double t);
|
||||
|
||||
//! Arithmetic
|
||||
Time operator+(const TimeSpan&) const;
|
||||
Time operator-(const TimeSpan&) const;
|
||||
TimeSpan operator-(const Time&) const;
|
||||
|
||||
Time& operator+=(const TimeSpan&);
|
||||
Time& operator-=(const TimeSpan&);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Sets the time
|
||||
Time& set(int year, int month, int day,
|
||||
int hour, int min, int sec,
|
||||
int usec);
|
||||
|
||||
//! Sets the time with yday intepreted as the days since January 1st
|
||||
//! (0-365)
|
||||
Time& set2(int year, int yday,
|
||||
int hour, int min, int sec,
|
||||
int usec);
|
||||
|
||||
//! Fill the parameters with the currently set time values
|
||||
//! @return The error flag
|
||||
bool get(int *year, int *month = nullptr, int *day = nullptr,
|
||||
int *hour = nullptr, int *min = nullptr, int *sec = nullptr,
|
||||
int *usec = nullptr) const;
|
||||
|
||||
//! Fill the parameters with the currently set time values with yday
|
||||
//! set to the days since January 1st (0-365)
|
||||
//! @return The error flag
|
||||
bool get2(int *year, int *yday = nullptr,
|
||||
int *hour = nullptr, int *min = nullptr, int *sec = nullptr,
|
||||
int *usec = nullptr) const;
|
||||
|
||||
//! Returns the current localtime
|
||||
static Time LocalTime();
|
||||
|
||||
/**
|
||||
* @return A string containing the local time zone name/abbreviation
|
||||
*/
|
||||
static std::string LocalTimeZone();
|
||||
|
||||
//! Returns the current gmtime
|
||||
static Time UTC();
|
||||
|
||||
//! Alias for UTC()
|
||||
static Time GMT();
|
||||
|
||||
/** Creates a time from the year and the day of the year
|
||||
@param year The year, including the century (for example, 1988)
|
||||
@param year_day The day of the year [0..365]
|
||||
@return The time value
|
||||
*/
|
||||
static Time FromYearDay(int year, int year_day);
|
||||
|
||||
/**
|
||||
* @return The offset from UTC/GMT time to local time, essentially
|
||||
* localtime minus GMT.
|
||||
*/
|
||||
TimeSpan localTimeZoneOffset() const;
|
||||
|
||||
//! Saves the current localtime in the calling object
|
||||
Time &localtime();
|
||||
|
||||
//! Saves the current gmtime in the calling object
|
||||
Time &utc();
|
||||
|
||||
//! Alias for utc()
|
||||
Time &gmt();
|
||||
|
||||
//! Converts the time to localtime
|
||||
Time toLocalTime() const;
|
||||
|
||||
//! Converts the time to gmtime
|
||||
Time toUTC() const;
|
||||
|
||||
//! Alias for toUTC()
|
||||
Time toGMT() const;
|
||||
|
||||
//! Returns whether the date is valid or not
|
||||
bool valid() const;
|
||||
|
||||
/** Converts the time to string using format fmt.
|
||||
@param fmt The format string can contain any specifiers
|
||||
as allowed for strftime. Additional the '%f'
|
||||
specifier is replaced by the fraction of the seconds.
|
||||
Example:
|
||||
toString("%FT%T.%fZ") = "1970-01-01T00:00:00.0000Z"
|
||||
@return A formatted string
|
||||
*/
|
||||
std::string toString(const char* fmt) const;
|
||||
|
||||
/**
|
||||
* Converts the time to a string using the ISO time description
|
||||
* @return A formatted string
|
||||
*/
|
||||
std::string iso() const;
|
||||
|
||||
/**
|
||||
* Converts a string into a time representation.
|
||||
* @param str The string representation of the time
|
||||
* @param fmt The format string containing the conversion
|
||||
* specification (-> toString)
|
||||
* @return The conversion result
|
||||
*/
|
||||
bool fromString(const char* str, const char* fmt);
|
||||
|
||||
/**
|
||||
* Converts a string into a time representation.
|
||||
* @param str The string representation of the time
|
||||
* @return The conversion result
|
||||
*/
|
||||
bool fromString(const char* str);
|
||||
|
||||
/**
|
||||
* Converts a string into a time representation.
|
||||
* @param str The string representation of the time
|
||||
* @return The conversion result
|
||||
*/
|
||||
bool fromString(const std::string &str);
|
||||
|
||||
/**
|
||||
* Static method to create a time value from a string.
|
||||
* The parameters are the same as in Time::fromString.
|
||||
*/
|
||||
static Time FromString(const char* str, const char* fmt);
|
||||
|
||||
/**
|
||||
* Static method to convert a time from a string without
|
||||
* an explicit format.
|
||||
* @param str The string representation of the time.
|
||||
* @return None if conversion failed, a valid instance otherwise.
|
||||
*/
|
||||
static OPT(Time) FromString(const char* str);
|
||||
|
||||
/**
|
||||
* Convenience method for fromString(const char*).
|
||||
*/
|
||||
static OPT(Time) FromString(const std::string &str);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
66
include/seiscomp/core/defs.h
Normal file
66
include/seiscomp/core/defs.h
Normal file
@ -0,0 +1,66 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_DEFS_H
|
||||
#define SEISCOMP_CORE_DEFS_H
|
||||
|
||||
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct SmartPointer {
|
||||
typedef ::boost::intrusive_ptr<T> Impl;
|
||||
};
|
||||
|
||||
|
||||
template <typename B, typename D>
|
||||
struct isTypeOf {
|
||||
bool operator()(B*& base) {
|
||||
return base->typeInfo().isTypeOf(D::TypeInfo());
|
||||
}
|
||||
|
||||
bool operator()(boost::intrusive_ptr<B>& base) {
|
||||
return base->typeInfo().isTypeOf(D::TypeInfo());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define TYPEDEF_SMARTPOINTER(classname) \
|
||||
typedef Seiscomp::Core::SmartPointer<classname>::Impl classname##Ptr
|
||||
|
||||
#define TYPEDEF_CONST_SMARTPOINTER(classname) \
|
||||
typedef Seiscomp::Core::SmartPointer<const classname>::Impl classname##CPtr
|
||||
|
||||
#define DEFINE_SMARTPOINTER(classname) \
|
||||
class classname; \
|
||||
TYPEDEF_SMARTPOINTER(classname); \
|
||||
TYPEDEF_CONST_SMARTPOINTER(classname)
|
||||
|
||||
|
||||
#endif
|
245
include/seiscomp/core/enumeration.h
Normal file
245
include/seiscomp/core/enumeration.h
Normal file
@ -0,0 +1,245 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_ENUMERATION_H
|
||||
#define SEISCOMP_CORE_ENUMERATION_H
|
||||
|
||||
|
||||
#include <seiscomp/core/io.h>
|
||||
|
||||
#include <ostream>
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Enumeration {
|
||||
public:
|
||||
virtual ~Enumeration();
|
||||
|
||||
/**
|
||||
* Converts an enumeration to its string representation
|
||||
* @return The enumeration value string
|
||||
*/
|
||||
virtual const char *toString() const = 0;
|
||||
|
||||
/**
|
||||
* Converts a string to an enumeration value.
|
||||
* @param str The name of the enumeration value. This name is
|
||||
* case sensitive.
|
||||
* @return The result of the conversion
|
||||
*/
|
||||
virtual bool fromString(const std::string &str) = 0;
|
||||
|
||||
/**
|
||||
* Converts an enumeration value to an integer
|
||||
* @return The integer value
|
||||
*/
|
||||
virtual int toInt() const = 0;
|
||||
|
||||
/**
|
||||
* Converts an integer to an enumeration value
|
||||
* @param value The integer value to be converted
|
||||
* @return The result of the conversion
|
||||
*/
|
||||
virtual bool fromInt(int value) = 0;
|
||||
};
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief An enumeration class that supports string conversion and
|
||||
* \brief serialization
|
||||
*
|
||||
* Native enumerations are difficult to serialize in string based
|
||||
* archives like XML. This class implements automatic string
|
||||
* conversion based on a name table created while compile time.
|
||||
* To create an enumeration the preprocessor macros MAKEENUM should
|
||||
* be used.
|
||||
* MAKEENUM(Name, ValueList, NameList)
|
||||
* \param Name The name of the enumeration
|
||||
* \param ValueList The list of values created with EVALUES
|
||||
* \param NameList The list of names created with ENAMES
|
||||
* \code
|
||||
* MAKEENUM(Type,
|
||||
* EVALUES(
|
||||
* AUTOMATIC,
|
||||
* MANUAL
|
||||
* ),
|
||||
* ENAMES(
|
||||
* "automatic",
|
||||
* "manual"
|
||||
* )
|
||||
* );
|
||||
* \endcode
|
||||
*
|
||||
* The above example expands to:
|
||||
* \code
|
||||
* enum EType { AUTOMATIC = 0x00, MANUAL, ETypeQuantity };
|
||||
* class ETypeNames {
|
||||
* public:
|
||||
* static const char* name(int i) {
|
||||
* static const char* names[] = { "automatic", "manual" };
|
||||
* return names[i];
|
||||
* }
|
||||
* };
|
||||
* typedef Enum<EType, AUTOMATIC, ETypeQuantity, ETypeNames> Type;
|
||||
* \endcode
|
||||
*
|
||||
* The class Type can be used like native enumerations.
|
||||
* \code
|
||||
* Type value = AUTOMATIC;
|
||||
* assert(value == AUTOMATIC);
|
||||
*
|
||||
* printf("value = %s", value.toString());
|
||||
* value.fromString("manual"); // enumeration names are case sensitive
|
||||
* assert(value == MANUAL);
|
||||
* \endcode
|
||||
*
|
||||
* NOTE: Because SWIG does not support nested classes (version 1.3.27)
|
||||
* the MAKENUM macro should no be used inside of class definitions.
|
||||
* However, in C++ it can be placed nearly anywhere.
|
||||
*/
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
class Enum : public Enumeration {
|
||||
// ------------------------------------------------------------------
|
||||
// Typetraits
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
typedef ENUMTYPE Type;
|
||||
typedef NAMES NameDispatcher;
|
||||
static const ENUMTYPE First = ENUMTYPE(0);
|
||||
static const ENUMTYPE End = ENUMTYPE(END - 1);
|
||||
static const ENUMTYPE Quantity = ENUMTYPE(END - 0);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Enum(ENUMTYPE value = ENUMTYPE(0));
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
operator ENUMTYPE() const;
|
||||
|
||||
bool operator==(ENUMTYPE value) const;
|
||||
bool operator!=(ENUMTYPE value) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive &ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Conversion
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
const char *toString() const override;
|
||||
bool fromString(const std::string &str) override;
|
||||
|
||||
int toInt() const override;
|
||||
bool fromInt(int value) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
ENUMTYPE _value;
|
||||
};
|
||||
|
||||
|
||||
#define ENUMNAME(Name, ...) \
|
||||
class E##Name##Names { \
|
||||
public: \
|
||||
E##Name##Names() {} \
|
||||
static const char* name(int i) { \
|
||||
static const char* names[] = { __VA_ARGS__ }; \
|
||||
return names[i]; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ENUMWRAPPERCLASS(Name) Seiscomp::Core::Enum<E##Name, E##Name##Quantity, E##Name##Names>
|
||||
|
||||
#define ENUMX(Name, ...) \
|
||||
enum E##Name { \
|
||||
__VA_ARGS__, \
|
||||
E##Name##Quantity \
|
||||
}; \
|
||||
class E##Name##Names
|
||||
|
||||
#define ENUMXNAMES(Name, ...) \
|
||||
ENUMNAME(Name, __VA_ARGS__)
|
||||
|
||||
|
||||
#define EVALUES(...) __VA_ARGS__
|
||||
#define ENAMES(...) __VA_ARGS__
|
||||
|
||||
#define PREPAREENUM(Name, DEFS, NAMES) \
|
||||
ENUMX(Name, DEFS); \
|
||||
ENUMXNAMES(Name, NAMES)
|
||||
|
||||
#define MAKEENUM(Name, DEFS, NAMES) \
|
||||
ENUMX(Name, DEFS); \
|
||||
ENUMXNAMES(Name, NAMES); \
|
||||
typedef ENUMWRAPPERCLASS(Name) Name
|
||||
|
||||
|
||||
#include <seiscomp/core/enumeration.inl>
|
||||
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &os, const Enumeration &e) {
|
||||
os << e.toString();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline std::ostream &operator<<(std::ostream &os, const Enum<ENUMTYPE, END, NAMES> &e) {
|
||||
os << e.toString();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace fmt {
|
||||
|
||||
template <>
|
||||
struct formatter<Seiscomp::Core::Enumeration> : ostream_formatter {};
|
||||
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
struct formatter<Seiscomp::Core::Enum<ENUMTYPE, END, NAMES>> : ostream_formatter {};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
130
include/seiscomp/core/enumeration.inl
Normal file
130
include/seiscomp/core/enumeration.inl
Normal file
@ -0,0 +1,130 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline Enum<ENUMTYPE, END, NAMES>::Enum(ENUMTYPE value)
|
||||
: _value(value) {
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline Enum<ENUMTYPE, END, NAMES>::operator ENUMTYPE () const {
|
||||
return _value;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline void Enum<ENUMTYPE, END, NAMES>::serialize(Archive& ar) {
|
||||
std::string str;
|
||||
if ( ar.isReading() ) {
|
||||
ar.read(str);
|
||||
ar.setValidity(fromString(str));
|
||||
}
|
||||
else {
|
||||
str = NAMES::name(int(_value)-int(0));
|
||||
ar.write(str);
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline bool
|
||||
Enum<ENUMTYPE, END, NAMES>::operator==(ENUMTYPE value) const {
|
||||
return value == _value;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline bool
|
||||
Enum<ENUMTYPE, END, NAMES>::operator!=(ENUMTYPE value) const {
|
||||
return value != _value;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline const char* Enum<ENUMTYPE, END, NAMES>::toString() const {
|
||||
return NAMES::name(_value-0);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline bool
|
||||
Enum<ENUMTYPE, END, NAMES>::fromString(const std::string& str) {
|
||||
int index = int(0);
|
||||
|
||||
while( str != std::string(NAMES::name(index-0)) ) {
|
||||
++index;
|
||||
if ( index >= int(END) )
|
||||
return false;
|
||||
}
|
||||
|
||||
_value = static_cast<ENUMTYPE>(index);
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline int Enum<ENUMTYPE, END, NAMES>::toInt() const {
|
||||
return _value;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
inline bool
|
||||
Enum<ENUMTYPE, END, NAMES>::fromInt(int v) {
|
||||
if ( v < int(0) || v >= int(END) )
|
||||
return false;
|
||||
|
||||
_value = static_cast<ENUMTYPE>(v);
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
121
include/seiscomp/core/exceptions.h
Normal file
121
include/seiscomp/core/exceptions.h
Normal file
@ -0,0 +1,121 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_EXCEPTIONS_H
|
||||
#define SEISCOMP_CORE_EXCEPTIONS_H
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API GeneralException : public std::exception {
|
||||
public:
|
||||
GeneralException();
|
||||
GeneralException( const std::string& str);
|
||||
|
||||
virtual ~GeneralException() throw();
|
||||
|
||||
virtual const char* what( void ) const throw();
|
||||
|
||||
private:
|
||||
std::string _descr;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API MemoryException : public GeneralException {
|
||||
public:
|
||||
MemoryException();
|
||||
MemoryException(std::string what);
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API StreamException : public GeneralException {
|
||||
public:
|
||||
StreamException();
|
||||
StreamException(std::string what);
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API EndOfStreamException : public StreamException {
|
||||
public:
|
||||
EndOfStreamException();
|
||||
EndOfStreamException(std::string what);
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API TypeConversionException : public GeneralException {
|
||||
public:
|
||||
TypeConversionException();
|
||||
TypeConversionException(const std::string& str);
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API OverflowException : public GeneralException {
|
||||
public:
|
||||
OverflowException();
|
||||
OverflowException(const std::string& str);
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API UnderflowException : public GeneralException {
|
||||
public:
|
||||
UnderflowException();
|
||||
UnderflowException(const std::string& str);
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ValueException : public GeneralException {
|
||||
public:
|
||||
ValueException();
|
||||
ValueException(const std::string& str);
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API TypeException : public GeneralException {
|
||||
public:
|
||||
TypeException();
|
||||
TypeException(const std::string& str);
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ClassNotFound : public GeneralException {
|
||||
public:
|
||||
ClassNotFound();
|
||||
ClassNotFound(const std::string& str);
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API DuplicateClassname : public GeneralException {
|
||||
public:
|
||||
DuplicateClassname();
|
||||
DuplicateClassname(const std::string& str);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
241
include/seiscomp/core/factory.h
Normal file
241
include/seiscomp/core/factory.h
Normal file
@ -0,0 +1,241 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_FACTORY_H
|
||||
#define SEISCOMP_CORE_FACTORY_H
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "metaobject.h"
|
||||
#include "rtti.h"
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
namespace Generic {
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief Template based class factory interface
|
||||
|
||||
Class factories are build upon polymorphic types.
|
||||
In order to provide an generalized factory interface, a template
|
||||
class is used to implement factories for different class hierarchies.
|
||||
Objects are created by a classname.
|
||||
|
||||
The current implementation sits on top of a custom RTTI implementation.
|
||||
A classname in the factory is the same as the one defined by the RTTI
|
||||
object. One could think of an implementation where different names could
|
||||
be useful. Therefore the static method getClassName(const T*) has been
|
||||
implemented. It does not call (T*)->className() but uses its own
|
||||
dictionaries to fetch the classname.
|
||||
|
||||
To create an object, use the following code
|
||||
\code
|
||||
ClassFactoryInterface<MyBaseClassType>::create("MyClassName");
|
||||
\endcode
|
||||
*/
|
||||
template <typename ROOT_TYPE>
|
||||
class ClassFactoryInterface {
|
||||
public:
|
||||
//! The type that represents the root class of the hierarchie.
|
||||
using RootType = ROOT_TYPE;
|
||||
using ClassPool = std::map<std::string, ClassFactoryInterface<ROOT_TYPE>*>;
|
||||
using ClassNames = std::map<const RTTI*, std::string>;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
//! C'tor
|
||||
ClassFactoryInterface(const RTTI *typeInfo,
|
||||
const MetaObject *meta,
|
||||
bool reregister = false);
|
||||
|
||||
public:
|
||||
//! D'tor
|
||||
virtual ~ClassFactoryInterface();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Creates an instance of the class with the passed in name
|
||||
static ROOT_TYPE* Create(const char *className);
|
||||
static ROOT_TYPE* Create(const std::string &className);
|
||||
|
||||
//! Returns the registered classname for an object
|
||||
static const char* ClassName(const ROOT_TYPE *object);
|
||||
|
||||
//! Returns the registered classname for a type
|
||||
static const char* ClassName(const RTTI *rtti);
|
||||
|
||||
//! Looks up a class factory for a given class name
|
||||
static ClassFactoryInterface* FindByClassName(const char *className);
|
||||
|
||||
static bool IsTypeOf(const char *baseName, const char *derivedName);
|
||||
|
||||
//! Returns the number of registered classes
|
||||
static unsigned int NumberOfRegisteredClasses();
|
||||
|
||||
//! Returns the name of the class (as given during construction) which can be created
|
||||
//! by this factory
|
||||
const char* className() const;
|
||||
|
||||
//! Returns the class id for the objects the factory can create
|
||||
const RTTI* typeInfo() const;
|
||||
|
||||
//! Returns the meta object for the objects the factory can create
|
||||
const MetaObject *meta() const;
|
||||
|
||||
//! Derived classes override this method to do the actual creation
|
||||
virtual ROOT_TYPE* create() const = 0;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
static ClassPool &Classes();
|
||||
static ClassNames &Names();
|
||||
|
||||
//! Adds a factory to the classpool
|
||||
//! \return whether the factory has been added or not
|
||||
static bool RegisterFactory(ClassFactoryInterface *factory, bool reregister = false);
|
||||
|
||||
//! Removes a factory from the classpool
|
||||
//! \return whether the factory has been removed or not
|
||||
static bool UnregisterFactory(ClassFactoryInterface *factory);
|
||||
|
||||
|
||||
private:
|
||||
const RTTI *_typeInfo;
|
||||
const MetaObject *_meta;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#define IMPLEMENT_CLASSFACTORY(BaseClass, APIDef) \
|
||||
template class APIDef Seiscomp::Core::Generic::ClassFactoryInterface<BaseClass>
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief Template based class factory for an abstract class
|
||||
|
||||
The class factory for an abstract class of a class hierarchie.
|
||||
It only registeres the root classname but does not create
|
||||
an object.
|
||||
*/
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
class AbstractClassFactory : public ClassFactoryInterface<ROOT_TYPE> {
|
||||
public:
|
||||
//! The type that represents the actual polymorphic class.
|
||||
typedef TYPE Type;
|
||||
|
||||
public:
|
||||
AbstractClassFactory(const char *);
|
||||
|
||||
protected:
|
||||
//! Always returns nullptr
|
||||
ROOT_TYPE *create() const;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief Template based class factory
|
||||
|
||||
Each polymorphic type must be registered with the class factory.
|
||||
This is done via a simple declaration:
|
||||
\code
|
||||
Factory<MyBaseClassType,MyClassType> MyFactory("MyClassName");
|
||||
\endcode
|
||||
|
||||
It is however recommended that the REGISTER_CLASS macro is used.
|
||||
\code
|
||||
REGISTER_CLASS(MyClass)
|
||||
\endcode
|
||||
*/
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
class ClassFactory : public ClassFactoryInterface<ROOT_TYPE> {
|
||||
public:
|
||||
//! The type that represents the actual polymorphic class.
|
||||
typedef TYPE Type;
|
||||
|
||||
public:
|
||||
ClassFactory(const char *, bool reregister = false);
|
||||
|
||||
protected:
|
||||
//! The actual creation
|
||||
ROOT_TYPE* create() const;
|
||||
};
|
||||
|
||||
|
||||
#define REGISTER_ABSTRACT_CLASS_VAR(BaseClass, Class) \
|
||||
Seiscomp::Core::Generic::AbstractClassFactory<BaseClass, Class> __##Class##Factory__(#Class)
|
||||
|
||||
#define REGISTER_ABSTRACT_CLASS(BaseClass, Class) \
|
||||
static REGISTER_ABSTRACT_CLASS_VAR(BaseClass, Class)
|
||||
|
||||
#define REGISTER_CLASS_VAR(BaseClass, Class) \
|
||||
Seiscomp::Core::Generic::ClassFactory<BaseClass, Class> __##Class##Factory__(#Class, false)
|
||||
|
||||
#define REGISTER_CLASS(BaseClass, Class) \
|
||||
static REGISTER_CLASS_VAR(BaseClass, Class)
|
||||
|
||||
#define REREGISTER_CLASS_VAR(BaseClass, Class) \
|
||||
Seiscomp::Core::Generic::ClassFactory<BaseClass, Class> __##Class##Factory__(#Class, true)
|
||||
|
||||
#define REREGISTER_CLASS(BaseClass, Class) \
|
||||
static REREGISTER_CLASS_VAR(BaseClass, Class)
|
||||
|
||||
#define DECLARE_CLASSFACTORY_FRIEND(BaseClass, Class) \
|
||||
friend class Seiscomp::Core::Generic::ClassFactory<BaseClass, Class>
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#include "factory.inl"
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
61
include/seiscomp/core/factory.inl
Normal file
61
include/seiscomp/core/factory.inl
Normal file
@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
AbstractClassFactory<ROOT_TYPE, TYPE>::AbstractClassFactory(const char*)
|
||||
: ClassFactoryInterface<ROOT_TYPE>(&TYPE::TypeInfo(), TYPE::Meta())
|
||||
{
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
ROOT_TYPE* AbstractClassFactory<ROOT_TYPE, TYPE>::create() const {
|
||||
return nullptr;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
ClassFactory<ROOT_TYPE, TYPE>::ClassFactory(const char*, bool reregister)
|
||||
: ClassFactoryInterface<ROOT_TYPE>(&TYPE::TypeInfo(), TYPE::Meta(), reregister)
|
||||
{
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE, typename TYPE>
|
||||
ROOT_TYPE* ClassFactory<ROOT_TYPE, TYPE>::create() const {
|
||||
return new TYPE();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
257
include/seiscomp/core/factory.ipp
Normal file
257
include/seiscomp/core/factory.ipp
Normal file
@ -0,0 +1,257 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
namespace Generic {
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
ClassFactoryInterface<ROOT_TYPE>::ClassFactoryInterface(const RTTI *typeInfo,
|
||||
const MetaObject *meta,
|
||||
bool reregister)
|
||||
: _typeInfo(typeInfo)
|
||||
, _meta(meta) {
|
||||
// while construction the interface will be added
|
||||
// to the classpool
|
||||
RegisterFactory(this, reregister);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
ClassFactoryInterface<ROOT_TYPE>::~ClassFactoryInterface() {
|
||||
// remove the Factory from the classpool
|
||||
UnregisterFactory(this);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
ROOT_TYPE* ClassFactoryInterface<ROOT_TYPE>::Create(const char *className) {
|
||||
ClassFactoryInterface<ROOT_TYPE> *factoryInterface = FindByClassName(className);
|
||||
if ( factoryInterface ) {
|
||||
return factoryInterface->create();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool ClassFactoryInterface<ROOT_TYPE>::IsTypeOf(const char *baseName, const char *derivedName) {
|
||||
ClassFactoryInterface<ROOT_TYPE> *derivedFactory = FindByClassName(derivedName);
|
||||
if ( !derivedFactory ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ClassFactoryInterface<ROOT_TYPE> *baseFactory = FindByClassName(baseName);
|
||||
if ( !baseFactory ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return derivedFactory->typeInfo()->isTypeOf(*baseFactory->typeInfo());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
ROOT_TYPE *ClassFactoryInterface<ROOT_TYPE>::Create(const std::string &className) {
|
||||
return Create(className.c_str());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
const char *ClassFactoryInterface<ROOT_TYPE>::ClassName(const ROOT_TYPE *object) {
|
||||
ClassNames::iterator it = Names().find(&object->typeInfo());
|
||||
return it == Names().end() ? nullptr : (*it).second.c_str();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
const char *ClassFactoryInterface<ROOT_TYPE>::ClassName(const RTTI *info) {
|
||||
ClassNames::iterator it = Names().find(info);
|
||||
return it == Names().end() ? nullptr : (*it).second.c_str();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
ClassFactoryInterface<ROOT_TYPE> *ClassFactoryInterface<ROOT_TYPE>::FindByClassName(const char *className) {
|
||||
if ( !className )
|
||||
return nullptr;
|
||||
|
||||
typename ClassPool::iterator it = Classes().find(className);
|
||||
if ( it == Classes().end() )
|
||||
return nullptr;
|
||||
|
||||
return (*it).second;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
unsigned int ClassFactoryInterface<ROOT_TYPE>::NumberOfRegisteredClasses() {
|
||||
return static_cast<unsigned int>(Classes().size());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
const char *ClassFactoryInterface<ROOT_TYPE>::className() const {
|
||||
return _typeInfo->className();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
const RTTI *ClassFactoryInterface<ROOT_TYPE>::typeInfo() const {
|
||||
return _typeInfo;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
const MetaObject *ClassFactoryInterface<ROOT_TYPE>::meta() const {
|
||||
return _meta;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
typename ClassFactoryInterface<ROOT_TYPE>::ClassPool &ClassFactoryInterface<ROOT_TYPE>::Classes() {
|
||||
static typename ClassFactoryInterface<ROOT_TYPE>::ClassPool *classes = new typename ClassFactoryInterface<ROOT_TYPE>::ClassPool;
|
||||
return *classes;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
typename ClassFactoryInterface<ROOT_TYPE>::ClassNames &ClassFactoryInterface<ROOT_TYPE>::Names() {
|
||||
static typename ClassFactoryInterface<ROOT_TYPE>::ClassNames* names = new typename ClassFactoryInterface<ROOT_TYPE>::ClassNames;
|
||||
return *names;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool ClassFactoryInterface<ROOT_TYPE>::RegisterFactory(ClassFactoryInterface<ROOT_TYPE> *factory, bool reregister) {
|
||||
if ( !factory ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !reregister ) {
|
||||
if ( Classes().find(factory->className()) != Classes().end() ) {
|
||||
throw DuplicateClassname(factory->className());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Classes()[factory->className()] = factory;
|
||||
Names()[factory->typeInfo()] = factory->className();
|
||||
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ROOT_TYPE>
|
||||
bool ClassFactoryInterface<ROOT_TYPE>::UnregisterFactory(ClassFactoryInterface<ROOT_TYPE> *factory) {
|
||||
if ( !factory ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
typename ClassPool::iterator it = Classes().find(factory->className());
|
||||
if ( it == Classes().end() ) {
|
||||
// the factory has not been registered already
|
||||
return false;
|
||||
}
|
||||
|
||||
Classes().erase(it);
|
||||
|
||||
typename ClassNames::iterator it_names = Names().find(factory->typeInfo());
|
||||
if ( it_names != Names().end() ) {
|
||||
Names().erase(it_names);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
}
|
160
include/seiscomp/core/genericmessage.h
Normal file
160
include/seiscomp/core/genericmessage.h
Normal file
@ -0,0 +1,160 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_GENERICMESSAGE_H
|
||||
#define SEISCOMP_CORE_GENERICMESSAGE_H
|
||||
|
||||
|
||||
#include <seiscomp/core/message.h>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
class GenericMessage : public ::Seiscomp::Core::Message {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
using AttachmentType = T;
|
||||
using AttachmentList = std::list<typename Seiscomp::Core::SmartPointer<T>::Impl>;
|
||||
typedef typename AttachmentList::iterator iterator;
|
||||
typedef typename AttachmentList::const_iterator const_iterator;
|
||||
|
||||
DECLARE_SERIALIZATION;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
GenericMessage();
|
||||
|
||||
//! Destructor
|
||||
~GenericMessage();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Attaches an object to the message
|
||||
* @param attachment A pointer to the object
|
||||
* @retval true The operation was successfull and the object has been attached properly
|
||||
* @retval false The object is nullptr or the object has been attached already
|
||||
*/
|
||||
bool attach(AttachmentType* attachment);
|
||||
bool attach(typename Seiscomp::Core::SmartPointer<AttachmentType>::Impl& attachment);
|
||||
|
||||
/**
|
||||
* Detaches an already attached object from the message
|
||||
* @param object Pointer to an object in the messagebody
|
||||
* @retval true The object has been detached successfully
|
||||
* @retval false The object has not been attached before
|
||||
*/
|
||||
bool detach(AttachmentType* attachment);
|
||||
bool detach(typename Seiscomp::Core::SmartPointer<AttachmentType>::Impl& attachment);
|
||||
|
||||
/**
|
||||
* Detaches an object from the message
|
||||
* @param it The iterator pointing to the object
|
||||
* @retval true The object has been detached successfully
|
||||
* @retval false The iterator is invalid
|
||||
*/
|
||||
iterator detach(iterator it);
|
||||
|
||||
//! Removes all attachments from the message
|
||||
void clear();
|
||||
|
||||
//! Returns the iterators for begin and end of
|
||||
//! the attachment list
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
//! Implemented from baseclass
|
||||
bool empty() const;
|
||||
|
||||
/**
|
||||
* @return Returns the number of objects attached to a message
|
||||
*/
|
||||
int size() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
MessageIterator::Impl* iterImpl() const;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
AttachmentList _attachments;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#define DEFINE_MESSAGE_FOR(CLASS, TYPENAME, APIDef) \
|
||||
class APIDef TYPENAME : public ::Seiscomp::Core::GenericMessage<CLASS> { \
|
||||
DECLARE_SC_CLASS(TYPENAME); \
|
||||
}; \
|
||||
typedef ::Seiscomp::Core::SmartPointer<TYPENAME>::Impl TYPENAME##Ptr
|
||||
|
||||
#define IMPLEMENT_MESSAGE_FOR(CLASS, TYPENAME, NAME) \
|
||||
IMPLEMENT_SC_CLASS_DERIVED(TYPENAME, ::Seiscomp::Core::Message, NAME)
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#include <seiscomp/core/genericmessage.ipp>
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#endif
|
226
include/seiscomp/core/genericmessage.ipp
Normal file
226
include/seiscomp/core/genericmessage.ipp
Normal file
@ -0,0 +1,226 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
template <typename T>
|
||||
class MessageIteratorImplT : public MessageIterator::Impl {
|
||||
protected:
|
||||
MessageIteratorImplT(typename GenericMessage<T>::const_iterator it,
|
||||
typename GenericMessage<T>::const_iterator end)
|
||||
: _it(it), _end(end) {}
|
||||
|
||||
public:
|
||||
MessageIterator::Impl* clone() const {
|
||||
return new MessageIteratorImplT<T>(_it, _end);
|
||||
}
|
||||
|
||||
Seiscomp::Core::BaseObject* get() const {
|
||||
return _it == _end?nullptr:(*_it).get();
|
||||
}
|
||||
|
||||
void next() {
|
||||
++_it;
|
||||
}
|
||||
|
||||
private:
|
||||
typename GenericMessage<T>::const_iterator _it;
|
||||
typename GenericMessage<T>::const_iterator _end;
|
||||
|
||||
friend class GenericMessage<T>;
|
||||
};
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline GenericMessage<T>::GenericMessage() {
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline GenericMessage<T>::~GenericMessage() {
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
MessageIterator::Impl* GenericMessage<T>::iterImpl() const {
|
||||
return new MessageIteratorImplT<T>(_attachments.begin(), _attachments.end());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline bool GenericMessage<T>::attach(AttachmentType* attachment) {
|
||||
// When the object can be found in the objectlist
|
||||
// no double insertion will be done
|
||||
iterator it = std::find(_attachments.begin(), _attachments.end(), attachment);
|
||||
if ( it != _attachments.end() )
|
||||
return false;
|
||||
|
||||
_attachments.push_back(attachment);
|
||||
return true;
|
||||
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline bool GenericMessage<T>::attach(typename Seiscomp::Core::SmartPointer<AttachmentType>::Impl& attachment) {
|
||||
return attach(attachment.get());
|
||||
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline bool GenericMessage<T>::detach(AttachmentType* attachment) {
|
||||
iterator it = std::find(_attachments.begin(), _attachments.end(), attachment);
|
||||
if ( it == _attachments.end() )
|
||||
return false;
|
||||
|
||||
_attachments.erase(it);
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline bool GenericMessage<T>::detach(typename Seiscomp::Core::SmartPointer<AttachmentType>::Impl& attachment) {
|
||||
return detach(attachment.get());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline typename GenericMessage<T>::iterator GenericMessage<T>::detach(iterator it) {
|
||||
return _attachments.erase(it);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline void GenericMessage<T>::clear() {
|
||||
_attachments.clear();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline typename GenericMessage<T>::iterator GenericMessage<T>::begin() {
|
||||
return _attachments.begin();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline typename GenericMessage<T>::const_iterator GenericMessage<T>::begin() const {
|
||||
return _attachments.begin();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline typename GenericMessage<T>::iterator GenericMessage<T>::end() {
|
||||
return _attachments.end();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline typename GenericMessage<T>::const_iterator GenericMessage<T>::end() const {
|
||||
return _attachments.end();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline bool GenericMessage<T>::empty() const {
|
||||
return _attachments.empty();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline int GenericMessage<T>::size() const {
|
||||
return (int)_attachments.size();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline void GenericMessage<T>::serialize(Archive& ar) {
|
||||
Message::serialize(ar);
|
||||
ar & NAMED_OBJECT("", _attachments);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
135
include/seiscomp/core/genericrecord.h
Normal file
135
include/seiscomp/core/genericrecord.h
Normal file
@ -0,0 +1,135 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_GENERICRECORD_H
|
||||
#define SEISCOMP_CORE_GENERICRECORD_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <seiscomp/core/record.h>
|
||||
#include <seiscomp/core/array.h>
|
||||
#include <seiscomp/core/bitset.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(GenericRecord);
|
||||
|
||||
class SC_SYSTEM_CORE_API GenericRecord : public Record {
|
||||
DECLARE_SC_CLASS(GenericRecord);
|
||||
DECLARE_SERIALIZATION;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Default Constructor
|
||||
GenericRecord(Array::DataType dt = Array::DOUBLE, Hint h = DATA_ONLY);
|
||||
|
||||
//! Initializing Constructor
|
||||
GenericRecord(std::string net, std::string sta,
|
||||
std::string loc, std::string cha,
|
||||
Core::Time stime, double fsamp, int tqual = -1,
|
||||
Array::DataType dt = Array::DOUBLE,
|
||||
Hint h = DATA_ONLY);
|
||||
|
||||
//! Copy Constructor
|
||||
GenericRecord(const GenericRecord& rec);
|
||||
|
||||
//! Another Constructor
|
||||
GenericRecord(const Record& rec);
|
||||
|
||||
//! Destructor
|
||||
virtual ~GenericRecord();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Operators
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Assignment operator
|
||||
GenericRecord& operator=(const GenericRecord& rec);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Sets the sample frequency
|
||||
void setSamplingFrequency(double freq);
|
||||
|
||||
//! Returns the data samples if the data is available; otherwise 0
|
||||
Array* data();
|
||||
|
||||
//! Returns the data samples if the data is available; otherwise 0
|
||||
const Array* data() const;
|
||||
|
||||
//! Same as data()
|
||||
const Array* raw() const;
|
||||
|
||||
//! Returns the clipmask. The size of the clipmask matches the size
|
||||
//! of the data array and each element (bit) is set to one if the
|
||||
//! sample at the same index is clipped. The returned pointer is
|
||||
//! managed by this instance and must not be deleted. But it is safe
|
||||
//! to store it in a smart pointer.
|
||||
const BitSet *clipMask() const;
|
||||
|
||||
//! Sets the data sample array. The ownership goes over to the record.
|
||||
//! Note that this call will remove any clip mask set with previous
|
||||
//! calls.
|
||||
void setData(Array* data);
|
||||
|
||||
//! Sets the data sample array.
|
||||
//! Note that this call will remove any clip mask set with previous
|
||||
//! calls.
|
||||
void setData(int size, const void *data, Array::DataType datatype);
|
||||
|
||||
/**
|
||||
* @brief Sets the clip mask.
|
||||
* @param The bitset pointer which will be managed by this instance.
|
||||
*/
|
||||
void setClipMask(BitSet *clipMask);
|
||||
|
||||
//! Updates internal parameters caused by data updates
|
||||
void dataUpdated();
|
||||
|
||||
//! This method does nothing.
|
||||
void saveSpace() const;
|
||||
|
||||
//! Returns a deep copy of the calling object.
|
||||
Record* copy() const;
|
||||
|
||||
void read(std::istream &in);
|
||||
void write(std::ostream &out);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
ArrayPtr _data;
|
||||
BitSetPtr _clipMask;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
131
include/seiscomp/core/greensfunction.h
Normal file
131
include/seiscomp/core/greensfunction.h
Normal file
@ -0,0 +1,131 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_GREENSFUNCTION_H
|
||||
#define SEISCOMP_CORE_GREENSFUNCTION_H
|
||||
|
||||
|
||||
#include <seiscomp/core/array.h>
|
||||
#include <seiscomp/core/enumeration.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
MAKEENUM(
|
||||
GreensFunctionComponent,
|
||||
EVALUES(
|
||||
ZSS,
|
||||
ZDS,
|
||||
ZDD,
|
||||
RSS,
|
||||
RDS,
|
||||
RDD,
|
||||
TSS,
|
||||
TDS,
|
||||
ZEP,
|
||||
REP
|
||||
),
|
||||
ENAMES(
|
||||
"ZSS",
|
||||
"ZDS",
|
||||
"ZDD",
|
||||
"RSS",
|
||||
"RDS",
|
||||
"RDD",
|
||||
"TSS",
|
||||
"TDS",
|
||||
"ZEP",
|
||||
"REP"
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(GreensFunction);
|
||||
|
||||
class SC_SYSTEM_CORE_API GreensFunction : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(GreensFunction);
|
||||
DECLARE_SERIALIZATION;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
GreensFunction();
|
||||
GreensFunction(const std::string &model, double distance,
|
||||
double depth, double fsamp, double timeOffset);
|
||||
|
||||
virtual ~GreensFunction();
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setId(const std::string &id);
|
||||
const std::string &id() const;
|
||||
|
||||
void setModel(const std::string &model);
|
||||
const std::string &model() const;
|
||||
|
||||
void setDistance(double);
|
||||
double distance() const;
|
||||
|
||||
void setDepth(double);
|
||||
double depth() const;
|
||||
|
||||
void setSamplingFrequency(double);
|
||||
double samplingFrequency() const;
|
||||
|
||||
void setTimeOffset(double);
|
||||
double timeOffset() const;
|
||||
|
||||
//! Returns the length in seconds
|
||||
double length(GreensFunctionComponent) const;
|
||||
|
||||
void setData(GreensFunctionComponent, Array *);
|
||||
Array *data(GreensFunctionComponent) const;
|
||||
|
||||
void setData(int, Array *);
|
||||
Array *data(int) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Private members
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
std::string _id;
|
||||
std::string _model;
|
||||
double _distance;
|
||||
double _depth;
|
||||
double _samplingFrequency;
|
||||
double _timeOffset;
|
||||
ArrayPtr _components[GreensFunctionComponent::Quantity];
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
134
include/seiscomp/core/interfacefactory.h
Normal file
134
include/seiscomp/core/interfacefactory.h
Normal file
@ -0,0 +1,134 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_INTERFACEFACTORY_H
|
||||
#define SEISCOMP_CORE_INTERFACEFACTORY_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
namespace Generic {
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief Template based service factory interface
|
||||
|
||||
To create an object, use the following code
|
||||
\code
|
||||
InterfaceFactory::Create(servicename);
|
||||
\endcode
|
||||
*/
|
||||
template <typename T>
|
||||
class InterfaceFactoryInterface {
|
||||
public:
|
||||
typedef T Interface;
|
||||
typedef std::vector<InterfaceFactoryInterface<T>*> ServicePool;
|
||||
typedef std::vector<std::string> ServiceNames;
|
||||
|
||||
|
||||
protected:
|
||||
InterfaceFactoryInterface(const char *serviceName);
|
||||
|
||||
public:
|
||||
virtual ~InterfaceFactoryInterface();
|
||||
|
||||
|
||||
public:
|
||||
static T *Create(const char* serviceName);
|
||||
static T *Create(const std::string &serviceName);
|
||||
|
||||
static unsigned int ServiceCount();
|
||||
|
||||
static ServiceNames *Services();
|
||||
|
||||
static InterfaceFactoryInterface *Find(const char* serviceName);
|
||||
static InterfaceFactoryInterface *Find(const std::string &serviceName);
|
||||
|
||||
const std::string &serviceName() const;
|
||||
|
||||
virtual Interface *create() const = 0;
|
||||
|
||||
|
||||
private:
|
||||
static bool RegisterFactory(InterfaceFactoryInterface *factory);
|
||||
static bool UnregisterFactory(InterfaceFactoryInterface *factory);
|
||||
|
||||
static ServicePool &Pool();
|
||||
|
||||
private:
|
||||
std::string _serviceName;
|
||||
};
|
||||
|
||||
#define DEFINE_INTERFACE_FACTORY(Class) \
|
||||
typedef Seiscomp::Core::Generic::InterfaceFactoryInterface<Class> Class##Factory
|
||||
|
||||
#define DEFINE_TEMPLATE_INTERFACE_FACTORY(Class) \
|
||||
template <typename T> \
|
||||
struct Class##Factory : Seiscomp::Core::Generic::InterfaceFactoryInterface< Class<T> > {}
|
||||
|
||||
|
||||
#define IMPLEMENT_INTERFACE_FACTORY(Class, APIDef) \
|
||||
template class APIDef Seiscomp::Core::Generic::InterfaceFactoryInterface<Class>
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief Template based service factory
|
||||
*/
|
||||
template <typename T, typename TYPE>
|
||||
class InterfaceFactory : public InterfaceFactoryInterface<T> {
|
||||
public:
|
||||
//! The type that represents the actual polymorphic class.
|
||||
typedef TYPE Type;
|
||||
|
||||
public:
|
||||
InterfaceFactory(const char *serviceName)
|
||||
: InterfaceFactoryInterface<T>(serviceName) {}
|
||||
|
||||
public:
|
||||
//! The actual creation
|
||||
typename InterfaceFactoryInterface<T>::Interface* create() const { return new TYPE; }
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#define DECLARE_INTERFACEFACTORY_FRIEND(Interface, Class) \
|
||||
friend class Seiscomp::Core::Generic::InterfaceFactory<Interface, Class>
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
195
include/seiscomp/core/interfacefactory.ipp
Normal file
195
include/seiscomp/core/interfacefactory.ipp
Normal file
@ -0,0 +1,195 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
namespace Generic {
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
InterfaceFactoryInterface<T>::InterfaceFactoryInterface(const char *serviceName) {
|
||||
_serviceName = serviceName;
|
||||
RegisterFactory(this);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
InterfaceFactoryInterface<T>::~InterfaceFactoryInterface() {
|
||||
UnregisterFactory(this);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
T* InterfaceFactoryInterface<T>::Create(const char *serviceName) {
|
||||
InterfaceFactoryInterface* factoryInterface = Find(serviceName);
|
||||
if ( factoryInterface != nullptr )
|
||||
return factoryInterface->create();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
T* InterfaceFactoryInterface<T>::Create(const std::string &serviceName) {
|
||||
return Create(serviceName.c_str());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
unsigned int InterfaceFactoryInterface<T>::ServiceCount() {
|
||||
return Pool().size();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
typename InterfaceFactoryInterface<T>::ServiceNames*
|
||||
InterfaceFactoryInterface<T>::Services() {
|
||||
if ( ServiceCount() == 0 ) return nullptr;
|
||||
|
||||
ServiceNames* names = new ServiceNames;
|
||||
for ( typename ServicePool::iterator it = Pool().begin(); it != Pool().end(); ++it )
|
||||
names->push_back((*it)->serviceName());
|
||||
|
||||
return names;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
InterfaceFactoryInterface<T>*
|
||||
InterfaceFactoryInterface<T>::Find(const char *serviceName) {
|
||||
for ( typename ServicePool::iterator it = Pool().begin(); it != Pool().end(); ++it ) {
|
||||
if ( !strcmp((*it)->serviceName().c_str(), serviceName) ) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
InterfaceFactoryInterface<T>*
|
||||
InterfaceFactoryInterface<T>::Find(const std::string &serviceName) {
|
||||
for ( typename ServicePool::iterator it = Pool().begin(); it != Pool().end(); ++it ) {
|
||||
if ( (*it)->serviceName() == serviceName ) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
const std::string &InterfaceFactoryInterface<T>::serviceName() const {
|
||||
return _serviceName;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool InterfaceFactoryInterface<T>::RegisterFactory(InterfaceFactoryInterface *factory) {
|
||||
if ( factory == nullptr )
|
||||
return false;
|
||||
|
||||
if ( Find(factory->serviceName()) != nullptr )
|
||||
return false;
|
||||
|
||||
Pool().push_back(factory);
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool InterfaceFactoryInterface<T>::UnregisterFactory(InterfaceFactoryInterface *factory) {
|
||||
for ( typename ServicePool::iterator it = Pool().begin(); it != Pool().end(); ++it ) {
|
||||
if ( *it == factory ) {
|
||||
Pool().erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
typename InterfaceFactoryInterface<T>::ServicePool &InterfaceFactoryInterface<T>::Pool() {
|
||||
static ServicePool* pool = new ServicePool;
|
||||
return *pool;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
}
|
108
include/seiscomp/core/interruptible.h
Normal file
108
include/seiscomp/core/interruptible.h
Normal file
@ -0,0 +1,108 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_INTERRUPTIBLE_H
|
||||
#define SEISCOMP_CORE_INTERRUPTIBLE_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API OperationInterrupted : public GeneralException {
|
||||
public:
|
||||
OperationInterrupted(): GeneralException("operation interrupted") {}
|
||||
OperationInterrupted(const std::string& what): GeneralException(what) {}
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(InterruptibleObject);
|
||||
|
||||
/**
|
||||
* Classes that implement opterations, which may potentially take long time
|
||||
* and need to be interrupted by the user, should inherit from
|
||||
* InterruptibleObject.
|
||||
*
|
||||
* The inherited class is supposed to implement handleInterrupt(int sig),
|
||||
* which is being called when interrupt is requested.
|
||||
* This method is normally called from a signal handler, so it is not
|
||||
* allowed to throw any exceptions. Normally it
|
||||
* just sets a flag, and exception is thrown after returning from a signal
|
||||
* handler. For this purpose, the exception OperationInterrupted has been
|
||||
* defined. Note: according the POSIX standard, a flag that is set in a
|
||||
* signal handler should be of type 'volatile sig_atomic_t'.
|
||||
*
|
||||
* The main program should set up signal handler as follows:
|
||||
*
|
||||
* \code
|
||||
* void signalHandler(int signal) {
|
||||
* Seiscomp::Core::InterruptibleObject::Interrupt(signal);
|
||||
* }
|
||||
*
|
||||
* int main(int argc, char **argv) {
|
||||
* struct sigaction sa;
|
||||
* sa.sa_handler = signalHandler;
|
||||
* sa.sa_flags = 0;
|
||||
* sigemptyset(&sa.sa_mask);
|
||||
* sigaction(SIGINT, &sa, nullptr);
|
||||
* sigaction(SIGTERM, &sa, nullptr);
|
||||
*
|
||||
* // Optionally, disable SIGHUP, so it is not necessary
|
||||
* // to start the process with nohup.
|
||||
* sa.sa_handler = SIG_IGN;
|
||||
* sigaction(SIGHUP, &sa, nullptr);
|
||||
*
|
||||
* ...
|
||||
*
|
||||
* return 0
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API InterruptibleObject : public BaseObject {
|
||||
public:
|
||||
InterruptibleObject();
|
||||
virtual ~InterruptibleObject();
|
||||
|
||||
static void Interrupt(int sig);
|
||||
|
||||
|
||||
protected:
|
||||
virtual void handleInterrupt(int) = 0;
|
||||
|
||||
|
||||
private:
|
||||
static std::list<InterruptibleObject*> _registered;
|
||||
std::list<InterruptibleObject*>::iterator _link;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Core
|
||||
} // namespace Seiscomp
|
||||
|
||||
|
||||
#endif
|
||||
|
36
include/seiscomp/core/io.h
Normal file
36
include/seiscomp/core/io.h
Normal file
@ -0,0 +1,36 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SC_CORE_IO_H
|
||||
#define SC_CORE_IO_H
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
typedef Generic::Archive<BaseObject> Archive;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
172
include/seiscomp/core/message.h
Normal file
172
include/seiscomp/core/message.h
Normal file
@ -0,0 +1,172 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_MESSAGE_H
|
||||
#define SEISCOMP_CORE_MESSAGE_H
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
DEFINE_SMARTPOINTER(Message);
|
||||
|
||||
/**
|
||||
* The MessageIterator is an iterator that iterates over the objects
|
||||
* attached to a message. Not all message types support attachments
|
||||
* what resulted in a generic iterator concept. Each derived message
|
||||
* type that wants to implement its iteration has to provide an
|
||||
* implementation class derived from MessageType::Impl
|
||||
* The iterator protocol looks like this:
|
||||
* \code
|
||||
* for ( Iterator it = msg->iter(); *it != nullptr; ++it ) {
|
||||
* BaseObject* o = *it;
|
||||
* // do something with o
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API MessageIterator {
|
||||
public:
|
||||
//! Implementation class for a message iterator
|
||||
class Impl {
|
||||
public:
|
||||
virtual ~Impl() {}
|
||||
|
||||
//! Clones the iterator implementation
|
||||
virtual Impl* clone() const = 0;
|
||||
|
||||
//! Returns the current element
|
||||
virtual Seiscomp::Core::BaseObject* get() const = 0;
|
||||
|
||||
//! Go to the next element
|
||||
virtual void next() = 0;
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
MessageIterator();
|
||||
MessageIterator(const MessageIterator& iter);
|
||||
~MessageIterator();
|
||||
|
||||
protected:
|
||||
MessageIterator(Impl*);
|
||||
|
||||
public:
|
||||
Seiscomp::Core::BaseObject* get() const;
|
||||
|
||||
MessageIterator& operator=(const MessageIterator& it);
|
||||
Seiscomp::Core::BaseObject* operator*() const;
|
||||
|
||||
MessageIterator& operator++();
|
||||
MessageIterator& operator++(int);
|
||||
|
||||
private:
|
||||
Impl* _impl;
|
||||
|
||||
friend class Message;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Message : public BaseObject {
|
||||
DECLARE_SC_CLASS(Message);
|
||||
DECLARE_SERIALIZATION;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
//! Constructor
|
||||
Message();
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
~Message();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Returns an iterator to iterate through the attachments.
|
||||
* To filter a particular object type, a class typeinfo can
|
||||
* be used to do that.
|
||||
* E.g., to filter only object of type A (and derived), use
|
||||
* A::TypeInfo() as input parameter.
|
||||
* \code
|
||||
* MessageIterator it = msg->iter(A::TypeInfo());
|
||||
* while ( it.next() ) {
|
||||
* A* a = static_cast<A*>(*it);
|
||||
* }
|
||||
* \endcode
|
||||
* @param typeInfo The object type filter
|
||||
* @return The iterator
|
||||
*/
|
||||
MessageIterator iter() const;
|
||||
|
||||
/**
|
||||
* @return Returns the number of objects attached to a message
|
||||
*/
|
||||
virtual int size() const;
|
||||
|
||||
/**
|
||||
* Checks whether a message is empty or not.
|
||||
* @retval true The message is empty
|
||||
* @retval false The message is not empty
|
||||
*/
|
||||
virtual bool empty() const = 0;
|
||||
|
||||
/**
|
||||
* Erases the content of the message.
|
||||
*/
|
||||
virtual void clear() {}
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Returns an iterator implementation for a particular message.
|
||||
* This method has to be implemented in derived classes to provide
|
||||
* generic iteration.
|
||||
* @return The implementation.
|
||||
*/
|
||||
virtual MessageIterator::Impl* iterImpl() const;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#endif
|
377
include/seiscomp/core/metaobject.h
Normal file
377
include/seiscomp/core/metaobject.h
Normal file
@ -0,0 +1,377 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_METAOBJECT_H
|
||||
#define SEISCOMP_CORE_METAOBJECT_H
|
||||
|
||||
#include <seiscomp/core/rtti.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
#include <boost/any.hpp>
|
||||
|
||||
#include <complex>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
class BaseObject;
|
||||
|
||||
typedef boost::any MetaValue;
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
class SC_SYSTEM_CORE_API PropertyNotFoundException : public GeneralException {
|
||||
public:
|
||||
PropertyNotFoundException();
|
||||
PropertyNotFoundException(const std::string& str);
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
class SC_SYSTEM_CORE_API MetaEnum {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
MetaEnum();
|
||||
virtual ~MetaEnum();
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the number of keys in the enumeration
|
||||
virtual int keyCount() const = 0;
|
||||
|
||||
//! Returns the key name at a given index
|
||||
virtual const char *key(int index) const = 0;
|
||||
|
||||
virtual const char *valueToKey(int value) const = 0;
|
||||
virtual int keyToValue(const char *key) const = 0;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
class SC_SYSTEM_CORE_API MetaProperty {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
MetaProperty();
|
||||
MetaProperty(const std::string& name,
|
||||
const std::string& type,
|
||||
bool isArray,
|
||||
bool isClass,
|
||||
bool isIndex,
|
||||
bool isReference,
|
||||
bool isOptional,
|
||||
bool isEnum,
|
||||
const MetaEnum *enumeration = nullptr);
|
||||
|
||||
virtual ~MetaProperty();
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Initialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setInfo(const std::string& name,
|
||||
const std::string& type,
|
||||
bool isArray,
|
||||
bool isClass,
|
||||
bool isIndex,
|
||||
bool isReference,
|
||||
bool isOptional,
|
||||
bool isEnum,
|
||||
const MetaEnum *enumeration = nullptr);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
const std::string& name() const;
|
||||
const std::string& type() const;
|
||||
|
||||
//! Returns a meta enum description if this property
|
||||
//! is an enumeration
|
||||
const MetaEnum *enumerator() const;
|
||||
|
||||
bool isArray() const;
|
||||
bool isClass() const;
|
||||
bool isIndex() const;
|
||||
bool isReference() const;
|
||||
bool isEnum() const;
|
||||
bool isOptional() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Creates an instance of the properties class type
|
||||
virtual BaseObject *createClass() const;
|
||||
|
||||
//! Returns the number of elements in the array if isArray() is
|
||||
//! true, -1 otherwise
|
||||
virtual size_t arrayElementCount(const BaseObject *object) const;
|
||||
|
||||
//! Returns the object at position i, nullptr otherwise
|
||||
virtual BaseObject *arrayObject(BaseObject *object, int i) const;
|
||||
|
||||
//! Adds a child to an object.
|
||||
//! If the property is not an array type, nothing will be done
|
||||
//! and 'false' will be returned.
|
||||
virtual bool arrayAddObject(BaseObject *object, BaseObject *child) const;
|
||||
|
||||
//! Removes a child from an object at a given index.
|
||||
virtual bool arrayRemoveObject(BaseObject *object, int i) const;
|
||||
|
||||
//! Removes a child from an object.
|
||||
virtual bool arrayRemoveObject(BaseObject *object, BaseObject *child) const;
|
||||
|
||||
//! Writes a value to an objects property.
|
||||
//! Returns true when the value has been written, false otherwise
|
||||
//! Throws:
|
||||
//! PropertyNotFoundException: The property does not exist
|
||||
//! TypeException: The type of the property is not compatible with value
|
||||
virtual bool write(BaseObject *object, MetaValue value) const;
|
||||
|
||||
//! Writes a value (as string representation) to an objects property.
|
||||
//! Returns true when the value has been written, false otherwise
|
||||
//! Throws:
|
||||
//! PropertyNotFoundException: The property does not exist
|
||||
//! TypeException: The type of the property is not compatible with value
|
||||
virtual bool writeString(BaseObject *object, const std::string &value) const;
|
||||
|
||||
//! Reads a value from an objects property.
|
||||
//! The returned value can be empty (empty()) if the object
|
||||
//! does not have a corresponding property or the property
|
||||
//! is not set.
|
||||
//! Throws:
|
||||
//! PropertyNotFoundException: The property does not exist
|
||||
virtual MetaValue read(const BaseObject *object) const;
|
||||
|
||||
//! Reads a value from an objects property as string representation.
|
||||
//! The returned value can be empty (empty()) if the object
|
||||
//! does not have a corresponding property or the property
|
||||
//! is not set or the datatype does not support string conversion
|
||||
//! Throws:
|
||||
//! PropertyNotFoundException: The property does not exist
|
||||
virtual std::string readString(const BaseObject *object) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
std::string _name;
|
||||
std::string _type;
|
||||
bool _isArray;
|
||||
bool _isClass;
|
||||
bool _isIndex;
|
||||
bool _isReference;
|
||||
bool _isEnum;
|
||||
bool _isOptional;
|
||||
|
||||
const MetaEnum *_enumeration;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief A metaobject (class information and access) class
|
||||
|
||||
To implement it into custom classes, use the supported METAOBJECT
|
||||
macros.
|
||||
|
||||
\code
|
||||
class MyClass {
|
||||
DECLARE_METAOBJECT;
|
||||
...
|
||||
public:
|
||||
MyClass();
|
||||
...
|
||||
};
|
||||
\endcode
|
||||
|
||||
To implement the metaobject interface, another macro has to be used.
|
||||
\code
|
||||
IMPLEMENT_METAOBJECT(MyClass);
|
||||
\endcode
|
||||
*/
|
||||
typedef std::shared_ptr<MetaProperty> MetaPropertyHandle;
|
||||
|
||||
class SC_SYSTEM_CORE_API MetaObject {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
MetaObject(const RTTI *rtti, const MetaObject *base = nullptr);
|
||||
~MetaObject();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the corresponding RTTI object
|
||||
const RTTI *rtti() const;
|
||||
|
||||
//! Returns the base MetaObject if available
|
||||
const MetaObject *base() const;
|
||||
|
||||
//! Returns the number of properties set
|
||||
size_t propertyCount() const;
|
||||
|
||||
//! Returns the property at a given position
|
||||
const MetaProperty *property(size_t index) const;
|
||||
|
||||
//! Returns the property with a given name
|
||||
const MetaProperty *property(const std::string &name) const;
|
||||
|
||||
static const MetaObject *Find(const std::string &className);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
void clearProperties();
|
||||
|
||||
bool addProperty(const std::string &name, const std::string &type,
|
||||
bool isArray, bool isClass, bool isIndex,
|
||||
bool isReference, bool isOptional, bool isEnum,
|
||||
const MetaEnum *enumeration = nullptr);
|
||||
|
||||
bool addProperty(MetaPropertyHandle);
|
||||
|
||||
bool removeProperty(size_t index);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
const RTTI *_rtti;
|
||||
const MetaObject *_base;
|
||||
std::vector<MetaPropertyHandle> _properties;
|
||||
|
||||
using MetaObjectMap = std::map<std::string, const MetaObject*>;
|
||||
static MetaObjectMap _map;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<MetaObject> MetaObjectHandle;
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#define DECLARE_METAOBJECT_INTERFACE \
|
||||
public: \
|
||||
static const Seiscomp::Core::MetaObject *Meta(); \
|
||||
\
|
||||
virtual const Seiscomp::Core::MetaObject *meta() const
|
||||
|
||||
#define DECLARE_METAOBJECT_DERIVED_INTERFACE \
|
||||
public: \
|
||||
static const Seiscomp::Core::MetaObject *Meta(); \
|
||||
\
|
||||
virtual const Seiscomp::Core::MetaObject *meta() const override
|
||||
|
||||
#define DECLARE_METAOBJECT \
|
||||
DECLARE_METAOBJECT_DERIVED_INTERFACE; \
|
||||
protected: \
|
||||
class MetaObject : public Seiscomp::Core::MetaObject { \
|
||||
public: \
|
||||
MetaObject(const Seiscomp::Core::RTTI* rtti); \
|
||||
}
|
||||
|
||||
#define DECLARE_METAOBJECT_DERIVED \
|
||||
DECLARE_METAOBJECT_DERIVED_INTERFACE; \
|
||||
protected: \
|
||||
class MetaObject : public Seiscomp::Core::MetaObject { \
|
||||
public: \
|
||||
MetaObject(const Seiscomp::Core::RTTI* rtti, const Seiscomp::Core::MetaObject *base = nullptr); \
|
||||
}
|
||||
|
||||
#define IMPLEMENT_METAOBJECT_EMPTY_METHODS(CLASS) \
|
||||
const Seiscomp::Core::MetaObject *CLASS::Meta() { \
|
||||
return nullptr; \
|
||||
} \
|
||||
\
|
||||
const Seiscomp::Core::MetaObject *CLASS::meta() const { \
|
||||
return nullptr; \
|
||||
}
|
||||
|
||||
#define IMPLEMENT_METAOBJECT_METHODS(CLASS) \
|
||||
const Seiscomp::Core::MetaObject *CLASS::meta() const { \
|
||||
return Meta(); \
|
||||
}
|
||||
|
||||
|
||||
#define IMPLEMENT_METAOBJECT(CLASS) \
|
||||
IMPLEMENT_METAOBJECT_METHODS(CLASS) \
|
||||
const Seiscomp::Core::MetaObject *CLASS::Meta() { \
|
||||
static CLASS::MetaObject classMetaObject(&CLASS::TypeInfo()); \
|
||||
return &classMetaObject; \
|
||||
}
|
||||
|
||||
|
||||
#define IMPLEMENT_METAOBJECT_DERIVED(CLASS, BASECLASS) \
|
||||
IMPLEMENT_METAOBJECT_METHODS(CLASS) \
|
||||
const Seiscomp::Core::MetaObject *CLASS::Meta() { \
|
||||
static CLASS::MetaObject classMetaObject(&CLASS::TypeInfo(), BASECLASS::Meta()); \
|
||||
return &classMetaObject; \
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
375
include/seiscomp/core/metaproperty.h
Normal file
375
include/seiscomp/core/metaproperty.h
Normal file
@ -0,0 +1,375 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_METAPROPERTY_H
|
||||
#define SEISCOMP_CORE_METAPROPERTY_H
|
||||
|
||||
#include <seiscomp/core/metaobject.h>
|
||||
#include <seiscomp/core/strings.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
namespace Generic {
|
||||
|
||||
|
||||
class No { };
|
||||
class Yes { No no[2]; };
|
||||
|
||||
|
||||
template <typename T>
|
||||
Yes isOptionalTester(boost::optional<T>*);
|
||||
No isOptionalTester(void*);
|
||||
|
||||
|
||||
template <typename T>
|
||||
class is_optional {
|
||||
static T* t;
|
||||
|
||||
public:
|
||||
enum { value = sizeof(isOptionalTester(t)) == sizeof(Yes) };
|
||||
};
|
||||
|
||||
|
||||
template <typename T, int>
|
||||
struct remove_optional_helper {};
|
||||
|
||||
template <typename T>
|
||||
struct remove_optional_helper<T,0> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct remove_optional_helper<T,1> {
|
||||
typedef typename T::value_type type;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct remove_optional {
|
||||
typedef typename remove_optional_helper<T, is_optional<T>::value>::type type;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
class MetaEnumImpl : public MetaEnum {
|
||||
public:
|
||||
MetaEnumImpl() : MetaEnum() {}
|
||||
|
||||
public:
|
||||
int keyCount() const { return T::Quantity; }
|
||||
|
||||
//! Returns the key name at a given index
|
||||
const char *key(int index) const;
|
||||
|
||||
const char *valueToKey(int value) const;
|
||||
int keyToValue(const char *key) const;
|
||||
};
|
||||
|
||||
#define DECLARE_METAENUM(CLASS, var) Seiscomp::Core::MetaEnumImpl<CLASS> var
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline const char *MetaEnumImpl<T>::key(int index) const {
|
||||
return T::NameDispatcher::name(index);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline const char *MetaEnumImpl<T>::valueToKey(int value) const {
|
||||
T tmp;
|
||||
if ( !tmp.fromInt(value) )
|
||||
throw ValueException("value out of bounds");
|
||||
|
||||
return tmp.toString();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline int MetaEnumImpl<T>::keyToValue(const char *key) const {
|
||||
T tmp;
|
||||
if ( !tmp.fromString(key) )
|
||||
throw ValueException("invalid key");
|
||||
|
||||
return tmp.toInt();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
class MetaClassProperty : public MetaProperty {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
MetaClassProperty() : MetaProperty() {}
|
||||
|
||||
MetaClassProperty(const std::string& name,
|
||||
const std::string& type,
|
||||
bool isArray,
|
||||
bool isIndex,
|
||||
bool isOptional)
|
||||
: MetaProperty(name, type, isArray, true, isIndex,
|
||||
isOptional, false, false, nullptr) {}
|
||||
|
||||
|
||||
public:
|
||||
BaseObject *createClass() const {
|
||||
return new T();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <template <typename T_1, typename T_2, typename T_3, typename T_4> class P,
|
||||
class C, typename R1, typename T1, typename T2>
|
||||
MetaPropertyHandle createProperty(R1 (C::*setter)(T1), T2 (C::*getter)()) {
|
||||
typedef typename std::remove_const<
|
||||
typename std::remove_cv<
|
||||
typename std::remove_pointer<
|
||||
typename std::remove_reference<T1>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type T;
|
||||
|
||||
return MetaPropertyHandle(new P<C, T, R1 (C::*)(T1), T2 (C::*)()>(setter, getter));
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <template <typename T_1, typename T_2, typename T_3, typename T_4> class P,
|
||||
class C, typename R1, typename T1, typename T2>
|
||||
MetaPropertyHandle createProperty(const std::string& name, const std::string& type,
|
||||
bool isArray, bool isClass, bool isIndex,
|
||||
bool isReference, bool isOptional, bool isEnum,
|
||||
const MetaEnum *enumeration,
|
||||
R1 (C::*setter)(T1), T2 (C::*getter)() const) {
|
||||
typedef typename std::remove_const<
|
||||
typename std::remove_cv<
|
||||
typename std::remove_pointer<
|
||||
typename std::remove_reference<T1>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type T;
|
||||
|
||||
MetaPropertyHandle h = MetaPropertyHandle(new P<C, T, R1 (C::*)(T1), T2 (C::*)() const>(setter, getter));
|
||||
h->setInfo(name, type, isArray, isClass, isIndex, isReference, isOptional, isEnum, enumeration);
|
||||
return h;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <template <typename T_1, typename T_2, typename T_3, typename T_4> class P,
|
||||
class C, typename R1, typename T1, typename T2>
|
||||
MetaPropertyHandle createProperty(const std::string& name, const std::string& type,
|
||||
bool isArray, bool isClass, bool isIndex,
|
||||
bool isReference, bool isOptional, bool isEnum,
|
||||
const MetaEnum *enumeration,
|
||||
R1 (C::*setter)(T1), T2 (C::*getter)()) {
|
||||
typedef typename std::remove_const<
|
||||
typename std::remove_cv<
|
||||
typename std::remove_pointer<
|
||||
typename std::remove_reference<T1>::type
|
||||
>::type
|
||||
>::type
|
||||
>::type T;
|
||||
|
||||
MetaPropertyHandle h = MetaPropertyHandle(new P<C, T, R1 (C::*)(T1), T2 (C::*)()>(setter, getter));
|
||||
h->setInfo(name, type, isArray, isClass, isIndex, isReference, isOptional, isEnum, enumeration);
|
||||
return h;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T, typename U, typename F1, typename F2, int>
|
||||
class SimplePropertyHelper : public MetaProperty {};
|
||||
|
||||
template <typename T, typename U, typename F1, typename F2>
|
||||
class SimplePropertyHelper<T,U,F1,F2,0> : public MetaProperty {
|
||||
public:
|
||||
SimplePropertyHelper(F1 setter, F2 getter)
|
||||
: _setter(setter), _getter(getter) {}
|
||||
|
||||
bool write(BaseObject *object, MetaValue value) const {
|
||||
T *target = T::Cast(object);
|
||||
if ( !target ) return false;
|
||||
(target->*_setter)(boost::any_cast<U>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool writeString(BaseObject *object, const std::string &value) const {
|
||||
T *target = T::Cast(object);
|
||||
if ( !target ) return false;
|
||||
|
||||
U tmp;
|
||||
if ( !fromString(tmp, value) )
|
||||
return false;
|
||||
|
||||
(target->*_setter)(tmp);
|
||||
return true;
|
||||
}
|
||||
|
||||
MetaValue read(const BaseObject *object) const {
|
||||
const T *target = T::ConstCast(object);
|
||||
if ( !target ) throw GeneralException("invalid object");
|
||||
return (target->*_getter)();
|
||||
}
|
||||
|
||||
std::string readString(const BaseObject *object) const {
|
||||
const T *target = T::ConstCast(object);
|
||||
if ( !target ) throw GeneralException("invalid object");
|
||||
return toString((target->*_getter)());
|
||||
}
|
||||
|
||||
private:
|
||||
F1 _setter;
|
||||
F2 _getter;
|
||||
};
|
||||
|
||||
template <typename T, typename U, typename F1, typename F2>
|
||||
class SimplePropertyHelper<T,U,F1,F2,1> : public MetaProperty {
|
||||
public:
|
||||
SimplePropertyHelper(F1 setter, F2 getter)
|
||||
: _setter(setter), _getter(getter) {}
|
||||
|
||||
bool write(BaseObject *object, MetaValue value) const {
|
||||
T *target = T::Cast(object);
|
||||
if ( !target ) return false;
|
||||
|
||||
if ( value.empty() )
|
||||
(target->*_setter)(Core::None);
|
||||
else
|
||||
(target->*_setter)(boost::any_cast<U>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool writeString(BaseObject *object, const std::string &value) const {
|
||||
T *target = T::Cast(object);
|
||||
if ( !target ) return false;
|
||||
|
||||
if ( value.empty() )
|
||||
(target->*_setter)(Core::None);
|
||||
else {
|
||||
typename Core::Generic::remove_optional<U>::type tmp;
|
||||
if ( !fromString(tmp, value) )
|
||||
return false;
|
||||
|
||||
(target->*_setter)(tmp);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
MetaValue read(const BaseObject *object) const {
|
||||
const T *target = T::ConstCast(object);
|
||||
if ( !target ) throw GeneralException("invalid object");
|
||||
return (target->*_getter)();
|
||||
}
|
||||
|
||||
std::string readString(const BaseObject *object) const {
|
||||
const T *target = T::ConstCast(object);
|
||||
if ( !target ) throw GeneralException("invalid object");
|
||||
return toString((target->*_getter)());
|
||||
}
|
||||
|
||||
private:
|
||||
F1 _setter;
|
||||
F2 _getter;
|
||||
};
|
||||
|
||||
|
||||
template <typename T, typename U, typename F1, typename F2>
|
||||
class SimpleProperty : public SimplePropertyHelper<T, U, F1, F2, Generic::is_optional<U>::value> {
|
||||
public:
|
||||
SimpleProperty(F1 setter, F2 getter)
|
||||
: SimplePropertyHelper<T, U, F1, F2, Generic::is_optional<U>::value>(setter, getter) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//! Creates a simple property assuming simple get/set methods
|
||||
//! \code
|
||||
//! class MyClass {
|
||||
//! public:
|
||||
//! void setAttrib(type value);
|
||||
//! type attrib() const;
|
||||
//! };
|
||||
//! \endcode
|
||||
template <class C, typename R1, typename T1, typename T2>
|
||||
MetaPropertyHandle simpleProperty(R1 (C::*setter)(T1), T2 (C::*getter)() const) {
|
||||
return createProperty<SimpleProperty>(setter, getter);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <class C, typename R1, typename T1, typename T2>
|
||||
MetaPropertyHandle simpleProperty(const std::string& name, const std::string& type,
|
||||
bool isArray, bool isClass, bool isIndex,
|
||||
bool isReference, bool isOptional, bool isEnum,
|
||||
const MetaEnum *enumeration,
|
||||
R1 (C::*setter)(T1), T2 (C::*getter)() const) {
|
||||
return createProperty<SimpleProperty>(name, type, isArray, isClass, isIndex,
|
||||
isReference, isOptional, isEnum, enumeration,
|
||||
setter, getter);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
79
include/seiscomp/core/optional.h
Normal file
79
include/seiscomp/core/optional.h
Normal file
@ -0,0 +1,79 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_OPTIONAL_H
|
||||
#define SEISCOMP_CORE_OPTIONAL_H
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
#include <exception>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/none.hpp>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
/** \brief Redefines boost::optional<T>
|
||||
* Optional values can be set or unset.
|
||||
* \code
|
||||
* void print(const Optional<int>::Impl& v) {
|
||||
* if ( !v )
|
||||
* cout << "value of v is not set" << endl;
|
||||
* else
|
||||
* cout << *v << endl;
|
||||
* }
|
||||
*
|
||||
* Optional<int>::Impl a = 5;
|
||||
* print(a); // output: "5"
|
||||
* a = None;
|
||||
* print(a); // output: "value of v is not set"
|
||||
* \endcode
|
||||
*/
|
||||
template <typename T>
|
||||
struct Optional {
|
||||
typedef ::boost::optional<T> Impl;
|
||||
};
|
||||
|
||||
/** Defines None */
|
||||
SC_SYSTEM_CORE_API extern ::boost::none_t const None;
|
||||
|
||||
template <typename T>
|
||||
T value(const boost::optional<T>&);
|
||||
|
||||
class SC_SYSTEM_CORE_API ValueError : public std::exception {
|
||||
public:
|
||||
ValueError() throw();
|
||||
~ValueError() throw();
|
||||
|
||||
public:
|
||||
const char* what() const throw();
|
||||
};
|
||||
|
||||
/** Macro to use optional values easily */
|
||||
#define OPT(T) Seiscomp::Core::Optional<T>::Impl
|
||||
/** Macro to use optional values as const reference */
|
||||
#define OPT_CR(T) const Seiscomp::Core::Optional<T>::Impl&
|
||||
|
||||
#include <seiscomp/core/optional.inl>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
27
include/seiscomp/core/optional.inl
Normal file
27
include/seiscomp/core/optional.inl
Normal file
@ -0,0 +1,27 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
template <typename T>
|
||||
T value(const boost::optional<T>& v) {
|
||||
if ( v )
|
||||
return *v;
|
||||
|
||||
throw ValueError();
|
||||
}
|
45
include/seiscomp/core/platform/osx.h
Normal file
45
include/seiscomp/core/platform/osx.h
Normal file
@ -0,0 +1,45 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_OSX_H__
|
||||
#define SEISCOMP_CORE_OSX_H__
|
||||
|
||||
/*
|
||||
* Signal handling
|
||||
*/
|
||||
#include <signal.h>
|
||||
#ifdef MACOSX
|
||||
typedef void (*sighandler_t)(int);
|
||||
#else
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Header files for malloc
|
||||
*/
|
||||
#ifdef MACOSX
|
||||
#include <stdlib.h>
|
||||
#include <malloc/malloc.h>
|
||||
#else
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
15
include/seiscomp/core/platform/platform.h
Normal file
15
include/seiscomp/core/platform/platform.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef SEISCOMP_CORE_PLATFORM_H
|
||||
#define SEISCOMP_CORE_PLATFORM_H
|
||||
|
||||
/* #undef MACOSX */
|
||||
#define LINUX
|
||||
#define SC_HAS_TIMER_CREATE
|
||||
#define SC_HAS_EVENTFD
|
||||
#define SC_HAS_EPOLL
|
||||
/* #undef SC_HAS_KQUEUE */
|
||||
|
||||
#ifdef MACOSX
|
||||
#include <seiscomp/core/platform/osx.h>
|
||||
#endif
|
||||
|
||||
#endif
|
128
include/seiscomp/core/plugin.h
Normal file
128
include/seiscomp/core/plugin.h
Normal file
@ -0,0 +1,128 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_PLUGIN_H
|
||||
#define SEISCOMP_CORE_PLUGIN_H
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core/version.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Plugin);
|
||||
|
||||
/**
|
||||
* The plugin class defines a general class to load code from
|
||||
* outside at runtime.
|
||||
* The macro IMPLEMENT_SC_PLUGIN(MyPlugin) has to be called
|
||||
* inside the plugin implementation to make it compatible.
|
||||
* It is also possible to declare the entry function without
|
||||
* the macro. One has to implement the function as follows:
|
||||
* \code
|
||||
* extern "C" Seiscomp::Core::Plugin* createSCPlugin();
|
||||
* \endcode
|
||||
*
|
||||
* One has to derive MyPlugin from Seiscomp::Core::Plugin and
|
||||
* set the description entries in the constructor.
|
||||
*
|
||||
* There is also a convenience macro ADD_SC_PLUGIN that does
|
||||
* not require any custom class declaration.
|
||||
* \code
|
||||
* SC_ADD_PLUGIN("My description", "I am the author", 0, 0, 1)
|
||||
* \endcode
|
||||
* This macro must only be called once inside a plugin library.
|
||||
*/
|
||||
|
||||
class SC_SYSTEM_CORE_API Plugin : public Seiscomp::Core::BaseObject {
|
||||
DECLARE_SC_CLASS(Plugin);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
typedef Plugin* (*CreateFunc)();
|
||||
|
||||
struct Description {
|
||||
struct Version {
|
||||
int major;
|
||||
int minor;
|
||||
int revision;
|
||||
};
|
||||
|
||||
std::string description;
|
||||
std::string author;
|
||||
Version version;
|
||||
int apiVersion;
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
Plugin();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
const Description &description() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected members
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
Description _description;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define IMPLEMENT_SC_PLUGIN(CLASSNAME) \
|
||||
extern "C" __declspec(dllexport) Seiscomp::Core::Plugin* createSCPlugin() { return new CLASSNAME; }
|
||||
#else
|
||||
#define IMPLEMENT_SC_PLUGIN(CLASSNAME) \
|
||||
extern "C" Seiscomp::Core::Plugin* createSCPlugin() { return new CLASSNAME; }
|
||||
#endif
|
||||
|
||||
#define ADD_SC_PLUGIN(DESC, AUTHOR, VMAJ, VMIN, VREV) \
|
||||
namespace { \
|
||||
class __PluginStub__ : public Seiscomp::Core::Plugin { \
|
||||
public: \
|
||||
__PluginStub__() { \
|
||||
_description.description = DESC; \
|
||||
_description.author = AUTHOR; \
|
||||
_description.version.major = VMAJ; \
|
||||
_description.version.minor = VMIN; \
|
||||
_description.version.revision = VREV; \
|
||||
_description.apiVersion = SC_API_VERSION; \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
IMPLEMENT_SC_PLUGIN(__PluginStub__)
|
||||
|
||||
#endif
|
259
include/seiscomp/core/record.h
Normal file
259
include/seiscomp/core/record.h
Normal file
@ -0,0 +1,259 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_RECORD_H
|
||||
#define SEISCOMP_CORE_RECORD_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core/interfacefactory.h>
|
||||
#include <seiscomp/core/timewindow.h>
|
||||
#include <seiscomp/core/array.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
|
||||
class BitSet;
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Record);
|
||||
|
||||
class SC_SYSTEM_CORE_API Record : public Seiscomp::Core::BaseObject {
|
||||
DECLARE_SC_CLASS(Record);
|
||||
DECLARE_SERIALIZATION;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public enumeration
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Specifies the memory storage flags.
|
||||
enum Hint {
|
||||
META_ONLY,
|
||||
DATA_ONLY,
|
||||
SAVE_RAW,
|
||||
H_QUANTITY
|
||||
};
|
||||
|
||||
//! This enum was introduced with API 13
|
||||
enum Authentication {
|
||||
NOT_SIGNED,
|
||||
SIGNATURE_VALIDATED,
|
||||
SIGNATURE_VALIDATION_FAILED,
|
||||
A_QUANTITY
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Default Constructor
|
||||
Record(Array::DataType datatype, Hint);
|
||||
|
||||
//! Initializing Constructor
|
||||
Record(Array::DataType, Hint,
|
||||
std::string net, std::string sta, std::string loc, std::string cha,
|
||||
Seiscomp::Core::Time stime, int nsamp, double fsamp, int tqual);
|
||||
|
||||
//! Copy Constructor
|
||||
Record(const Record &rec);
|
||||
|
||||
//! Destructor
|
||||
virtual ~Record();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Operators
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Assignment operator
|
||||
Record &operator=(const Record &rec);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public attribute access
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the network code
|
||||
const std::string &networkCode() const;
|
||||
|
||||
//! Sets the network code
|
||||
virtual void setNetworkCode(std::string net);
|
||||
|
||||
//! Returns the station code
|
||||
const std::string &stationCode() const;
|
||||
|
||||
//! Sets the station code
|
||||
virtual void setStationCode(std::string sta);
|
||||
|
||||
//! Returns the location code
|
||||
const std::string &locationCode() const;
|
||||
|
||||
//! Sets the location code
|
||||
virtual void setLocationCode(std::string loc);
|
||||
|
||||
//! Returns the channel code
|
||||
const std::string &channelCode() const;
|
||||
|
||||
//! Sets the channel code
|
||||
virtual void setChannelCode(std::string cha);
|
||||
|
||||
//! Returns the start time
|
||||
const Core::Time& startTime() const;
|
||||
|
||||
//! Sets the start time
|
||||
virtual void setStartTime(const Core::Time& time);
|
||||
|
||||
//! Returns the end time
|
||||
Core::Time endTime() const;
|
||||
|
||||
//! Returns the time window between start and end time of a record
|
||||
Core::TimeWindow timeWindow() const;
|
||||
|
||||
//! Returns the sample number
|
||||
int sampleCount() const;
|
||||
|
||||
//! Returns the sample frequency
|
||||
double samplingFrequency() const;
|
||||
|
||||
//! Returns the timing quality
|
||||
int timingQuality() const;
|
||||
|
||||
//! Sets the timing quality
|
||||
void setTimingQuality(int tqual);
|
||||
|
||||
//! Returns the so called stream ID: <net>.<sta>.<loc>.<cha>
|
||||
std::string streamID() const;
|
||||
|
||||
//! Returns the data type specified for the data sample requests
|
||||
Array::DataType dataType() const;
|
||||
|
||||
//! Sets the data type for the data requests which can differ
|
||||
//! from the real type of the data samples.
|
||||
void setDataType(Array::DataType dt);
|
||||
|
||||
//! Sets the hint used for data operations
|
||||
void setHint(Hint h);
|
||||
|
||||
/**
|
||||
* @brief Sets the authentication state.
|
||||
* This function was introduced with API 13.
|
||||
* @param auth The authentication status
|
||||
*/
|
||||
void setAuthentication(Authentication auth);
|
||||
|
||||
//! This function was introduced with API 13
|
||||
Authentication authentication() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the authentication authority
|
||||
* This function was introduced with API 13.
|
||||
* @param authority The authority which signed the record
|
||||
*/
|
||||
void setAuthority(const std::string &authority);
|
||||
|
||||
//! This function was introduced with API 13
|
||||
const std::string &authority() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public data access
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns a nonmutable pointer to the data samples if the data is available; otherwise 0
|
||||
//! (the data type is independent from the original one and was given by the DataType flag in the constructor)
|
||||
virtual const Array* data() const = 0;
|
||||
|
||||
//! Returns the raw data of the record if existing
|
||||
virtual const Array* raw() const = 0;
|
||||
|
||||
//! Returns a deep copy of the calling object.
|
||||
virtual Record* copy() const = 0;
|
||||
|
||||
//! Return the clip mask for the data in the record. The clip mask
|
||||
//! holds a bit for each sample and sets that bit to 1 if the sample
|
||||
//! is clipped. The default implementation always returns nullptr.
|
||||
//! Support has to be provided in derived implementations.
|
||||
virtual const BitSet *clipMask() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Frees the memory allocated for the data samples.
|
||||
virtual void saveSpace() const = 0;
|
||||
|
||||
virtual void read(std::istream &in) = 0;
|
||||
virtual void write(std::ostream &out) = 0;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected members
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
std::string _net;
|
||||
std::string _sta;
|
||||
std::string _loc;
|
||||
std::string _cha;
|
||||
Core::Time _stime;
|
||||
Array::DataType _datatype;
|
||||
Hint _hint;
|
||||
int _nsamp;
|
||||
double _fsamp;
|
||||
int _timequal;
|
||||
Authentication _authenticationStatus;
|
||||
std::string _authority;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_INTERFACE_FACTORY(Record);
|
||||
|
||||
#define REGISTER_RECORD_VAR(Class, Service) \
|
||||
Seiscomp::Core::Generic::InterfaceFactory<Seiscomp::Record, Class> __##Class##InterfaceFactory__(Service)
|
||||
|
||||
#define REGISTER_RECORD(Class, Service) \
|
||||
static REGISTER_RECORD_VAR(Class, Service)
|
||||
|
||||
|
||||
inline Record::Authentication Record::authentication() const {
|
||||
return _authenticationStatus;
|
||||
}
|
||||
|
||||
inline const std::string &Record::authority() const {
|
||||
return _authority;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
SC_SYSTEM_CORE_API std::istream& operator>>(std::istream &is, Seiscomp::Record &rec);
|
||||
SC_SYSTEM_CORE_API std::ostream& operator<<(std::ostream &os, Seiscomp::Record &rec);
|
||||
|
||||
|
||||
#endif
|
277
include/seiscomp/core/recordsequence.h
Normal file
277
include/seiscomp/core/recordsequence.h
Normal file
@ -0,0 +1,277 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_RECORDSEQUENCE_H
|
||||
#define SEISCOMP_RECORDSEQUENCE_H
|
||||
|
||||
|
||||
#include <seiscomp/core/genericrecord.h>
|
||||
#include <seiscomp/core/timewindow.h>
|
||||
|
||||
#include <deque>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
|
||||
/**
|
||||
* RecordSequence
|
||||
*
|
||||
* A container class for record sequences (i.e. records sorted in time)
|
||||
* The class RecordSequence is a container for Record objects. It forms
|
||||
* the basis for the implementation as RingBuffer or TimeWindowBuffer.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API RecordSequence : public std::deque<RecordCPtr> {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
typedef std::deque<Core::TimeWindow> TimeWindowArray;
|
||||
typedef std::pair<double,double> Range;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
RecordSequence(double tolerance=0.5);
|
||||
|
||||
//! D'tor
|
||||
virtual ~RecordSequence();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Feed a record to buffer. Returns true if the record
|
||||
//! was actually added.
|
||||
virtual bool feed(const Record*) = 0;
|
||||
|
||||
//! Returns a copy of the sequence including all fed
|
||||
//! records.
|
||||
virtual RecordSequence *copy() const = 0;
|
||||
|
||||
//! Returns a cloned sequence without containing records.
|
||||
virtual RecordSequence *clone() const = 0;
|
||||
|
||||
//! Return the time tolerance in samples
|
||||
//! The tolerance is the maximum gap/overlap (in samples)
|
||||
//! that will not break the continuity of the sequence.
|
||||
double tolerance() const;
|
||||
|
||||
//! Set the time tolerance in samples
|
||||
void setTolerance(double);
|
||||
|
||||
//! Return Record's as one contiguous record. Compiled in is support for
|
||||
//! float, double and int. If interpolation is enabled gaps will be linearly
|
||||
//! interpolated between the last and the next sample.
|
||||
template <typename T>
|
||||
GenericRecord *contiguousRecord(const Seiscomp::Core::TimeWindow *tw = nullptr,
|
||||
bool interpolate = false) const;
|
||||
|
||||
//! DECPRECATED: For backward compatibility, does exactly the same as
|
||||
//! contiguousRecord. Please use contiguousRecord in your
|
||||
//! code. This method will be removed in future releases.
|
||||
template <typename T>
|
||||
GenericRecord *continuousRecord(const Seiscomp::Core::TimeWindow *tw = nullptr,
|
||||
bool interpolate = false) const;
|
||||
|
||||
|
||||
//! Time window currently in buffer, irrespective of gaps
|
||||
Core::TimeWindow timeWindow() const;
|
||||
|
||||
//! The amplitude range in a given time window.
|
||||
//! Returns (0,0) if the sequence is empty or no records fall inside
|
||||
//! the given optional time window.
|
||||
Range amplitudeRange(const Seiscomp::Core::TimeWindow *tw = nullptr) const;
|
||||
|
||||
//! returns the continuous time windows available
|
||||
//! This is usually one time window but may be split into
|
||||
//! several if there are any gaps.
|
||||
TimeWindowArray windows() const;
|
||||
|
||||
//! returns the gaps that exceed dt *samples*
|
||||
TimeWindowArray gaps() const;
|
||||
|
||||
//! Does the buffer contain all data for the time window?
|
||||
bool contains(const Core::TimeWindow &tw) const;
|
||||
|
||||
//! Returns the percentage of available data within a given time window
|
||||
double availability(const Core::TimeWindow& tw) const;
|
||||
|
||||
//! Returns the number of stored records, same as size().
|
||||
size_t recordCount() const;
|
||||
|
||||
//! Determine average timing quality from the records stored in this
|
||||
//! sequence.
|
||||
//! Returns true on success; in that case, count and quality are set
|
||||
bool timingQuality(int &count, float &quality) const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
bool alreadyHasRecord(const Record*) const;
|
||||
bool findInsertPosition(const Record*, iterator*);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Members
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
double _tolerance;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* TimeWindowBuffer
|
||||
*
|
||||
* A container class for record sequences (i.e. records sorted in time)
|
||||
* The records are stored only if they at least overlap with the fixed time
|
||||
* window. This is useful if only a certain fixed time window is of interest.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API TimeWindowBuffer : public RecordSequence {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
TimeWindowBuffer(const Core::TimeWindow &tw, double tolerance=0.5);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public RecordSequence interface overrides
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
virtual bool feed(const Record*);
|
||||
virtual RecordSequence *copy() const;
|
||||
virtual RecordSequence *clone() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Return percentage of available data within TimeWindowBuffer's TimeWindow
|
||||
double availability() const;
|
||||
|
||||
//! Return the buffered TimeWindow
|
||||
const Core::TimeWindow &timeWindowToStore() const;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
Core::TimeWindow _timeWindow;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* RingBuffer
|
||||
*
|
||||
* A container class for record sequences (i.e. records sorted in time)
|
||||
* The records are stored only up to a maximum number; once this maximum
|
||||
* number is reached, the oldest record is removed each time a new record is
|
||||
* stored. Note that this doesn't usually guarantee a certain time window
|
||||
* length.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API RingBuffer : public RecordSequence {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Create RingBuffer for fixed maximum number of records
|
||||
//! This version stores at most nmax most recent records.
|
||||
RingBuffer(int nmax, double tolerance=0.5);
|
||||
|
||||
//! Create RingBuffer for fixed time span
|
||||
//! This version stores at least a certain time
|
||||
//! window length of available data ending at the
|
||||
//! end time of the last record.
|
||||
RingBuffer(Core::TimeSpan span, double tolerance=0.5);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public RecordSequence interface overrides
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
virtual bool feed(const Record*);
|
||||
virtual RecordSequence *copy() const;
|
||||
virtual RecordSequence *clone() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! clear the buffer
|
||||
void reset() { clear(); }
|
||||
|
||||
//! Return the maximum number of records the RingBuffer stores
|
||||
unsigned int numberOfRecordsToStore() const;
|
||||
|
||||
//! Return the TimeSpan the RingBuffer stores
|
||||
const Core::TimeSpan &timeSpanToStore() const;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
unsigned int _nmax;
|
||||
Core::TimeSpan _span;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Inline implementations
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
inline double RecordSequence::tolerance() const {
|
||||
return _tolerance;
|
||||
}
|
||||
|
||||
inline void RecordSequence::setTolerance(double dt) {
|
||||
_tolerance = dt;
|
||||
}
|
||||
|
||||
inline size_t RecordSequence::recordCount() const {
|
||||
return size();
|
||||
}
|
||||
|
||||
inline const Core::TimeWindow &TimeWindowBuffer::timeWindowToStore() const {
|
||||
return _timeWindow;
|
||||
}
|
||||
|
||||
inline unsigned int RingBuffer::numberOfRecordsToStore() const {
|
||||
return _nmax;
|
||||
}
|
||||
|
||||
inline const Core::TimeSpan &RingBuffer::timeSpanToStore() const {
|
||||
return _span;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
200
include/seiscomp/core/rtti.h
Normal file
200
include/seiscomp/core/rtti.h
Normal file
@ -0,0 +1,200 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_RTTI_H
|
||||
#define SEISCOMP_CORE_RTTI_H
|
||||
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief A RTTI (Runtime Type Information) class
|
||||
|
||||
This class implements an RTTI object returned by the
|
||||
RTTI interface below (DECLARE_RTTI).
|
||||
It supports retrieving a classname, the parent type information
|
||||
and comparing two types for equality or collating order.
|
||||
Drawback: No multiple inheritance supported!
|
||||
|
||||
To implement it into your own classes, use the supported RTTI
|
||||
macros.
|
||||
|
||||
\code
|
||||
class MyClass {
|
||||
DECLARE_RTTI;
|
||||
...
|
||||
public:
|
||||
MyClass();
|
||||
...
|
||||
};
|
||||
\endcode
|
||||
|
||||
To implement the RTTI interface, another macro is to be used. There are
|
||||
two versions. One version to implement the RTTI interface for the root type
|
||||
and another version for derived types.
|
||||
\code
|
||||
IMPLEMENT_ROOT_RTTI(MyClass, MyClassNameWithRespectToMyRTTI);
|
||||
\endcode
|
||||
|
||||
and
|
||||
|
||||
\code
|
||||
IMPLEMENT_RTTI(MyDerivedClass, MyDerivedClassNameWithRespectToMyRTTI, MyClass);
|
||||
\endcode
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API RTTI {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
RTTI(const char* classname, const RTTI* parent = nullptr);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Operators
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Checks two types for equality
|
||||
bool operator==(const RTTI& other) const;
|
||||
bool operator!=(const RTTI& other) const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
const RTTI* parent() const;
|
||||
const char* className() const;
|
||||
|
||||
//! Returns whether other is derived from *this or not.
|
||||
//! If both types are equal, false is returned.
|
||||
bool before(const RTTI& other) const;
|
||||
|
||||
//! Returns true when *this is derived from or equal to other
|
||||
bool isTypeOf(const RTTI& other) const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
std::string _classname;
|
||||
const RTTI* _parent;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
#define DECLARE_BASE_RTTI \
|
||||
public: \
|
||||
static const char* ClassName(); \
|
||||
static const Seiscomp::Core::RTTI& TypeInfo(); \
|
||||
\
|
||||
virtual const char* className() const; \
|
||||
virtual const Seiscomp::Core::RTTI& typeInfo() const
|
||||
|
||||
|
||||
#define DECLARE_RTTI \
|
||||
public: \
|
||||
static const char* ClassName(); \
|
||||
static const Seiscomp::Core::RTTI& TypeInfo(); \
|
||||
\
|
||||
virtual const char* className() const override; \
|
||||
virtual const Seiscomp::Core::RTTI& typeInfo() const override
|
||||
|
||||
|
||||
#define IMPLEMENT_ROOT_RTTI(CLASS, CLASSNAME) \
|
||||
const Seiscomp::Core::RTTI& CLASS::TypeInfo() { \
|
||||
static Seiscomp::Core::RTTI classRTTI(CLASSNAME); \
|
||||
return classRTTI; \
|
||||
}
|
||||
|
||||
|
||||
#define IMPLEMENT_RTTI(CLASS, CLASSNAME, BASECLASS) \
|
||||
const Seiscomp::Core::RTTI& CLASS::TypeInfo() { \
|
||||
static Seiscomp::Core::RTTI classRTTI(CLASSNAME, &BASECLASS::TypeInfo()); \
|
||||
return classRTTI; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define IMPLEMENT_TEMPLATE_RTTI(CLASS, CLASSNAME, BASECLASS) \
|
||||
template <> \
|
||||
const Seiscomp::Core::RTTI& CLASS::TypeInfo() { \
|
||||
static Seiscomp::Core::RTTI classRTTI(CLASSNAME, &BASECLASS::TypeInfo()); \
|
||||
return classRTTI; \
|
||||
}
|
||||
|
||||
|
||||
#define IMPLEMENT_RTTI_METHODS(CLASS) \
|
||||
const char* CLASS::ClassName() { \
|
||||
return TypeInfo().className(); \
|
||||
} \
|
||||
\
|
||||
const char* CLASS::className() const { \
|
||||
return TypeInfo().className(); \
|
||||
} \
|
||||
\
|
||||
const Seiscomp::Core::RTTI& CLASS::typeInfo() const { \
|
||||
return TypeInfo(); \
|
||||
}
|
||||
|
||||
|
||||
#define IMPLEMENT_TEMPLATE_RTTI_METHODS(CLASS, CLASSNAME) \
|
||||
template <typename T> \
|
||||
inline const char* CLASS<T>::ClassName() { \
|
||||
return TypeInfo().className(); \
|
||||
} \
|
||||
\
|
||||
template <typename T> \
|
||||
inline const Seiscomp::Core::RTTI& CLASS<T>::TypeInfo() { \
|
||||
static Seiscomp::Core::RTTI classRTTI(CLASSNAME); \
|
||||
return classRTTI; \
|
||||
} \
|
||||
template <typename T> \
|
||||
inline const char* CLASS<T>::className() const { \
|
||||
return TypeInfo().className(); \
|
||||
} \
|
||||
\
|
||||
template <typename T> \
|
||||
inline const Seiscomp::Core::RTTI& CLASS<T>::typeInfo() const { \
|
||||
return TypeInfo(); \
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
213
include/seiscomp/core/serialization.h
Normal file
213
include/seiscomp/core/serialization.h
Normal file
@ -0,0 +1,213 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_SERIALIZATION_H
|
||||
#define SEISCOMP_CORE_SERIALIZATION_H
|
||||
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
namespace Generic {
|
||||
|
||||
|
||||
template <typename T> class Archive;
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
//! Class used to give names to objects
|
||||
template<typename T>
|
||||
class ObjectNamer {
|
||||
// ------------------------------------------------------------------
|
||||
// Public types
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
typedef T Type;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Construction requires a reference to the object and the name to give the object
|
||||
ObjectNamer(const char* name, Type& object, int h = 0)
|
||||
: _pair(name, &object), _hint(h) {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the name of the object
|
||||
const char* name() const { return _pair.first; }
|
||||
|
||||
//! Returns a reference to the object being named
|
||||
Type& object() const { return *_pair.second; }
|
||||
|
||||
//! Returns the hint for serialization
|
||||
int hint() const { return _hint; }
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
std::pair<const char*, Type*> _pair; //!< The pair which maps a name to an object
|
||||
int _hint;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
//! Class used to iterate over a sequence of objects
|
||||
template<typename T>
|
||||
class ObjectIterator {
|
||||
// ------------------------------------------------------------------
|
||||
// Public types
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
typedef T Type;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Construction requires a reference to the object and the name to give the object
|
||||
ObjectIterator(Type& object, bool first) : _object(&object), _first(first) {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the flag to state whether to read the first
|
||||
//! object or the next in the sequence
|
||||
bool first() const { return _first; }
|
||||
|
||||
//! Returns a reference to the object being read
|
||||
Type& object() const { return *_object; }
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
Type* _object; //!< The object which has to be read
|
||||
bool _first; //!< Initialize
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
//NOTE Because of a bug in the SUNPRO compiler up to version 5.10
|
||||
// a non template containertype is being used.
|
||||
//template<template <typename, typename> class C, typename T, typename ADD>
|
||||
template<class C, typename T, typename ADD>
|
||||
class ObjectContainer {
|
||||
public:
|
||||
typedef T Type;
|
||||
//typedef C<T, std::allocator<T> > ContainerType;
|
||||
typedef C ContainerType;
|
||||
|
||||
ObjectContainer(ContainerType& c, ADD a) : _container(&c), _add(a) {}
|
||||
|
||||
ContainerType& container() const {
|
||||
return *_container;
|
||||
}
|
||||
|
||||
bool add(T& v) const {
|
||||
_add(v);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable ContainerType* _container;
|
||||
mutable ADD _add;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template<typename T>
|
||||
ObjectNamer<T> nameObject(const char* name, T& object, int h = 0) {
|
||||
return ObjectNamer<T>(name, object, h);
|
||||
}
|
||||
template<typename T>
|
||||
ObjectNamer<const T> nameObject(const char* name, const T& object, int h = 0) {
|
||||
return ObjectNamer<const T>(name, object, h);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template<typename T>
|
||||
ObjectIterator<T> itObject(T& object, bool first) {
|
||||
return ObjectIterator<T>(object, first);
|
||||
}
|
||||
template<typename T>
|
||||
ObjectIterator<const T> itObject(const T& object, bool first) {
|
||||
return ObjectIterator<const T>(object, first);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template<template <typename, typename> class C, typename T, typename ADD>
|
||||
ObjectContainer<C<T, std::allocator<T> >, T, ADD> containerMember(C<T, std::allocator<T> >& container, ADD add) {
|
||||
return ObjectContainer<C<T, std::allocator<T> >, T, ADD>(container, add);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename Tgt, class ret, class T>
|
||||
std::function<ret (const typename Core::SmartPointer<Tgt>::Impl &ptr)>
|
||||
bindMemberFunction(ret (T::*f)(Tgt*), T* c) {
|
||||
return [c,f](const typename Core::SmartPointer<Tgt>::Impl &ptr) {
|
||||
return (c->*f)(ptr.get());
|
||||
};
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
#define TAGGED_MEMBER(x) Seiscomp::Core::Generic::nameObject(#x, _##x)
|
||||
#define NAMED_OBJECT(name, x) Seiscomp::Core::Generic::nameObject(name, x)
|
||||
#define NAMED_OBJECT_HINT(name, x, h) Seiscomp::Core::Generic::nameObject(name, x, h)
|
||||
|
||||
#define SEQUENCE_OBJECT(object, first) Seiscomp::Core::Generic::itObject(object, first)
|
||||
#define FIRST_OBJECT(object) Seiscomp::Core::Generic::itObject(object, true)
|
||||
#define NEXT_OBJECT(object) Seiscomp::Core::Generic::itObject(object, false)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
469
include/seiscomp/core/strings.h
Normal file
469
include/seiscomp/core/strings.h
Normal file
@ -0,0 +1,469 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_STRINGS_H
|
||||
#define SEISCOMP_CORE_STRINGS_H
|
||||
|
||||
|
||||
#include <seiscomp/core/optional.h>
|
||||
#include <seiscomp/core/enumeration.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/math/math.h>
|
||||
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <fmt/printf.h>
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <complex>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
/** Array of whitespace characters */
|
||||
const std::string WHITESPACE = "\t\n\v\f\r ";
|
||||
|
||||
|
||||
/**
|
||||
* Converts a value into a string. Conversions are supported
|
||||
* for following types:
|
||||
* char
|
||||
* int, long
|
||||
* float, double
|
||||
* Core::Time, std::complex
|
||||
* and any other type that is supported by std::ostream
|
||||
* std::vector and OPT() of all above types
|
||||
*
|
||||
* @param value The value
|
||||
* @return The value as string
|
||||
*/
|
||||
template <typename T>
|
||||
std::string toString(const T &value);
|
||||
|
||||
template <typename T>
|
||||
std::string toString(const std::complex<T> &value);
|
||||
|
||||
SC_SYSTEM_CORE_API std::string toString(const std::string &value);
|
||||
SC_SYSTEM_CORE_API std::string toString(bool value);
|
||||
SC_SYSTEM_CORE_API std::string toString(const Time &value);
|
||||
SC_SYSTEM_CORE_API std::string toString(const Enumeration &value);
|
||||
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
std::string toString(const Enum<ENUMTYPE, END, NAMES> &value);
|
||||
|
||||
template <typename T>
|
||||
std::string toString(const std::vector<T> &v);
|
||||
|
||||
template <typename T>
|
||||
std::string toString(const ::boost::optional<T> &v);
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct Number {
|
||||
Number(const T &v) : ref(v) {}
|
||||
const T &ref;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Number<T> number(const T &v) { return Number<T>(v); }
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const Number<float> &s);
|
||||
std::ostream &operator<<(std::ostream &os, const Number<double> &s);
|
||||
|
||||
/**
|
||||
* Converts a string into a value. Conversions are supported
|
||||
* for following types:
|
||||
* int/uint with 8,16,32 and 64 bit
|
||||
* float, double
|
||||
* std::vector of all above types
|
||||
* IMPORTANT: integer types are converted in base 10!
|
||||
*
|
||||
* @param value The target value
|
||||
* @param str The source string
|
||||
*/
|
||||
template <typename T>
|
||||
bool fromString(T &value, const std::string &str);
|
||||
|
||||
template <typename T>
|
||||
bool fromString(std::complex<T> &value, const std::string &str);
|
||||
|
||||
SC_SYSTEM_CORE_API bool fromString(Time &value, const std::string &str);
|
||||
SC_SYSTEM_CORE_API bool fromString(Enumeration &value, const std::string &str);
|
||||
SC_SYSTEM_CORE_API bool fromString(std::string &value, const std::string &str);
|
||||
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
bool fromString(Enum<ENUMTYPE, END, NAMES> &value, const std::string &str);
|
||||
|
||||
template <typename T>
|
||||
bool fromString(std::vector<T> &vec, const std::string &str);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Produces output according to a format as used by printf. The output
|
||||
* is written to a string and returned.
|
||||
* @param format A format description as used by printf
|
||||
* @return The string containing the output
|
||||
*/
|
||||
template <typename S, typename... Args>
|
||||
std::string stringify(const S &format, Args &&...args);
|
||||
|
||||
/**
|
||||
* @brief Splits a string into several tokens separated by one of the specified
|
||||
* delimiter characters.
|
||||
* @param tokens Result vector containing the individual tokens
|
||||
* @param source The source string
|
||||
* @param delimiter Sequence of characters to spit the string at
|
||||
* @param compressOn If enabled, adjacent separators are merged together.
|
||||
* Otherwise, every two separators delimit a token.
|
||||
* @return The number of generated tokens.
|
||||
*/
|
||||
SC_SYSTEM_CORE_API
|
||||
int split(std::vector<std::string> &tokens, const char *source,
|
||||
const char *delimiter, bool compressOn = true);
|
||||
|
||||
/**
|
||||
* @brief Convenience function which takes an std::string as source parameter
|
||||
* rather than a const char pointer.
|
||||
* See @ref split(std::vector<std::string> &, const char *, const char *, bool).
|
||||
*/
|
||||
SC_SYSTEM_CORE_API
|
||||
int split(std::vector<std::string> &tokens, const std::string &source,
|
||||
const char *delimiter, bool compressOn = true);
|
||||
|
||||
/**
|
||||
* @brief Splits a string into several tokens separated by one of the specified
|
||||
* delimiter characters. A delimiter character is ignored if it occurs in
|
||||
* a quoted string or if it is protected by a backslash. Likewise quotes
|
||||
* may be protected by a backslash. By default, leading and trailing
|
||||
* whitespaces will be trimmed if they occur outside of a quoted string
|
||||
* and if they are not protected by a backslash.
|
||||
* @param tokens Result vector containing the individual tokens
|
||||
* @param source The source string
|
||||
* @param delimiter Sequence of characters to spit the string at
|
||||
* @param compressOn If enabled, adjacent separators are merged together.
|
||||
* Otherwise, every two separators delimit a token.
|
||||
* @param unescape Request removal of surrounding quotes and unescape of certain
|
||||
* characters.
|
||||
* In particular a backslash outside quotes is removed if it protects a
|
||||
* backslash, a whitespace, a quote or a delimiter character. While a
|
||||
* backslash inside quotes only is removed if it protects a backslash or
|
||||
* the beginning quote character.
|
||||
* @param trim Request trimming of whitespaces
|
||||
* @param whitespace Sequence of characters to interpret as a whitespace
|
||||
* @param quotes Sequence of characters to interpret as a quote
|
||||
* @return Number of tokens found
|
||||
*/
|
||||
SC_SYSTEM_CORE_API
|
||||
size_t splitExt(std::vector<std::string> &tokens, const char *source,
|
||||
const char *delimiter = ",", bool compressOn = true,
|
||||
bool unescape = false, bool trim = true,
|
||||
const char *whitespaces = " \t\n\v\f\r",
|
||||
const char *quotes = "\"'");
|
||||
|
||||
/**
|
||||
* @brief Creates and returns a new string by concatenating all of the elements
|
||||
* in an array, separated by commas or a specified separator string.
|
||||
*
|
||||
* If the array has only one item, then that item will be returned without
|
||||
* using the separator.
|
||||
*
|
||||
* @param tokens[in] The array to be joined
|
||||
* @param separator[in] The optional separator string
|
||||
* @return The resulting string
|
||||
*/
|
||||
SC_SYSTEM_CORE_API
|
||||
template <class CONT>
|
||||
std::string join(const CONT &tokens, const char *separator = nullptr);
|
||||
|
||||
SC_SYSTEM_CORE_API
|
||||
template <class CONT>
|
||||
std::string join(const CONT &tokens, const std::string &separator);
|
||||
|
||||
SC_SYSTEM_CORE_API bool isEmpty(const char*);
|
||||
|
||||
/**
|
||||
* A case-insensitive comparison.
|
||||
* @return Result as defined by strcmp
|
||||
*/
|
||||
SC_SYSTEM_CORE_API int compareNoCase(const std::string &a, const std::string &b);
|
||||
|
||||
/** Removes whitespace at the beginning and end of the string.
|
||||
* @param string to be trimmed (in/out parameter)
|
||||
* @return returns the trimmed string
|
||||
*/
|
||||
SC_SYSTEM_CORE_API std::string &trim(std::string &str);
|
||||
|
||||
template <typename T>
|
||||
void toHex(std::string &target, T source);
|
||||
|
||||
/** Checks if given character is whitespace */
|
||||
bool isWhitespace(const char c);
|
||||
|
||||
/** Checks if the given string solely contanins whitespace */
|
||||
bool isWhitespace(const std::string &str);
|
||||
|
||||
/** wildcmp() compares a string containing wildcards with another
|
||||
* string where '?' represents a single character and '*'
|
||||
* represents zero to unlimited characters.
|
||||
* wildicmp() performs the same operation, but is case insensitive
|
||||
* This code has been written by Alessandro Cantatore
|
||||
* http://xoomer.virgilio.it/acantato/dev/wildcard/wildmatch.html
|
||||
* @param wild The string containing the wildcards
|
||||
* @param str The string checked against the wildcard string
|
||||
* @return The match result
|
||||
*/
|
||||
SC_SYSTEM_CORE_API bool wildcmp(const char *wild, const char *str);
|
||||
SC_SYSTEM_CORE_API bool wildcmp(const std::string &wild, const std::string &str);
|
||||
SC_SYSTEM_CORE_API bool wildicmp(const char *wild, const char *str);
|
||||
SC_SYSTEM_CORE_API bool wildicmp(const std::string &wild, const std::string &str);
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Plain C string functions which do not modify the input string and work
|
||||
// mostly with length rather than an terminating null byte.
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Tokenizes an input string. Empty tokens will be skipped and not
|
||||
* returned (also referred to as compression).
|
||||
* @param str The input string. The address is modified that it will point to
|
||||
* the next token.
|
||||
* @param delim A string of characters of allowed delimiters
|
||||
* @param len_source The source length. This parameter will be modified
|
||||
* to match the remaining length of the string.
|
||||
* @param len_tok The length of the returned token.
|
||||
* @return The address to the token found or nullptr.
|
||||
*/
|
||||
template <typename T>
|
||||
T *tokenize(T *&str, const char *delim, size_t &len_source, size_t &len_tok);
|
||||
|
||||
/**
|
||||
* @brief Works like tokenize but does not compress empty tokens.
|
||||
* @param str The input string. The address is modified that it will point to
|
||||
* the next token.
|
||||
* @param delim A string of characters of allowed delimiters
|
||||
* @param len_source The source length. This parameter will be modified
|
||||
* to match the remaining length of the string.
|
||||
* @param len_tok The length of the returned token.
|
||||
* @return The address to the token found or nullptr.
|
||||
*/
|
||||
template <typename T>
|
||||
T *tokenize2(T *&str, const char *delim, size_t &len_source, size_t &len_tok);
|
||||
|
||||
/**
|
||||
* @brief Splits a string into several tokens separated by one of the specified
|
||||
* delimiter characters. A delimiter character is ignored if it occurs in
|
||||
* a quoted string or if it is protected by a backslash. Likewise quotes
|
||||
* may be protected by a backslash. By default, leading and trailing
|
||||
* whitespaces will be trimmed if they occur outside of a quoted string
|
||||
* and if they are not protected by a backslash.
|
||||
* In contrast to the splitExt method this function operates entirely on
|
||||
* the source string without modifying it or creating any copies.
|
||||
* @param lenSource Returns remaining length of source string
|
||||
* @param lenTok Returns length of current token
|
||||
* @param source The source string
|
||||
* @param delimFound Returns the delimiter character found or 0 if the end of
|
||||
* the source string was reached
|
||||
* @param delimiter Sequence of characters to spit the string at
|
||||
* @param trim Request trimming of whitespaces
|
||||
* @param whitespace Sequence of characters to interpret as a whitespace
|
||||
* @param quotes Sequence of characters to interpret as a quote
|
||||
* @return Pointer to the next token within the source string, length of the
|
||||
* token and number of remaining characters in the source string.
|
||||
*/
|
||||
SC_SYSTEM_CORE_API
|
||||
const char *tokenizeExt(size_t &lenTok, size_t &lenSource, const char *&source,
|
||||
char &delimFound, const char *delimiter = ",",
|
||||
bool trim = true,
|
||||
const char *whitespaces = " \t\n\v\f\r",
|
||||
const char *quotes = "\"'");
|
||||
|
||||
/**
|
||||
* @brief Splits a string into several tokens separated by one of the specified
|
||||
* delimiter characters. A delimiter character is ignored if it occurs in
|
||||
* a quoted string or if it is protected by a backslash. Likewise quotes
|
||||
* may be protected by a backslash. By default, leading and trailing
|
||||
* whitespaces will be trimmed if they occur outside of a quoted string
|
||||
* and if they are not protected by a backslash.
|
||||
* Unlike the tokenizeExt variant this function will modify the source
|
||||
* string and remove surrounding quotes and will unescape certain
|
||||
* characters.
|
||||
* In particular a backslash outside quotes is removed if it protects a
|
||||
* backslash, a whitespace, a quote or a delimiter character. While a
|
||||
* backslash inside quotes only is removed if it protects a backslash or
|
||||
* the beginning quote character.
|
||||
* @param lenSource Returns remaining length of source string
|
||||
* @param lenTok Returns length of current token
|
||||
* @param source The source string
|
||||
* @param delimFound Returns the delimiter character found or 0 if the end of
|
||||
* the source string was reached
|
||||
* @param delimiter Sequence of characters to spit the string at
|
||||
* @param trim Request trimming of whitespaces
|
||||
* @param whitespace Sequence of characters to interpret as a whitespace
|
||||
* @param quotes Sequence of characters to interpret as a quote
|
||||
* @return Pointer to the next token within the source string, length of the
|
||||
* token and number of remaining characters in the source string.
|
||||
*/
|
||||
SC_SYSTEM_CORE_API
|
||||
const char *tokenizeUnescape(size_t &lenTok, size_t &lenSource, char *&source,
|
||||
char &delimFound, const char *delimiter = ",",
|
||||
bool trim = true,
|
||||
const char *whitespaces = " \t\n\v\f\r",
|
||||
const char *quotes = "\"'");
|
||||
|
||||
SC_SYSTEM_CORE_API bool isEmpty(const char*);
|
||||
|
||||
/**
|
||||
* @brief Removes whitespaces from the front of a string.
|
||||
* @param data The data pointer which will be advanced until the first
|
||||
* non-whitespace was found.
|
||||
* @param len The length of the input string which will hold the effective length
|
||||
* if the trimmed string.
|
||||
* @return The pointer to the first non-whitespace character.
|
||||
*/
|
||||
char *trimFront(char *&data, size_t &len);
|
||||
const char *trimFront(const char *&data, size_t &len);
|
||||
|
||||
/**
|
||||
* @brief Removes whitespaces from the back of a string.
|
||||
* @param data The input data pointer.
|
||||
* @param len The length of the input string which will hold the effective length
|
||||
* if the trimmed string.
|
||||
* @return The input pointer.
|
||||
*/
|
||||
char *trimBack(char *data, size_t &len);
|
||||
const char *trimBack(const char *data, size_t &len);
|
||||
|
||||
/**
|
||||
* @brief Strips whitespaces from the front and the back of the string.
|
||||
* @param data The data pointer which will be advanced until the first
|
||||
* non-whitespace was found.
|
||||
* @param len The length of the input string which will hold the effective length
|
||||
* if the trimmed string.
|
||||
* @return The pointer to the first non-whitespace character.
|
||||
*/
|
||||
char *trim(char *&data, size_t &len);
|
||||
const char *trim(const char *&data, size_t &len);
|
||||
|
||||
char *strnchr(char *p, size_t n, char c);
|
||||
const char *strnchr(const char *p, size_t n, char c);
|
||||
|
||||
/**
|
||||
* @brief Advances a data pointer
|
||||
* @param data Pointer to beginning of the string
|
||||
* @param len Length of input and output string.
|
||||
* @param offset The number of characters to advance the data pointer.
|
||||
* @return The pointer to the advanced string.
|
||||
*/
|
||||
const char *advance(const char *&data, size_t &len, size_t offset);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the number of "significant" digits including leading zeros
|
||||
* after the decimal point w.r.t. base 10.
|
||||
*
|
||||
* Example (fractionOnly = true): 0.1234 = 4, 0.001 = 3, 123.45678 = 5
|
||||
* Example (fractionOnly = false): 0.1234 = 4, 0.001 = 3, 123.45678 = 8
|
||||
*
|
||||
* Actually a floating point value cannot be converted into a string
|
||||
* in a perfect way. This function exists in order to output a floating
|
||||
* point value with the number of most significant digits. "Most significant"
|
||||
* means that if for one digits the difference between its representation and
|
||||
* a number which cuts all subsequent digits is less than 1E-(6 + digit) then
|
||||
* this is the last significant digit. Actually two digits separated by six
|
||||
* or more zeros are cut. For example the number 0.500000001 has one
|
||||
* significant digits only because 5 and 1 are separated by 7 zeros.
|
||||
*
|
||||
* @param value The input value
|
||||
* @param fractionOnly Whether the fraction only or also the integer part
|
||||
* should be considered.
|
||||
* @return The number of digits to base 10
|
||||
*/
|
||||
size_t digits10(float value, bool fractionOnly = true);
|
||||
size_t digits10(double value, bool fractionOnly = true);
|
||||
|
||||
|
||||
/**
|
||||
* @brief A helper class that allows to write to STL containers in
|
||||
* combination with boost iostreams.
|
||||
*/
|
||||
template<typename Container>
|
||||
class ContainerSink {
|
||||
public:
|
||||
typedef typename Container::value_type char_type;
|
||||
typedef boost::iostreams::sink_tag category;
|
||||
ContainerSink(Container &container)
|
||||
: _container(container) { }
|
||||
|
||||
std::streamsize write(const char_type *s, std::streamsize n) {
|
||||
_container.insert(_container.end(), s, s + n);
|
||||
return n;
|
||||
}
|
||||
|
||||
Container &container() { return _container; }
|
||||
|
||||
private:
|
||||
ContainerSink operator=(const ContainerSink&);
|
||||
Container &_container;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief A helper class that allows to read from STL containers in
|
||||
* combination with boost iostreams.
|
||||
*/
|
||||
template<typename Container>
|
||||
class ContainerSource {
|
||||
public:
|
||||
typedef typename Container::value_type char_type;
|
||||
typedef boost::iostreams::source_tag category;
|
||||
ContainerSource(const Container &container)
|
||||
: _container(container), _pos(0) {}
|
||||
|
||||
std::streamsize read(char_type* s, std::streamsize n) {
|
||||
std::streamsize amt = static_cast<std::streamsize>(_container.size() - _pos);
|
||||
std::streamsize result = (std::min)(n, amt);
|
||||
if ( result != 0 ) {
|
||||
copy(_container.begin() + _pos, _container.begin() + _pos + result, s);
|
||||
_pos += result;
|
||||
return result;
|
||||
}
|
||||
return -1; // EOF
|
||||
}
|
||||
|
||||
Container &container() { return _container; }
|
||||
|
||||
private:
|
||||
typedef typename Container::size_type size_type;
|
||||
const Container &_container;
|
||||
size_type _pos;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include <seiscomp/core/strings.ipp>
|
||||
|
||||
#endif
|
440
include/seiscomp/core/strings.ipp
Normal file
440
include/seiscomp/core/strings.ipp
Normal file
@ -0,0 +1,440 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include <seiscomp/core/enumeration.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <sstream>
|
||||
#include <complex>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline std::string toString(const T &v) {
|
||||
std::ostringstream os;
|
||||
os << v;
|
||||
return os.str();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <>
|
||||
inline std::string toString(const float &v) {
|
||||
std::ostringstream os;
|
||||
os << number(v);
|
||||
return os.str();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <>
|
||||
inline std::string toString(const double &v) {
|
||||
std::ostringstream os;
|
||||
os << number(v);
|
||||
return os.str();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline std::string toString(const std::complex<T>& v) {
|
||||
std::ostringstream os;
|
||||
os << "(" << number(v.real()) << "," << number(v.imag()) << ")";
|
||||
return os.str();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
std::string toString(const Enum<ENUMTYPE, END, NAMES>& value) {
|
||||
return value.toString();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline std::string toString(const std::vector<T>& v) {
|
||||
typename std::vector<T>::const_iterator it = v.begin();
|
||||
std::string str;
|
||||
if ( it != v.end() )
|
||||
str += toString(*it);
|
||||
else
|
||||
return "";
|
||||
|
||||
++it;
|
||||
|
||||
while ( it != v.end() ) {
|
||||
str += " ";
|
||||
str += toString(*it);
|
||||
++it;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline std::string toString(const ::boost::optional<T>& v) {
|
||||
if ( !v )
|
||||
return "None";
|
||||
|
||||
return toString(*v);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||||
bool fromString(Enum<ENUMTYPE, END, NAMES>& value, const std::string& str) {
|
||||
return value.fromString(str);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline bool fromString(std::complex<T>& value, const std::string& str) {
|
||||
size_t s = str.find_first_not_of(' ');
|
||||
size_t e = str.find_last_not_of(' ');
|
||||
if ( s == std::string::npos || e == std::string::npos )
|
||||
return false;
|
||||
|
||||
if ( str[s] != '(' || str[e] != ')' )
|
||||
return false;
|
||||
|
||||
size_t delimPos = str.find(',', s+1);
|
||||
if ( delimPos == std::string::npos )
|
||||
return false;
|
||||
|
||||
T realPart, imgPart;
|
||||
|
||||
if ( !fromString(realPart, str.substr(s+1, delimPos-s-1)) ) return false;
|
||||
if ( !fromString(imgPart, str.substr(delimPos+1, e-delimPos-1)) ) return false;
|
||||
|
||||
value = std::complex<T>(realPart, imgPart);
|
||||
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline bool fromString(std::vector<T>& vec, const std::string& str) {
|
||||
std::vector<std::string> tokens;
|
||||
split(tokens, str.c_str(), " ");
|
||||
for ( size_t i = 0; i < tokens.size(); ++i ) {
|
||||
T v;
|
||||
if ( !fromString(v, tokens[i]) )
|
||||
return false;
|
||||
vec.push_back(v);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline bool fromString(std::vector<std::complex<T> >& vec, const std::string& str) {
|
||||
std::vector<std::string> tokens;
|
||||
split(tokens, str.c_str(), " ");
|
||||
for ( size_t i = 0; i < tokens.size(); ++i ) {
|
||||
std::complex<T> v;
|
||||
int count = 1;
|
||||
|
||||
size_t countPos = tokens[i].find_first_not_of(' ');
|
||||
if ( countPos != std::string::npos ) {
|
||||
if ( tokens[i][countPos] != '(' ) {
|
||||
size_t bracketPos = tokens[i].find('(', countPos);
|
||||
// Invalid complex string
|
||||
if ( bracketPos == std::string::npos ) continue;
|
||||
if ( !fromString(count, tokens[i].substr(countPos, bracketPos-countPos)) )
|
||||
return false;
|
||||
tokens[i] = tokens[i].substr(bracketPos);
|
||||
}
|
||||
}
|
||||
|
||||
if ( !fromString(v, tokens[i]) ) return false;
|
||||
for ( int i = 0; i < count; ++i )
|
||||
vec.push_back(v);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline void toHex(std::string &target, T source) {
|
||||
static const char *hex = "0123456789ABCDEF";
|
||||
unsigned char *bytes = reinterpret_cast<unsigned char*>(&source);
|
||||
for ( size_t i = 0; i < sizeof(T); ++i ) {
|
||||
target += hex[bytes[i] & 0x0F];
|
||||
target += hex[(bytes[i] >> 4) & 0x0F];
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline T *tokenize(T *&str, const char *delim, size_t &len_source, size_t &len_tok) {
|
||||
len_tok = 0;
|
||||
for ( ; len_source; --len_source, ++str ) {
|
||||
// Hit first non delimiter?
|
||||
if ( strchr(delim, *str) == nullptr ) {
|
||||
T *tok = str;
|
||||
|
||||
++str; --len_source;
|
||||
len_tok = 1;
|
||||
|
||||
// Hit first delimiter?
|
||||
for ( ; len_source; --len_source, ++str, ++len_tok ) {
|
||||
if ( strchr(delim, *str) != nullptr )
|
||||
break;
|
||||
}
|
||||
return tok;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline T *tokenize2(T *&str, const char *delim, size_t &len_source, size_t &len_tok) {
|
||||
len_tok = 0;
|
||||
|
||||
if ( !len_source ) return nullptr;
|
||||
|
||||
T *tok = str;
|
||||
for ( ; len_source; --len_source, ++str, ++len_tok ) {
|
||||
// Hit delimiter?
|
||||
if ( strchr(delim, *str) != nullptr ) {
|
||||
// Move over delim
|
||||
++str;
|
||||
--len_source;
|
||||
return tok;
|
||||
}
|
||||
}
|
||||
|
||||
return tok;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline char *trimFront(char *&data, size_t &len) {
|
||||
while ( len ) {
|
||||
if ( !isspace(*data) ) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
++data;
|
||||
--len;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const char *trimFront(const char *&data, size_t &len) {
|
||||
while ( len ) {
|
||||
if ( !isspace(*data) ) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
++data;
|
||||
--len;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline char *trimBack(char *data, size_t &len) {
|
||||
while ( len ) {
|
||||
if ( !isspace(data[len-1]) ) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
--len;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const char *trimBack(const char *data, size_t &len) {
|
||||
while ( len ) {
|
||||
if ( !isspace(data[len-1]) ) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
--len;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline char *trim(char *&data, size_t &len) {
|
||||
trimFront(data, len);
|
||||
trimBack(data, len);
|
||||
return data;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const char *trim(const char *&data, size_t &len) {
|
||||
trimFront(data, len);
|
||||
trimBack(data, len);
|
||||
return data;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const char *advance(const char *&data, size_t &len, size_t offset) {
|
||||
data += offset;
|
||||
len -= offset;
|
||||
return data;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <class CONT>
|
||||
inline std::string join(const CONT &tokens, const char *separator) {
|
||||
static std::string defaultSeparator = ",";
|
||||
|
||||
if ( !separator ) separator = defaultSeparator.c_str();
|
||||
|
||||
std::string s;
|
||||
bool first = true;
|
||||
for ( auto &&item : tokens ) {
|
||||
if ( !first ) {
|
||||
s += separator;
|
||||
}
|
||||
else {
|
||||
first = false;
|
||||
}
|
||||
s += item;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <class CONT>
|
||||
std::string join(const CONT &tokens, const std::string &separator) {
|
||||
return join(tokens, separator.c_str());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename S, typename... Args>
|
||||
inline std::string stringify(const S &format, Args &&...args) {
|
||||
return fmt::vsprintf(format, fmt::make_printf_args(args...));
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
124
include/seiscomp/core/system.h
Normal file
124
include/seiscomp/core/system.h
Normal file
@ -0,0 +1,124 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CORE_SYSTEM_H
|
||||
#define SEISCOMP_CORE_SYSTEM_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
#include <boost/version.hpp>
|
||||
#if BOOST_VERSION < 108600
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
#else
|
||||
#include <boost/filesystem.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
#if BOOST_VERSION <= 103301
|
||||
#define SC_FS_IT_LEAF(it) it->leaf()
|
||||
#define SC_FS_IT_STR(it) it->string()
|
||||
#define SC_FS_IT_PATH(it) *it
|
||||
#else
|
||||
#if BOOST_FILESYSTEM_VERSION >= 3
|
||||
#define SC_FS_IT_LEAF(it) it->path().filename().string()
|
||||
#else
|
||||
#define SC_FS_IT_LEAF(it) it->path().leaf()
|
||||
#endif
|
||||
#define SC_FS_IT_PATH(it) it->path()
|
||||
#define SC_FS_IT_STR(it) it->path().string()
|
||||
#endif
|
||||
|
||||
//see, http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/deprecated.html
|
||||
#if BOOST_FILESYSTEM_VERSION >= 3
|
||||
#define BOOST_FILESYSTEM_NO_DEPRECATED
|
||||
|
||||
// path
|
||||
#define SC_FS_PATH(PATH_STR) boost::filesystem::path(PATH_STR)
|
||||
#define SC_FS_DECLARE_PATH(NAME, PATH_STR) \
|
||||
boost::filesystem::path NAME(PATH_STR);
|
||||
|
||||
#define SC_FS_FILE_PATH(PATH) PATH.filename()
|
||||
#define SC_FS_FILE_NAME(PATH) SC_FS_FILE_PATH(PATH).string()
|
||||
|
||||
#define SC_FS_HAS_PARENT_PATH(PATH) PATH.has_parent_path()
|
||||
#define SC_FS_PARENT_PATH(PATH) PATH.parent_path()
|
||||
|
||||
#define SC_FS_EXT_PATH(PATH) PATH.extension()
|
||||
#define SC_FS_EXT_NAME(PATH) SC_FS_EXT_PATH(PATH).string()
|
||||
#define SC_FS_STEM_PATH(PATH) PATH.stem()
|
||||
#define SC_FS_STEM_NAME(PATH) SC_FS_STEM_PATH(PATH).string()
|
||||
|
||||
// operations
|
||||
#define SC_FS_IS_REGULAR_FILE(PATH) boost::filesystem::is_regular_file(PATH)
|
||||
|
||||
// directory entry
|
||||
#define SC_FS_DE_PATH(DIRENT) DIRENT->path()
|
||||
#else
|
||||
// path
|
||||
#define SC_FS_PATH(PATH_STR) boost::filesystem::path(PATH_STR,\
|
||||
boost::filesystem::native)
|
||||
#define SC_FS_DECLARE_PATH(NAME, PATH_STR) \
|
||||
boost::filesystem::path NAME(PATH_STR, boost::filesystem::native);
|
||||
|
||||
#if BOOST_VERSION < 103600
|
||||
#define SC_FS_FILE_NAME(PATH) PATH.leaf()
|
||||
#define SC_FS_EXT_NAME(PATH) boost::filesystem::extension(PATH)
|
||||
#define SC_FS_STEM_NAME(PATH) boost::filesystem::basename(PATH)
|
||||
#define SC_FS_HAS_PARENT_PATH(PATH) PATH.has_branch_path()
|
||||
#define SC_FS_PARENT_PATH(PATH) PATH.branch_path()
|
||||
#define SC_FS_IS_REGULAR_FILE(PATH) boost::filesystem::is_regular(PATH)
|
||||
#else
|
||||
#define SC_FS_FILE_NAME(PATH) PATH.filename()
|
||||
#define SC_FS_EXT_NAME(PATH) PATH.extension()
|
||||
#define SC_FS_STEM_NAME(PATH) PATH.stem()
|
||||
#define SC_FS_HAS_PARENT_PATH(PATH) PATH.has_parent_path()
|
||||
#define SC_FS_PARENT_PATH(PATH) PATH.parent_path()
|
||||
#define SC_FS_IS_REGULAR_FILE(PATH) boost::filesystem::is_regular_file(PATH)
|
||||
#endif
|
||||
#define SC_FS_FILE_PATH(PATH) SC_FS_PATH(SC_FS_FILE_NAME(PATH))
|
||||
#define SC_FS_EXT_PATH(PATH) SC_FS_PATH(SC_FS_EXT_NAME(PATH))
|
||||
#define SC_FS_STEM_PATH(PATH) SC_FS_PATH(SC_FS_STEM_NAME(PATH))
|
||||
|
||||
// directory entry
|
||||
#if BOOST_VERSION <= 103301
|
||||
#define SC_FS_DE_PATH(DIRENT) (*DIRENT)
|
||||
#else
|
||||
#define SC_FS_DE_PATH(DIRENT) DIRENT->path()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
SC_SYSTEM_CORE_API std::string getHostname();
|
||||
|
||||
SC_SYSTEM_CORE_API void sleep(unsigned long seconds);
|
||||
SC_SYSTEM_CORE_API void msleep(unsigned long milliseconds);
|
||||
|
||||
SC_SYSTEM_CORE_API bool system(const std::string& command);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
178
include/seiscomp/core/timewindow.h
Normal file
178
include/seiscomp/core/timewindow.h
Normal file
@ -0,0 +1,178 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SC_CORE_TIMESPAN_H
|
||||
#define SC_CORE_TIMESPAN_H
|
||||
|
||||
#include<seiscomp/core.h>
|
||||
#include<seiscomp/core/datetime.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
class SC_SYSTEM_CORE_API TimeWindow {
|
||||
|
||||
// Xstruction
|
||||
public:
|
||||
TimeWindow();
|
||||
TimeWindow(const Time &startTime, double length);
|
||||
TimeWindow(const Time &startTime, const Time &endTime);
|
||||
TimeWindow(const TimeWindow &tw);
|
||||
~TimeWindow() {}
|
||||
|
||||
// Operators
|
||||
public:
|
||||
bool operator==(const TimeWindow&) const;
|
||||
bool operator!=(const TimeWindow&) const;
|
||||
operator bool() const;
|
||||
|
||||
//! Returns the minimal timewindow including this and other
|
||||
TimeWindow operator|(const TimeWindow &other) const;
|
||||
|
||||
// more operators :-)
|
||||
|
||||
// Interface
|
||||
public:
|
||||
Time startTime() const;
|
||||
Time endTime() const;
|
||||
double length() const;
|
||||
|
||||
void set(const Time &t1, const Time &t2);
|
||||
void setStartTime(const Time &t);
|
||||
void setEndTime(const Time &t);
|
||||
//! set length in seconds, affects endTime
|
||||
void setLength(double length);
|
||||
|
||||
//! does it contain time t?
|
||||
bool contains(const Time &t) const;
|
||||
|
||||
//! does it contain time window tw completely?
|
||||
bool contains(const TimeWindow &tw) const;
|
||||
|
||||
//! is equal to time window?
|
||||
//! +/- tolerance in seconds
|
||||
bool equals(const TimeWindow &tw, double tolerance=0.0) const;
|
||||
|
||||
//! does it overlap with time window tw?
|
||||
bool overlaps(const TimeWindow &tw) const;
|
||||
|
||||
//! compute overlap with time window tw
|
||||
TimeWindow overlap(const TimeWindow &tw) const;
|
||||
|
||||
//! test if this+other would form a contiguous time window
|
||||
bool contiguous(const TimeWindow&, double tolerance=0) const;
|
||||
|
||||
//! extend time window by appending the other (without check!)
|
||||
void extend(const TimeWindow&);
|
||||
|
||||
//! merges this and other to the minimal timewindow overlapping both
|
||||
TimeWindow merge(const TimeWindow&) const;
|
||||
|
||||
// Implementation
|
||||
private:
|
||||
Time _startTime, _endTime;
|
||||
};
|
||||
|
||||
|
||||
inline TimeWindow::TimeWindow()
|
||||
{
|
||||
set(Time(), Time());
|
||||
}
|
||||
|
||||
inline TimeWindow::TimeWindow(const Time &startTime, double length)
|
||||
{
|
||||
set(startTime, startTime + Time(length)); // FIXME
|
||||
}
|
||||
|
||||
inline TimeWindow::TimeWindow(const Time &startTime, const Time &endTime)
|
||||
{
|
||||
set(startTime, endTime);
|
||||
}
|
||||
|
||||
inline TimeWindow::TimeWindow(const TimeWindow &tw)
|
||||
{
|
||||
set(tw._startTime, tw._endTime);
|
||||
}
|
||||
|
||||
inline bool TimeWindow::operator==(const TimeWindow &tw) const
|
||||
{
|
||||
return _startTime == tw._startTime && _endTime == tw._endTime;
|
||||
}
|
||||
|
||||
inline bool TimeWindow::operator!=(const TimeWindow &tw) const
|
||||
{
|
||||
return _startTime != tw._startTime || _endTime != tw._endTime;
|
||||
}
|
||||
|
||||
inline TimeWindow::operator bool() const
|
||||
{
|
||||
return (bool)_startTime && (bool)_endTime;
|
||||
}
|
||||
|
||||
inline Time TimeWindow::startTime() const
|
||||
{
|
||||
return _startTime;
|
||||
}
|
||||
|
||||
inline Time TimeWindow::endTime() const
|
||||
{
|
||||
return _endTime;
|
||||
}
|
||||
|
||||
inline double TimeWindow::length() const
|
||||
{
|
||||
return (double)(_endTime-_startTime);
|
||||
}
|
||||
|
||||
inline void TimeWindow::set(const Time &startTime, const Time &endTime)
|
||||
{
|
||||
_startTime = startTime;
|
||||
_endTime = endTime;
|
||||
}
|
||||
|
||||
inline void TimeWindow::setStartTime(const Time &t)
|
||||
{
|
||||
_startTime = t;
|
||||
}
|
||||
|
||||
inline void TimeWindow::setEndTime(const Time &t)
|
||||
{
|
||||
_endTime = t;
|
||||
}
|
||||
|
||||
inline void TimeWindow::setLength(double length)
|
||||
{
|
||||
_endTime = _startTime + Time(length); // FIXME
|
||||
}
|
||||
|
||||
inline bool TimeWindow::contains(const Time &t) const
|
||||
{
|
||||
return t >= _startTime && t < _endTime;
|
||||
}
|
||||
|
||||
inline bool TimeWindow::contains(const TimeWindow &tw) const
|
||||
{
|
||||
return tw._startTime >= _startTime && tw._endTime <= _endTime;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
306
include/seiscomp/core/typedarray.h
Normal file
306
include/seiscomp/core/typedarray.h
Normal file
@ -0,0 +1,306 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SC_CORE_TYPEDARRAY_H
|
||||
#define SC_CORE_TYPEDARRAY_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <complex>
|
||||
#include <cstdint>
|
||||
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/core/array.h>
|
||||
#include <seiscomp/core/arrayfactory.h>
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(min)
|
||||
#undef min
|
||||
#endif
|
||||
#if defined(max)
|
||||
#undef max
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
|
||||
/**
|
||||
* Class defining different types of arrays (such as CharArray, IntArray, FloatArray, DoubleArray).
|
||||
*/
|
||||
template<typename T>
|
||||
class TypedArray : public Array {
|
||||
DECLARE_SC_CLASS(TypedArray);
|
||||
DECLARE_SERIALIZATION;
|
||||
|
||||
public:
|
||||
typedef typename std::vector<T> DataArray;
|
||||
typedef typename DataArray::iterator iterator;
|
||||
typedef typename DataArray::const_iterator const_iterator;
|
||||
|
||||
typedef T Type;
|
||||
static DataType ArrayType;
|
||||
|
||||
//! Default Constructor
|
||||
TypedArray();
|
||||
|
||||
//! Initializing Constructor
|
||||
TypedArray(int size);
|
||||
|
||||
//! Initializing Constructor
|
||||
TypedArray(int size, const T* data);
|
||||
|
||||
//! Copy Constructor
|
||||
TypedArray(const TypedArray &array);
|
||||
|
||||
//! Destructor
|
||||
virtual ~TypedArray();
|
||||
|
||||
//! Assignment operator
|
||||
TypedArray& operator=(const TypedArray &array);
|
||||
|
||||
//! Index operator
|
||||
T operator[](int index) const;
|
||||
T& operator[](int index);
|
||||
|
||||
//! Returns an array of the specified data type.
|
||||
Array* copy(DataType dt) const override;
|
||||
|
||||
//! Sets the data from a typed memory chunk
|
||||
void setData(int size, const T* data);
|
||||
|
||||
//! Returns the data address pointer.
|
||||
const void* data() const override;
|
||||
|
||||
//! Returns the typed data pointer
|
||||
T* typedData();
|
||||
const T* typedData() const;
|
||||
|
||||
//! Returns the size of the array.
|
||||
int size() const override;
|
||||
|
||||
//! Returns the number of bytes of an array element.
|
||||
int elementSize() const override;
|
||||
|
||||
//! Resizes the array
|
||||
void resize(int size) override;
|
||||
|
||||
//! Drops all elements.
|
||||
void clear() override;
|
||||
|
||||
//! Sets all values to v
|
||||
void fill(const T &v);
|
||||
|
||||
//! Sets the element at a given index
|
||||
void set(int index, T v);
|
||||
|
||||
//! Returns the element at the given index.
|
||||
T get(int index) const;
|
||||
|
||||
//! Concatenates the given array to this array.
|
||||
void append(const Array *array) override;
|
||||
|
||||
//! Concatenates the given array to this array.
|
||||
void append(int size, const T* data);
|
||||
|
||||
//! Appends value n-times to this array.
|
||||
void append(int n, T value);
|
||||
|
||||
//! Concatenates this array to the given array and store the result
|
||||
//! in this array.
|
||||
void prepend(const Array *array);
|
||||
|
||||
//! Concatenates this array to the given array and store the result
|
||||
//! in this array.
|
||||
void prepend(int size, const T* data);
|
||||
|
||||
//! Prepends value n-times to this array.
|
||||
void prepend(int n, T value);
|
||||
|
||||
//! Returns the slice m...n-1 of the array
|
||||
TypedArray<T>* slice(int m, int n) const override;
|
||||
|
||||
//! Returns an iterator to the first element of the array
|
||||
iterator begin();
|
||||
|
||||
//! Returns an const_iterator to the first element of the array
|
||||
const_iterator begin() const;
|
||||
|
||||
//! Returns an iterator just past the end of the array
|
||||
iterator end();
|
||||
|
||||
//! Returns an const_iterator just past the end of the array
|
||||
const_iterator end() const;
|
||||
|
||||
const DataArray &impl() const { return _data; }
|
||||
DataArray &impl() { return _data; }
|
||||
|
||||
|
||||
protected:
|
||||
DataArray _data;
|
||||
|
||||
friend class ArrayFactory;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
class NumericArray : public TypedArray<T> {
|
||||
DECLARE_SC_CLASS(NumericArray);
|
||||
|
||||
public:
|
||||
//! Default Constructor
|
||||
NumericArray();
|
||||
|
||||
//! Initializing Constructor
|
||||
NumericArray(int size);
|
||||
|
||||
//! Initializing Constructor
|
||||
NumericArray(int size, const T* data);
|
||||
|
||||
//! Copy Constructor
|
||||
NumericArray(const NumericArray &array);
|
||||
|
||||
//! Destructor
|
||||
virtual ~NumericArray();
|
||||
|
||||
//! Assignment operator
|
||||
NumericArray& operator=(const NumericArray &array);
|
||||
|
||||
//! Returns the maximum value of the array elements.
|
||||
T max() const;
|
||||
|
||||
//! Returns the first local maximum value of the array elements.
|
||||
T firstMax() const;
|
||||
|
||||
//! Returns the maximum of the absolute values of the array elements.
|
||||
T absMax() const;
|
||||
|
||||
//! Returns the minimum value of the array elements.
|
||||
T min() const;
|
||||
|
||||
//! Returns the median value of the array elements.
|
||||
T median() const;
|
||||
|
||||
//! Returns the mean value of the array elements.
|
||||
T mean() const;
|
||||
|
||||
//! Returns the rms of the data using an offset if given.
|
||||
T rms(T offset = 0) const;
|
||||
|
||||
//! Returns the slice m...n-1 of the array
|
||||
NumericArray<T>* slice(int m, int n) const override;
|
||||
|
||||
NumericArray<T> &operator+=(T v);
|
||||
NumericArray<T> &operator-=(T v);
|
||||
NumericArray<T> &operator*=(T v);
|
||||
NumericArray<T> &operator/=(T v);
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef NumericArray<char> CharArray;
|
||||
TYPEDEF_SMARTPOINTER(CharArray);
|
||||
TYPEDEF_CONST_SMARTPOINTER(CharArray);
|
||||
|
||||
typedef NumericArray<std::int32_t> Int32Array;
|
||||
TYPEDEF_SMARTPOINTER(Int32Array);
|
||||
TYPEDEF_CONST_SMARTPOINTER(Int32Array);
|
||||
|
||||
typedef Int32Array IntArray;
|
||||
typedef Int32ArrayPtr IntArrayPtr;
|
||||
typedef Int32ArrayCPtr IntArrayCPtr;
|
||||
|
||||
typedef NumericArray<float> FloatArray;
|
||||
TYPEDEF_SMARTPOINTER(FloatArray);
|
||||
TYPEDEF_CONST_SMARTPOINTER(FloatArray);
|
||||
|
||||
typedef NumericArray<double> DoubleArray;
|
||||
TYPEDEF_SMARTPOINTER(DoubleArray);
|
||||
TYPEDEF_CONST_SMARTPOINTER(DoubleArray);
|
||||
|
||||
typedef TypedArray<Core::Time> DateTimeArray;
|
||||
TYPEDEF_SMARTPOINTER(DateTimeArray);
|
||||
TYPEDEF_CONST_SMARTPOINTER(DateTimeArray);
|
||||
|
||||
typedef TypedArray<std::string> StringArray;
|
||||
TYPEDEF_SMARTPOINTER(StringArray);
|
||||
TYPEDEF_CONST_SMARTPOINTER(StringArray);
|
||||
|
||||
typedef TypedArray< std::complex<float> > ComplexFloatArray;
|
||||
TYPEDEF_SMARTPOINTER(ComplexFloatArray);
|
||||
TYPEDEF_CONST_SMARTPOINTER(ComplexFloatArray);
|
||||
|
||||
typedef TypedArray< std::complex<double> > ComplexDoubleArray;
|
||||
TYPEDEF_SMARTPOINTER(ComplexDoubleArray);
|
||||
TYPEDEF_CONST_SMARTPOINTER(ComplexDoubleArray);
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline T TypedArray<T>::operator[](int index) const {
|
||||
return _data[index];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T& TypedArray<T>::operator[](int index) {
|
||||
return _data[index];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int TypedArray<T>::size() const {
|
||||
return _data.size();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void TypedArray<T>::set(int index, T v) {
|
||||
_data[index] = v;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T TypedArray<T>::get(int index) const {
|
||||
return _data.at(index);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline typename TypedArray<T>::iterator TypedArray<T>::begin() {
|
||||
return _data.begin();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline typename TypedArray<T>::const_iterator TypedArray<T>::begin() const {
|
||||
return _data.begin();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline typename TypedArray<T>::iterator TypedArray<T>::end() {
|
||||
return _data.end();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline typename TypedArray<T>::const_iterator TypedArray<T>::end() const {
|
||||
return _data.end();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
734
include/seiscomp/core/version.h
Normal file
734
include/seiscomp/core/version.h
Normal file
@ -0,0 +1,734 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SC_CORE_VERSION_H
|
||||
#define SC_CORE_VERSION_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Core {
|
||||
|
||||
|
||||
/* #if (SC_API_VERSION >= SC_API_VERSION_CHECK(16, 4, 0)) */
|
||||
#define SC_API_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
|
||||
|
||||
|
||||
/* SC_API_VERSION is (major << 16) + (minor << 8) + patch. */
|
||||
#define SC_API_VERSION 0x100400
|
||||
|
||||
#define SC_API_VERSION_MAJOR(v) (v >> 16)
|
||||
#define SC_API_VERSION_MINOR(v) ((v >> 8) & 0xff)
|
||||
#define SC_API_VERSION_PATCH(v) (v & 0xff)
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
API Changelog
|
||||
******************************************************************************
|
||||
|
||||
"16.4.0" 0x100400
|
||||
- Added Seiscomp::Math::double2frac
|
||||
|
||||
"16.3.0" 0x100300
|
||||
- Added Seiscomp::Gui::Application::createCSV(view, header)
|
||||
- Added Seiscomp::Gui::RecordView::sortByText(item1, item2, item3)
|
||||
- Added Seiscomp::Gui::RecordView::sortByText(item1, item2, item3, item4)
|
||||
|
||||
"16.2.0" 0x100200
|
||||
- Added Seiscomp::DataModel::PublicObject::Lock
|
||||
- Added Seiscomp::DataModel::PublicObject::UnLock
|
||||
|
||||
"16.1.0" 0x100100
|
||||
- Added Seiscomp::DataModel::numberOfComponents
|
||||
|
||||
"16.0.0" 0x100000
|
||||
- Added Seiscomp::Core::digits10
|
||||
- Added Seiscomp::Client::Application::setDatabaseURI
|
||||
- Added Seiscomp::Client::Application::setRecordStreamURL
|
||||
- Removed Seiscomp::Math::round
|
||||
- Renamed GenericMessage::AttachementType to GenericMessage::AttachmentType
|
||||
- Renamed GenericMessage::AttachementList to GenericMessage::AttachmentList
|
||||
- Made Seiscomp::Gui::Ruler::rulerWidth() public
|
||||
- Made Seiscomp::Gui::Ruler::rulerHeight() public
|
||||
- Made Seiscomp::Gui::Ruler::isBottom() public
|
||||
- Made Seiscomp::Gui::Ruler::isTop() public
|
||||
- Made Seiscomp::Gui::Ruler::isLeft() public
|
||||
- Made Seiscomp::Gui::Ruler::isRight() public
|
||||
- Made Seiscomp::Gui::Ruler::isHorizontal() public
|
||||
- Made Seiscomp::Gui::Ruler::isVertical() public
|
||||
- Add second parameter to Seiscomp::Gui::Ruler::setPosition(pos, allowRotation)
|
||||
- Add Seiscomp::Gui::Ruler::setReverseDirection(bool)
|
||||
- Changed KM_OF_DEGREE constant according to WGS84 mean radius definition
|
||||
- Removed Seiscomp::Gui::Application::setDatabaseSOHInterval
|
||||
- Added Seiscomp::Client::Application::stateOfHealth
|
||||
- Removed virtual from Seiscomp::Core::BaseObject::operator=
|
||||
- Removed virtual from Seiscomp::Gui::Map::Layer::operator=
|
||||
- Changed signature of Seiscomp::Processing::MagnitudeProcessor::estimateMw
|
||||
- Removed Seiscomp::DataModel::DatabaseArchive::write(object, parentID)
|
||||
- Added Seiscomp::DataModel::DatabaseArchive::insert(object, parentID)
|
||||
- Added Seiscomp::Processing::NCompsOperator<>::buffer()
|
||||
- Added Seiscomp::Processing::NCompsOperator<>::proc()
|
||||
- Added Seiscomp::Processing::NCompsOperator<>::reset()
|
||||
- Added Seiscomp::Processing::CodeWrapper<>::reset()
|
||||
- Added Seiscomp::Processing::StreamConfigWrapper<>::proc()
|
||||
- Added Seiscomp::Processing::StreamConfigWrapper<>::reset()
|
||||
- Added Seiscomp::Processing::NoOpWrapper<>::reset()
|
||||
- Added Seiscomp::Processing::FilterWrapper<>::proc()
|
||||
- Added Seiscomp::Processing::FilterWrapper<>::reset()
|
||||
- Seiscomp::Geo::GeoCoordinate::ValueType = double
|
||||
- Added Seiscomp::TravelTimeTableInterface::computeTime()
|
||||
- Added Seiscomp::TravelTime::azi field
|
||||
- Seiscomp::Math::Geo::delazi() allows null arguments
|
||||
- Added Seiscomp::Math::Geo::delta()
|
||||
- Added Seiscomp::Util::StopWatch::microseconds()
|
||||
- Added Seiscomp::Util::StopWatch::nanoseconds()
|
||||
|
||||
"15.6.0" 0x0F0600
|
||||
- Added Seiscomp::Gui::PickerView::setAuxiliaryChannels
|
||||
|
||||
"15.5.0" 0x0F0500
|
||||
- Added Seiscomp::Utils::TabValues
|
||||
|
||||
"15.4.0" 0x0F0400
|
||||
- Added Seiscomp::Gui::RecordView::hasSelectedItems()
|
||||
- Added Seiscomp::Gui::RecordView::mapToTime()
|
||||
- Added Seiscomp::Gui::RecordView::mapToUnit()
|
||||
- Added Seiscomp::Gui::RecordView::setRubberBandSelectionEnabled()
|
||||
- Added Seiscomp::Gui::RecordView::SelectionOperation
|
||||
- Added Seiscomp::Gui::RecordView::SelectionOperationFlag
|
||||
- Added Seiscomp::Gui::RecordView::visibleTimeRange
|
||||
- Added signal Seiscomp::Gui::RecordView::selectedRubberBand()
|
||||
- Added Seiscomp::Gui::FlowLayout
|
||||
- Added Seiscomp::Gui::setBold
|
||||
- Added Seiscomp::Gui::setItalic
|
||||
|
||||
"15.3.0" 0x0F0300
|
||||
- Added Seiscomp::Client::ThreadedQueue::isClosed
|
||||
- Added Seiscomp::Client::ThreadedQueue::reset
|
||||
|
||||
"15.2.0" 0x0F0200
|
||||
- Added Seiscomp::Wired::peerCertificate
|
||||
- Added Seiscomp::Client::ThreadedQueue::reset
|
||||
- Added Seiscomp::DataModel::PublicObject::typeInfo
|
||||
|
||||
"15.1.0" 0x0F0100
|
||||
- Added Seiscomp::MetaObject::Find
|
||||
- Added Seiscomp::DataModel::Diff4
|
||||
- Added Seiscomp::DataModel::QML_NS
|
||||
- Added Seiscomp::DataModel::QML_NS_RT
|
||||
- Added Seiscomp::DataModel::QML_NS_BED
|
||||
- Added Seiscomp::DataModel::QML_NS_BED_RT
|
||||
- Added Seiscomp::DataModel::QML_SMIPrefixEnvVar
|
||||
- Added Seiscomp::Gui::Map::TileStore::loadingComplete
|
||||
- Added Seiscomp::Gui::Map::TileStore::loadingCancelled
|
||||
|
||||
"15.0.0" 0x0F0000
|
||||
- Added OriginUncertainty::confidenceLevel
|
||||
- Set DataModel version to 0.12
|
||||
- Added WindowFunc::apply(..., left, right)
|
||||
- Changed WindowFunc::process(int n, T *inout, double width)
|
||||
to WindowFunc::process(int n, T *inout, double left, double right)
|
||||
- Added locale to Seiscomp::Processing::MagnitudeProcessor::computeMagnitude
|
||||
- Removed Seiscomp::Processing::MagnitudeProcessor::correctMagnitude
|
||||
- Added signal Seiscomp::Gui::EventListView::visibleEventCountChanged()
|
||||
- Added Seiscomp::Gui::StationSymbol::setOutlineColor(QColor)
|
||||
- Removed Seiscomp::Core::Generic::Archive::read(int)
|
||||
- Removed Seiscomp::Core::Generic::Archive::write(int)
|
||||
- Removed Seiscomp::Core::Generic::Archive::read(time_t)
|
||||
- Removed Seiscomp::Core::Generic::Archive::write(time_t)
|
||||
- Removed Seiscomp::Core::Generic::Archive::read(std::vector<int>)
|
||||
- Removed Seiscomp::Core::Generic::Archive::write(std::vector<int>)
|
||||
- Added Seiscomp::Core::Generic::Archive::read(int8_t)
|
||||
- Added Seiscomp::Core::Generic::Archive::write(int8_t)
|
||||
- Added Seiscomp::Core::Generic::Archive::read(int16_t)
|
||||
- Added Seiscomp::Core::Generic::Archive::write(int16_t)
|
||||
- Added Seiscomp::Core::Generic::Archive::read(int32_t)
|
||||
- Added Seiscomp::Core::Generic::Archive::write(int32_t)
|
||||
- Added Seiscomp::Core::Generic::Archive::read(int64_t)
|
||||
- Added Seiscomp::Core::Generic::Archive::write(int64_t)
|
||||
- Added Seiscomp::Core::Generic::Archive::read(std::vector<int8_t>)
|
||||
- Added Seiscomp::Core::Generic::Archive::write(std::vector<int8_t>)
|
||||
- Added Seiscomp::Core::Generic::Archive::read(std::vector<int16_t>)
|
||||
- Added Seiscomp::Core::Generic::Archive::write(std::vector<int16_t>)
|
||||
- Added Seiscomp::Core::Generic::Archive::read(std::vector<int32_t>)
|
||||
- Added Seiscomp::Core::Generic::Archive::write(std::vector<int32_t>)
|
||||
- Added Seiscomp::Core::Generic::Archive::read(std::vector<int64_t>)
|
||||
- Added Seiscomp::Core::Generic::Archive::write(std::vector<int64_t>)
|
||||
- Added Seiscomp::Gui::Map::AnnotationItem
|
||||
- Added Seiscomp::Gui::Map::AnnotationStyle
|
||||
- Added Seiscomp::Gui::Map::Annotations
|
||||
- Added Seiscomp::Gui::Map::AnnotationLayer
|
||||
- Added Seiscomp::Core::Time::utc()
|
||||
- Added Seiscomp::Core::Time::UTC()
|
||||
- Added Seiscomp::Core::Time::toUTC()
|
||||
- Changed signature from
|
||||
Seiscomp::Core::trimBack(char *&data, size_t &len) to
|
||||
Seiscomp::Core::trimBack(char *data, size_t &len)
|
||||
- Set TileStore API to version 3 which is incompatible with previous versions
|
||||
- Remove Seiscomp::Gui::Alg::MapTree and Seiscomp::Gui::Alg::MapTreeNode
|
||||
- Added Seiscomp::DataModel::id(const Network*, ...)
|
||||
- Added Seiscomp::DataModel::id(const Station*, ...)
|
||||
- Added Seiscomp::DataModel::id(const SensorLocation*, ...)
|
||||
- Added Seiscomp::DataModel::id(const Stream*, ...)
|
||||
- Added virtual Seiscomp::Wired::Session::accepted()
|
||||
- Added Seiscomp::Wired::Socket::isAccepted()
|
||||
- Added Seiscomp::Util::catchBool
|
||||
- Fixed Python API for ExportSink::write to always pass bytes and
|
||||
remove size parameter
|
||||
- Added Regions::getFlinnEngdahlRegion
|
||||
- Removed public access of Regions constructor
|
||||
- Changed RecordWidget::Filter from float to double
|
||||
- Changed SLOT Gui::RecordWidget::setScale(double, float) to
|
||||
SLOT Gui::RecordWidget::setScale(double, double)
|
||||
- Changed SLOT Gui::RecordWidget::setAmplScale(float) to
|
||||
SLOT Gui::RecordWidget::setAmplScale(double)
|
||||
- Changed SIGNAL Gui::RecordView::scaleChanged(double, float) to
|
||||
Gui::RecordView::scaleChanged(double, double)
|
||||
- Changed SIGNAL Gui::RecordView::amplScaleChanged(float) to
|
||||
Gui::RecordView::amplScaleChanged(double)
|
||||
- Changed SLOT Gui::RecordView::setScale(double, float) to
|
||||
SLOT Gui::RecordView::setScale(double, double)
|
||||
|
||||
"14.4.0" 0x0E0400
|
||||
- Added class Seiscomp::Core::Number<T> (ostream output)
|
||||
- Added Seiscomp::Core::number<T>() (Number<T> generator)
|
||||
- Added Seiscomp::Processing::Picker::noiseWindow()
|
||||
- Added Seiscomp::Processing::Picker::signalWindow()
|
||||
- Added Seiscomp::DataModel::PublicObjectCache::contains(PublicObject*)
|
||||
- Added Seiscomp::DataModel::PublicObjectCache::contains(string)
|
||||
|
||||
"14.3.0" 0x0E0300
|
||||
- Added Seiscomp::RingBuffer::numberOfRecordsToStore()
|
||||
- Added Seiscomp::RingBuffer::timeSpanToStore()
|
||||
- Added Seiscomp::TimeWindowBuffer::timeWindowToStore()
|
||||
- Added Seiscomp::Gui::OriginLocatorMap::stationSymbolToolTip()
|
||||
- Added Seiscomp::Gui::MagnitudeMap::stationSymbolToolTip()
|
||||
- Added Seiscomp::Environment::resolvePath()
|
||||
- Added Seiscomp::Wired::Device::takeFd()
|
||||
- Added Seiscomp::Wired::SSLSocket::take()
|
||||
- Added Seiscomp::IO::Socket::takeFd()
|
||||
- Added Seiscomp::IO::SSLSocket::setFd()
|
||||
- Added Seiscomp::Geo::GeoFeature::setAttribute()
|
||||
- Added Seiscomp::Geo::GeoFeatureSet::readFile()
|
||||
- Added Seiscomp::Geo::GeoFeatureSet::readDir()
|
||||
- Added Seiscomp::Geo::readGeoJSON()
|
||||
- Deprecated Seiscomp::Geo::GeoFeatureSet::readBNAFile()
|
||||
- Deprecated Seiscomp::Geo::GeoFeatureSet::readBNADir()
|
||||
- Added Seiscomp::Gui::CM_SHOW_NOTIFICATION enumeration
|
||||
|
||||
"14.2.0" 0x0E0200
|
||||
- Added Seiscomp::Client::Application::injectMessage
|
||||
- Added RecordStream factory "caps" and "capss"
|
||||
|
||||
"14.1.0" 0x0E0100
|
||||
- Added Seiscomp::Wired::Session::handleTimeout
|
||||
- Declared Seiscomp::Geo::GeoFeature::area as deprecated
|
||||
- Added function Seiscomp::Geo::area which replaces
|
||||
Seiscomp::Geo::GeoFeature::area
|
||||
- Added functions Seiscomp::Geo::contains
|
||||
- Added Seiscomp::Math::Filtering::IIR::ButterworthBandstop
|
||||
- Added another Seiscomp::Math::Filtering::cosRamp function
|
||||
- Added Seiscomp::Gui::AdvancedOriginSymbol
|
||||
|
||||
"14.0.0" 0x0E0000
|
||||
- Added length based string functions to Seiscomp::Core:
|
||||
- tokenize
|
||||
- tokenize2
|
||||
- trimFront
|
||||
- trimBack
|
||||
- trim
|
||||
- strnchr
|
||||
- advance
|
||||
- Added seiscomp/wire package
|
||||
- Moved Client::Commandline to System::Commandline
|
||||
- Moved Client::PluginRegistry to System::PluginRegistry
|
||||
- Moved all functions from daemon.h from namespace Utils to namespace System
|
||||
- Added System::Application
|
||||
- Removed Core::Alarmable
|
||||
- Removed RecordStream::ODCArchive
|
||||
- Removed Seiscomp::Client::Application::sync
|
||||
- Removed Seiscomp::Client::Application::requestSync
|
||||
- Removed Seiscomp::Client::Application::handleStartSync
|
||||
- Removed Seiscomp::Client::Application::handleEndSync
|
||||
- Removed Seiscomp::Client::Application::handleSync
|
||||
- Renamed Seiscomp::Client::Connection::send to Seiscomp::Client::Connection::sendMessage
|
||||
- Added Gui::Map::MercatorProjection
|
||||
- Renamed include directories from seiscomp3/ to seiscomp/
|
||||
|
||||
"13.0.0" 0x0D0000
|
||||
- Added virtual Seiscomp::IO::Database::escape
|
||||
- Renamed Seiscomp::Array::bytes() to elementSize()
|
||||
- Added enums ZEP and REP to Seiscomp::Core::GreensfunctionComponent
|
||||
- Added Seiscomp::DataModel::touch(obj)
|
||||
- Changed database oid type to 64bit
|
||||
- Added Record::authentication and Record::authority
|
||||
- Seiscomp::Gui::Application does not inherit from QApplication anymore
|
||||
- Added Seiscomp::Gui::Map::Symbol::layerVisibilityChanged
|
||||
- Added Seiscomp::Gui::Map::Layer::setToolTip
|
||||
- Added Seiscomp::Gui::Map::Layer::toolTip
|
||||
- Added Seiscomp::Gui::Map::Layer::hasCursorShape
|
||||
- Added Seiscomp::Gui::Map::Layer::cursorShape
|
||||
- Added Seiscomp::Gui::Map::Layer::setCursorShape
|
||||
- Added Seiscomp::Gui::Map::Layer::unsetCursorShape
|
||||
- Added Seiscomp::Gui::Map::Layer::update
|
||||
- Added Seiscomp::Gui::Axis::ticks
|
||||
- Added Seiscomp::Gui::Axis::subTicks
|
||||
- Declared Seiscomp::Gui::Axis::updateLayout, sizeHint, draw and drawGrid virtual
|
||||
- Declared Seiscomp::Gui::Graph::unproject virtual
|
||||
|
||||
"12.3.0" 0x0C0300
|
||||
- Added ArtificialEventParametersMessage
|
||||
|
||||
"12.2.0" 0x0C0200
|
||||
- Added Application::waitEvent
|
||||
|
||||
"12.1.1" 0x0C0101
|
||||
- Fixed RecordWidget::mouseMoveEvent to not ignore handled events
|
||||
- Fixed libtau wrapper setModel initialization bug
|
||||
|
||||
"12.1.0" 0x0C0100
|
||||
- Fixed RecordWidget emitting of traceUpdated signal if the record slot to
|
||||
be shown has changed
|
||||
- Added non-const RecordWidget::traceInfo method
|
||||
- Added RecordWidget::recordPen(int) method
|
||||
|
||||
"12.0.0" 0x0C0000
|
||||
- Added Seiscomp::Core::Generic::Archive property interface
|
||||
- Added Seiscomp::DataModel::DatabaseQuery::getAmplitudes
|
||||
- Changed Seiscomp::DataModel::DatabaseArchive::toString() from protected to
|
||||
public const
|
||||
- Added Seiscomp::Core::Time::localTimeZoneOffset()
|
||||
- Removed geo prefix of all headers under <seiscomp/geo/>
|
||||
- Added Seiscomp::Util::UnitConverter
|
||||
- Added Seiscomp::Processing::WaveformProcessor::Status enumeration TravelTimeEstimateFailed
|
||||
- Added Seiscomp::Processing::MagnitudeProcessor::Status enumeration InvalidAmplitudeUnit
|
||||
- Added Seiscomp::Processing::MagnitudeProcessor::Status enumeration ReceiverOutOfRegions
|
||||
- Added Seiscomp::Processing::MagnitudeProcessor::Status enumeration RayPathOutOfRegions
|
||||
- Added Seiscomp::Processing::MagnitudeProcessor::Status enumeration MissingAmplitudeObject
|
||||
- Added Geo::GeoFeature::updateBoundingBox method
|
||||
- Added static method Seiscomp::Geo::GeoFeatureSet::load
|
||||
- Added class Seiscomp::Geo::GeoFeatureSetObserver
|
||||
- Added Seiscomp::Gui::Map::StandardLegend::clear
|
||||
- Added Seiscomp::Gui::Map::StandardLegend::count
|
||||
- Added Seiscomp::Gui::Map::StandardLegend::itemAt
|
||||
- Added Seiscomp::Gui::Map::StandardLegend::takeItem
|
||||
- Added Seiscomp::Gui::EventLegend
|
||||
- Removed Seiscomp::Gui::LayerProperties
|
||||
- Removed Seiscomp::Gui::Map::Canvas::drawGeoFeature(LayerProperties ...)
|
||||
- Added QPainter reference as 2nd parameter to Seiscomp::Gui::Map::Layer::bufferUpdated
|
||||
- Added QPainter reference as 2nd parameter to Seiscomp::Gui::Map::Layer::baseBufferUpdated
|
||||
- Added virtual Seiscomp::Gui::Map::Projection::project(QPainterPath, ...) method
|
||||
- Added Seiscomp::Gui::Map::Projection::boundingBox() method
|
||||
- Added enum Seiscomp::Gui::Map::FilterMode
|
||||
- Changed prototype of Seiscomp::Gui::Map::Canvas::drawImage and add filterMode
|
||||
parameter
|
||||
- Renamed Seiscomp::Gui::Canvas::drawGeoLine to Seiscomp::Gui::Canvas::drawLine
|
||||
- Renamed Seiscomp::Gui::Canvas::drawGeoPolyline to Seiscomp::Gui::Canvas::drawPolyline
|
||||
- Renamed Seiscomp::Gui::Canvas::drawGeoPolygon to Seiscomp::Gui::Canvas::drawPolygon
|
||||
- Renamed Seiscomp::Gui::Canvas::drawGeoFeature to Seiscomp::Gui::Canvas::drawFeature
|
||||
- Seiscomp::Gui::Scheme::colors.records.gaps/overlaps is now a brush rather than
|
||||
a color
|
||||
- Added Seiscomp::Gui::Plot::addAxis
|
||||
- Added Seiscomp::Processing::MagnitudeProcessor::Status enumeration IncompleteConfiguration
|
||||
- Added Seiscomp::Processing::AmplitudeProcessor::setEnvironment
|
||||
- Added Seiscomp::Processing::AmplitudeProcessor::finalizeAmplitude
|
||||
- Added amplitude to Seiscomp::Processing::MagnitudeProcessor::computeMagnitude
|
||||
- Added unit to Seiscomp::Processing::MagnitudeProcessor::computeMagnitude
|
||||
- Added Seiscomp::Processing::MagnitudeProcessor::treatAsValidMagnitude()
|
||||
- Added Seiscomp::IO::Exporter::put(std::streambuf* buf, const ObjectList &objects);
|
||||
- Added Seiscomp::Gui::RecordMarker::drawBackground
|
||||
- Made Seiscomp::Client::Application::version public
|
||||
- Changed Seiscomp::Gui::Scheme::colors.map.grid from QColor to QPen
|
||||
- Added Seiscomp::Gui::SpectrogramRenderer::range
|
||||
- Added parameter stretch to Seiscomp::Gui::SpectrogramRenderer::renderAxis
|
||||
- Added overloaded methods to Seiscomp::Gui::Axis::sizeHint and
|
||||
Seiscomp::Gui::Axis::updateLayer that only use QFontMetrics
|
||||
|
||||
"11.1.0" 0x0B0100
|
||||
- Added Seiscomp::DataModel::StrongMotion::Rupture::_strike
|
||||
- Added Seiscomp::Gui::Map::StandardLegend
|
||||
|
||||
"11.0.0" 0x0B0000
|
||||
- Remove dynamic type throw declarations from all methods as this is
|
||||
deprecated in current C++ standard
|
||||
- Added Seiscomp::Gui::Axis::setPen/setGridPen/setSubGridPen
|
||||
- Added Seiscomp::Gui::Map::Layer::canvas method to access the parent canvas
|
||||
- Added Seiscomp::Gui::Map::Canvas::filterMouseReleaseEvent
|
||||
- Added Seiscomp::Gui::Map::Canvas::size
|
||||
- Changed Seiscomp::Gui::Map::Canvas::menu parent parameter type from QWidget to QMenu
|
||||
- Changed Seiscomp::Gui::Map::Layer::menu parent parameter type from QWidget to QMenu
|
||||
- Removed Seiscomp::Gui::Map::Layer RTTI interface
|
||||
- Added Seiscomp::Gui::Map::Layer::show
|
||||
- Added Seiscomp::Gui::Map::Layer::hide
|
||||
- Added Seiscomp::Gui::Map::Layer::baseBufferUpdated
|
||||
- Added Seiscomp::Gui::Map::Layer::size
|
||||
- Added Seiscomp::Gui::Map::Layer::isInside
|
||||
- Added Seiscomp::Gui::Map::Layer::handleEnterEvent
|
||||
- Added Seiscomp::Gui::Map::Layer::handleLeaveEvent
|
||||
- Added Seiscomp::Gui::Map::Layer::filterMouseMoveEvent
|
||||
- Added Seiscomp::Gui::Map::Layer::filterMouseDoubleClickEvent
|
||||
- Added Seiscomp::Gui::Map::Layer::filterMousePressEvent
|
||||
- Added Seiscomp::Gui::Map::Layer::filterMouseReleaseEvent
|
||||
- Added Seiscomp::Gui::Map::Legend::contextResizeEvent
|
||||
- Removed virtual declaration of Seiscomp::Gui::Map::Legend::size
|
||||
- Removed class Seiscomp::Gui::Map::CanvasDelegate
|
||||
- Added class Seiscomp::Gui::EventLayer
|
||||
- Added Seiscomp::Gui::OriginSymbol::setColor
|
||||
- Added Seiscomp::Gui::OriginSymbol::color
|
||||
- Added Seiscomp::Gui::OriginSymbol::setFillColor
|
||||
- Added Seiscomp::Gui::OriginSymbol::fillColor
|
||||
- Added Seiscomp::Gui::MapWidget::setDrawLegends
|
||||
- Added Seiscomp::Gui::RecordView::setMaximumRowHeight
|
||||
- Added Seiscomp::Gui::RecordView::setRelativeRowHeight
|
||||
- Added Seiscomp::Gui::Application::messageGroups
|
||||
- Added Seiscomp::Gui::Application::initLicense
|
||||
- Added Seiscomp::Gui::LUT::operator[]
|
||||
- Added class Seiscomp::Math::Filtering::Min<T>
|
||||
- Added class Seiscomp::Math::Filtering::Max<T>
|
||||
- Added Seiscomp::Gui::RecordWidget::setGridVSpacing
|
||||
- Added Seiscomp::Gui::RecordWidget::setGridVRange
|
||||
- Added Seiscomp::Gui::RecordWidget::setGridVScale
|
||||
- Added Seiscomp::Gui::AbstractLegend
|
||||
- Added Seiscomp::Gui::Plot::addGraph(graph)
|
||||
- Added Seiscomp::Gui::Plot::setLegend
|
||||
- Added Seiscomp::Gui::Plot::isInsidePlot
|
||||
- Added Seiscomp::Gui::Plot::plotRect
|
||||
- Added virtual Seiscomp::Gui::Graph::draw
|
||||
- Added virtual Seiscomp::Gui::Graph::drawSymbol
|
||||
- Added Seiscomp::Gui::Graph::setName/name
|
||||
- Added Seiscomp::Client::Application::reloadBindings
|
||||
- Increased datamodel version to 0.10
|
||||
- Added class Seiscomp::DataModel::ResponseIIR
|
||||
- Inherit class Seiscomp::DataModel::Stream from Seiscomp::DataModel::PublicObject
|
||||
- Added hypocenter and receiver to Seiscomp::Processing::MagnitudeProcessor::computeMagnitude
|
||||
- Added Seiscomp::Processing::MagnitudeProcessor::Status enumeration EpicenterOutOfRegions
|
||||
- Add SC3_LOCATOR_INTERFACE_VERSION define and initialize with version 2
|
||||
- Replace LocatorInterface WeightedPick with PickItem
|
||||
- Refactored Seiscomp::IO::RecordStream interface
|
||||
- Expose PublicObject::registerMe and PublicObject::deregisterMe as public
|
||||
methods
|
||||
|
||||
"10.0.0" 0x0A0000
|
||||
- Added Seiscomp::Core::Time::LocalTimeZone()
|
||||
- Added Seiscomp::IO::GFArchive::getTravelTime(...)
|
||||
- Added Seiscomp::Math::WindowFunc and several implementations
|
||||
- Changed Seiscomp::Util::Bindings::getKeys to const
|
||||
- Added Seiscomp::Gui::Map:Canvas::prependLayer(...)
|
||||
- Added Seiscomp::Gui::Map:Canvas::insertLayerBefore(...)
|
||||
- Fixed bug in Seiscomp::Gui::Map::TextureCache that affected custom
|
||||
Seiscomp::Gui::Map::TileStore implementations
|
||||
- Added Seiscomp::Gui::RecordView::coveredTimeRange()
|
||||
- Added Seiscomp::Core::stringify(...)
|
||||
- Added Seiscomp::Gui::timeToString()
|
||||
- Added Seiscomp::Gui::timeToLabel(...)
|
||||
- Added Seiscomp::Gui::MapWidget::setGrayScale(...)
|
||||
- Added Seiscomp::Gui::Map::Layer::bufferUpdated(...)
|
||||
- Added Seiscomp::Gui::Map::CompositionMode (Source, SourceOver, Multiply)
|
||||
- Changed prototype of Seiscomp::Gui::Map::Canvas::drawImage(..., +CompositionMode)
|
||||
- Changed prototype of Seiscomp::Gui::Map::Projection::drawImage(..., +CompositionMode)
|
||||
- Reworked Seiscomp::Gui::Map::Symbol and add geodetic location and screen
|
||||
position attributes (Symbol API v2)
|
||||
- Add default implementation of Seiscomp::Gui::Map::Symbol::calculateMapPosition
|
||||
|
||||
"9.1.0" 0x090100
|
||||
- Added Seiscomp::Client::Application::Stage enum PLUGINS
|
||||
- Added Seiscomp::Gui::TensorRenderer::renderNP
|
||||
- Fixed parameter const'ness of Seiscomp::Math::Tensor2S
|
||||
|
||||
"9.0.0" 0x090000
|
||||
- Added member creationInfo to class Seiscomp::DataModel::ConfigStation
|
||||
and increased datamodel version to 0.9
|
||||
- Added optional error code to Seiscomp::Communication class methods
|
||||
- Changed internal Seiscomp::Util::Timer API
|
||||
- Added Seiscomp::Util::Timer::setTimeout2
|
||||
- Added Seiscomp::Core::Archive::setStrictMode
|
||||
- Added Seiscomp::Core::Archive::isStrictMode
|
||||
- Added Seiscomp::IO::DatabaseInterface::numberOfAffectedRows
|
||||
- Added optional error code to Seiscomp::Inventory class
|
||||
- Added macro REREGISTER_CLASS which allows to overwrite class registrations
|
||||
- Added method Seiscomp::Gui::Alg::MapTreeNode::parent()
|
||||
- Allow Seiscomp::Gui::Map::TileStore::load to return null images
|
||||
- Increased TILESTORE version to 2
|
||||
|
||||
"8.0.0" 0x080000
|
||||
- Added class Seiscomp::DataModel::ResponseFAP
|
||||
- Changed Seiscomp::IO::GFArchive::addRequest from 1D request signature to
|
||||
3D request signature (distance,depth) -> (source,receiver)
|
||||
- Made Seiscomp::RecordStream::SDSArchive private members and methods
|
||||
protected
|
||||
- Added GUI plotting library
|
||||
|
||||
"7.0.0" 0x070000
|
||||
- Added support for httpmsgbus messaging protocol
|
||||
- Added Seiscomp::IO::HttpSocket
|
||||
- Added Seiscomp::Communication::NetworkInterface::setSequenceNumber
|
||||
- Added Seiscomp::Communication::NetworkInterface::getSequenceNumber
|
||||
- Added Seiscomp::Communication::SystemConnection::setSequenceNumber
|
||||
- Added Seiscomp::Communication::SystemConnection::getSequenceNumber
|
||||
- Modify Seiscomp::IO::Socket don't start timeout stopwatch automatically
|
||||
|
||||
"6.1.0" 0x060100
|
||||
- Added Seiscomp::Gui::RecordWidget::setRecordStepFunction
|
||||
|
||||
"6.0.0" 0x060000
|
||||
- Added virtual method Seiscomp::Record::clipMask()
|
||||
|
||||
"5.1.0" 0x050100
|
||||
- Added Seiscomp::Core::BitSet
|
||||
|
||||
"5.0.1" 0x050001
|
||||
- Renamed seiscomp/math/filtering/rca.h to seiscomp/math/filtering/average.h
|
||||
and made it a "real" average instead of an average of absolute values
|
||||
|
||||
"5.0.0" 0x050000
|
||||
- Removed Seiscomp::Core::RecordSequence::continuousRecord(...)
|
||||
- Removed Seiscomp::Core::RecordSequence::fillGaps
|
||||
- Added template method Seiscomp::Core::RecordSequence::continuousRecord<T>(...)
|
||||
- Added Seiscomp::Processing::Picker::Config::noiseBegin
|
||||
- Added Seiscomp::Gui::Ruler::pixelPerUnit
|
||||
- Added Seiscomp::Gui::Ruler::scale
|
||||
|
||||
"4.0.0" 0x040000
|
||||
- Added Seiscomp::System::ConfigDelegate::aboutToWrite
|
||||
- Added Seiscomp::System::ConfigDelegate::finishedWriting
|
||||
- Added Seiscomp::System::ConfigDelegate::hasWriteError
|
||||
- Added Seiscomp::System::ConfigDelegate::handleWriteTimeMismatch
|
||||
- Added delegate parameter to Seiscomp::System::*::writeConfig
|
||||
- Added Seiscomp::Gui::RecordStreamThread::setRecordHint
|
||||
- Added Seiscomp::Client::StreamApplication::setRecordDatatype
|
||||
- Added Seiscomp::Client::StreamApplication::recordDataType
|
||||
- Added Seiscomp::IO::DatabaseInterface::getRowFieldName virtual abstract
|
||||
method
|
||||
- Fixed Gui::RecordPolyline rendering with large offset
|
||||
- Added Seiscomp::Logging::Output::setUTCEnabled
|
||||
- Added Seiscomp::IO::QuakeLink::Response::disposed field
|
||||
|
||||
"3.1.0" 0x030100
|
||||
- Change private to protected access in Seiscomp::IO::QuakeLink::Connection
|
||||
|
||||
"3.0.0" 0x030000
|
||||
- Added Seiscomp::IO::RecordStream::filterRecord virtual method
|
||||
- Fixed bug in Seiscomp::IO::QuakeLink::Connection
|
||||
- Added Processing::Picker::Result::polarity
|
||||
|
||||
"2.5.0" 0x020500
|
||||
- Added Seiscomp::Client::Application::configGetPath
|
||||
|
||||
"2.4.0" 0x020400
|
||||
- Added Seiscomp::IO::BSONArchive
|
||||
- Added Seiscomp::IO::JSONArchive
|
||||
|
||||
"2.3.0" 0x020300
|
||||
- Added Seiscomp::DataModel::Object::setLastModifiedInArchive
|
||||
- Added Seiscomp::DataModel::Object::lastModifiedInArchive
|
||||
- Populate Seiscomp::DataModel::Object::_lastModifiedInArchive
|
||||
with Seiscomp::DataModel::DatabaseArchive
|
||||
|
||||
"2.2.0" 0x020200
|
||||
- Added optimization flag to Seiscomp::Gui::RecordPolyline::create
|
||||
- Added Seiscomp::Gui::RecordWidget::setRecordOptimization
|
||||
- Added Seiscomp::Gui::RecordWidget::traceInfo
|
||||
- Added Seiscomp::Gui::RecordWidget::areScaledValuesShown
|
||||
- Implement Seiscomp::Gui::Ruler::sizeHint for vertical layout
|
||||
|
||||
"2.1.0" 0x020100
|
||||
- Removed Seiscomp::MultiComponentArray
|
||||
|
||||
"2.0.0" 0x020000
|
||||
- Moved Processing::Parameters to Util::KeyValues
|
||||
- Renamed Processing::Parameters::readFrom to Util::KeyValues::init
|
||||
- Added Util::Bindings class
|
||||
|
||||
"1.16.0" 0x011000
|
||||
- Added Seiscomp::IO::Spectralizer
|
||||
- Added Seiscomp::Gui::LUT
|
||||
- Added Seiscomp::Gui::StaticLUT
|
||||
- Added Seiscomp::Gui::StaticColorLUT
|
||||
- Added Seiscomp::Gui::SpectrogramRenderer
|
||||
- Added Seiscomp::Gui::SpectrogramWidget
|
||||
|
||||
"1.15.0" 0x010F00
|
||||
- Added Seiscomp::Math::Geo::delazi_wgs84
|
||||
|
||||
"1.14.0" 0x010E00
|
||||
- Changed return type of Seiscomp::DataModel::getThreeComponents to bool
|
||||
|
||||
"1.13.0" 0x010D00
|
||||
- Changed Seiscomp::DataModel::DiffMerge::compareNonArrayProperty signature
|
||||
from Object* to BaseObject *
|
||||
- Added method Seiscomp::DataModel::DatabaseArchive::parentPublicID(...)
|
||||
|
||||
"1.12.0" 0x010C00
|
||||
- Set Seiscomp::Seismology::LocatorInterface::locate(...) initTime to const
|
||||
|
||||
"1.11.0" 0x010B00
|
||||
- Added const Record * as first parameter to
|
||||
Seiscomp::Processing::NCompsOperator<...>::Proc::operator()
|
||||
|
||||
"1.10.0" 0x010A00
|
||||
- Derive Seiscomp::IO::QuakeLink::Connection from BaseObject
|
||||
|
||||
"1.9.0" 0x010900
|
||||
- Renamed Seiscomp::Client::Application::version to
|
||||
Seiscomp::Client::Application::frameworkVersion
|
||||
- Added Seiscomp::Client::Application::version virtual method
|
||||
- Added Seiscomp::Client::Application::reloadInventory method
|
||||
|
||||
"1.8.0" 0x010800
|
||||
- Added Seiscomp::Client::Application::reloadInventory method
|
||||
|
||||
"1.7.0" 0x010700
|
||||
- Added Seiscomp::Processing::Picker::filterID method
|
||||
- Added Seiscomp::Processing::SecondaryPicker::filterID method
|
||||
|
||||
"1.6.0" 0x010600
|
||||
- Added Seiscomp::IO::QuakeLink keep alive option
|
||||
|
||||
"1.5.0" 0x010500
|
||||
- Added Seiscomp::Core::TimeSpan::MinTime and
|
||||
Seiscomp::Core::TimeSpan::MaxTime
|
||||
|
||||
"1.4.0" 0x010400
|
||||
- Added clone method to Seiscomp::IO::RecordFilterInterface
|
||||
- Added Seiscomp::IO::RecordDemuxFilter
|
||||
|
||||
"1.3.1" 0x010301
|
||||
- Fixed severe bug in Seiscomp::RecordStream::Decimation
|
||||
|
||||
"1.3.0" 0x010300
|
||||
- Added Seiscomp::IO::RecordFilterInterface
|
||||
Added Seiscomp::IO::RecordIIRFilter
|
||||
- Added Seiscomp::IO::RecordResampler
|
||||
|
||||
"1.2.0" 0x010200
|
||||
- Added Diff2 class to Seiscomp::DataModel
|
||||
- Added canPush, canPop methods to ThreadedQueue
|
||||
- Added acquititionError signal to RecordStreamThread
|
||||
|
||||
"1.1.0" 0x010100
|
||||
- Added function DataModel::PublicObjectCache::cached()
|
||||
- Added function Gui::ImageTree::hasPendingRequests()
|
||||
- Added function Gui::Canvas::reload()
|
||||
- Added function Gui::Canvas::renderingComplete()
|
||||
- Added signal Gui::Canvas::renderingCompleted()
|
||||
- Added function Gui::TextureCache::invalidateTexture(...)
|
||||
*/
|
||||
|
||||
|
||||
template <std::uint16_t major, std::uint8_t minor, std::uint8_t patch>
|
||||
class VersionPacker {
|
||||
public:
|
||||
enum { Value = major << 0x10 | minor << 0x08 | patch };
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Version {
|
||||
// ----------------------------------------------------------------------
|
||||
// Traits
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
typedef uint32_t PackType;
|
||||
typedef uint16_t MajorType;
|
||||
typedef uint8_t MinorType;
|
||||
typedef uint8_t PatchType;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Version(PackType packed_version = 0) : packed(packed_version) {}
|
||||
Version(MajorType major, MinorType minor, PatchType patch = 0) {
|
||||
packed = pack(major, minor, patch);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
MajorType majorTag() const { return packed >> 0x10; }
|
||||
MinorType minorTag() const { return (packed >> 0x08) & 0xff; }
|
||||
PatchType patchTag() const { return packed & 0xff; }
|
||||
|
||||
PackType majorMinor() const { return packed & ~0xff; }
|
||||
|
||||
std::string toString() const;
|
||||
bool fromString(const std::string &str);
|
||||
|
||||
static PackType pack(MajorType major, MinorType minor, PatchType patch = 0) {
|
||||
return (major << 0x10) | (minor << 0x08) | patch;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Operators
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
// Operators
|
||||
bool operator==(const Version &other) const { return packed == other.packed; }
|
||||
bool operator!=(const Version &other) const { return packed != other.packed; }
|
||||
bool operator<(const Version &other) const { return packed < other.packed; }
|
||||
bool operator>(const Version &other) const { return packed > other.packed; }
|
||||
bool operator<=(const Version &other) const { return packed <= other.packed; }
|
||||
bool operator>=(const Version &other) const { return packed >= other.packed; }
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public members
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
PackType packed;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API FrameworkVersion {
|
||||
public:
|
||||
FrameworkVersion();
|
||||
|
||||
//! Returns the version string
|
||||
std::string toString() const;
|
||||
|
||||
//! Returns additional system build information
|
||||
std::string systemInfo() const;
|
||||
|
||||
const Version &version() const;
|
||||
const Version &api() const;
|
||||
|
||||
|
||||
private:
|
||||
Version _version;
|
||||
Version _api;
|
||||
std::string _release;
|
||||
};
|
||||
|
||||
extern FrameworkVersion CurrentVersion;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user