[seiscomp, scanloc] Install, add .gitignore
This commit is contained in:
219
include/seiscomp/broker/client.h
Normal file
219
include/seiscomp/broker/client.h
Normal file
@@ -0,0 +1,219 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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 GEMPA_BROKER_CLIENT_H__
|
||||
#define GEMPA_BROKER_CLIENT_H__
|
||||
|
||||
|
||||
#include <seiscomp/wired/devices/socket.h>
|
||||
#include <string>
|
||||
|
||||
#include <seiscomp/broker/message.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Messaging {
|
||||
namespace Broker {
|
||||
|
||||
|
||||
class Message;
|
||||
class Group;
|
||||
class Queue;
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Client interface describes a client connected to a queue acting
|
||||
* as message subscriber.
|
||||
*
|
||||
* The only thing that a client does is to store a name which is being assigned
|
||||
* by the queue and publish messages. The publish method is abstract and needs
|
||||
* to be implemented by derived classes such as communication protocols.
|
||||
*/
|
||||
class SC_BROKER_API Client {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types and enumerations
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
enum Constants {
|
||||
MaxLocalHeapSize = 128
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Client();
|
||||
|
||||
//! D'tor
|
||||
virtual ~Client();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
const std::string &name() const { return _name; }
|
||||
|
||||
/**
|
||||
* @brief Returns the absolute memory pointer of an local heap
|
||||
* offset
|
||||
* @param offset The offset in bytes
|
||||
* @return The pointer of the memory block
|
||||
*/
|
||||
void *memory(int offset);
|
||||
const void *memory(int offset) const;
|
||||
|
||||
/**
|
||||
* @return The time in UTC when the client has connected.
|
||||
*/
|
||||
const Core::Time &created() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Subscriber interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool setMembershipInformationEnabled(bool enable);
|
||||
bool wantsMembershipInformation() const;
|
||||
|
||||
/**
|
||||
* @brief Sets whether to discard messages where receiver equals
|
||||
* the sender or not.
|
||||
* @param enable The enable flag
|
||||
* @return Success flag
|
||||
*/
|
||||
bool setDiscardSelf(bool enable);
|
||||
bool discardSelf() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the number of messages required to send back an
|
||||
* acknoledgement.
|
||||
* @param numberOfMessages The window size
|
||||
*/
|
||||
void setAcknowledgeWindow(SequenceNumber numberOfMessages);
|
||||
|
||||
/**
|
||||
* @brief Returns the IP address connected to the client socket.
|
||||
* If the underlying transport does not implement IP socket
|
||||
* communication, it can return 0.
|
||||
* @return The IP address
|
||||
*/
|
||||
virtual Wired::Socket::IPAddress IPAddress() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Publishes a message
|
||||
*
|
||||
* This method has to be implemented by all subclasses to encode it
|
||||
* into their transport format and to send it.
|
||||
*
|
||||
* @param sender The sender of the message
|
||||
* @param msg The message
|
||||
* @return Number of bytes sent
|
||||
*/
|
||||
virtual size_t publish(Client *sender, Message *msg) = 0;
|
||||
|
||||
/**
|
||||
* @brief Notifies a client that a new member entered a group the client
|
||||
* is also member in.
|
||||
* @param group The group the new member entered.
|
||||
* @param newMember The client pointer to the new member.
|
||||
* @param msg The message to be sent.
|
||||
*/
|
||||
virtual void enter(const Group *group, const Client *newMember, Message *msg) = 0;
|
||||
|
||||
/**
|
||||
* @brief Notifies a client that a member left a group the client
|
||||
* is also member in.
|
||||
* @param group The group the member left.
|
||||
* @param oldMember The client pointer to the member.
|
||||
* @param msg The message to be sent.
|
||||
*/
|
||||
virtual void leave(const Group *group, const Client *oldMember, Message *msg) = 0;
|
||||
|
||||
virtual void disconnected(const Client *disconnectedClient, Message *msg) = 0;
|
||||
|
||||
//! Send acknowledgment to sender
|
||||
virtual void ack() = 0;
|
||||
|
||||
//! Remove the clients resources
|
||||
virtual void dispose() = 0;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected members
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
Queue *_queue{nullptr};
|
||||
Core::Time _created;
|
||||
Core::Time _lastSOHReceived;
|
||||
std::string _name;
|
||||
bool _wantsMembershipInformation{false};
|
||||
bool _discardSelf{false};
|
||||
SequenceNumber _sequenceNumber{0};
|
||||
SequenceNumber _acknowledgeWindow{20};
|
||||
SequenceNumber _acknowledgeCounter{20};
|
||||
Core::Time _ackInitiated;
|
||||
int _inactivityCounter{0}; // The number of seconds
|
||||
// of inactivity
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
// Local client heap to additional user data stored by e.g. plugins
|
||||
char _heap[MaxLocalHeapSize];
|
||||
|
||||
friend class Queue;
|
||||
};
|
||||
|
||||
|
||||
inline bool Client::wantsMembershipInformation() const {
|
||||
return _wantsMembershipInformation;
|
||||
}
|
||||
|
||||
inline bool Client::discardSelf() const {
|
||||
return _discardSelf;
|
||||
}
|
||||
|
||||
inline void *Client::memory(int offset) {
|
||||
return _heap + offset;
|
||||
}
|
||||
|
||||
inline const void *Client::memory(int offset) const {
|
||||
return _heap + offset;
|
||||
}
|
||||
|
||||
inline const Core::Time &Client::created() const {
|
||||
return _created;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
137
include/seiscomp/broker/group.h
Normal file
137
include/seiscomp/broker/group.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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 GEMPA_BROKER_GROUP_H__
|
||||
#define GEMPA_BROKER_GROUP_H__
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <string>
|
||||
|
||||
#include <seiscomp/broker/hashset.h>
|
||||
#include <seiscomp/broker/statistics.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Messaging {
|
||||
namespace Broker {
|
||||
|
||||
|
||||
class Client;
|
||||
class Queue;
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Group);
|
||||
|
||||
/**
|
||||
* @brief The Group class implements a particular group (or channel/topic) of
|
||||
* a queue.
|
||||
*
|
||||
* Each group can have members. A member is a client. This class is nothing
|
||||
* else than a manager of members in an efficient way. It implements a very
|
||||
* fast hashset (KHash) of its members which makes member tests very fast and
|
||||
* does not make it necessary to manage additional complicated lookup
|
||||
* structures.
|
||||
*/
|
||||
class SC_BROKER_API Group : public Core::BaseObject {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
typedef KHashSet<Client*> Members;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
explicit Group(const char *name);
|
||||
|
||||
//! D'tor
|
||||
~Group();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the name of the group.
|
||||
const std::string &name() const;
|
||||
|
||||
//! Returns the number of members.
|
||||
size_t memberCount() const;
|
||||
|
||||
/**
|
||||
* @brief Adds a member to the group if it is not yet.
|
||||
* @param client The pointer identifying a unique client
|
||||
* @return true on success, false otherwise e.g. duplicates
|
||||
*/
|
||||
bool addMember(Client *client);
|
||||
|
||||
/**
|
||||
* @brief Removes a member from the group.
|
||||
* @param client The pointer identifying a unique client
|
||||
* @return true on success, false otherwise e.g. does not exist
|
||||
*/
|
||||
bool removeMember(Client *client);
|
||||
|
||||
//! Returns if a client is a member of not.
|
||||
bool hasMember(const Client *client) const;
|
||||
|
||||
//! Removes all members.
|
||||
void clearMembers() { _members.clear(); }
|
||||
|
||||
const Members &members() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
std::string _name;
|
||||
Members _members;
|
||||
mutable Tx _txMessages;
|
||||
mutable Tx _txBytes;
|
||||
mutable Tx _txPayload;
|
||||
|
||||
|
||||
friend class Queue;
|
||||
};
|
||||
|
||||
|
||||
inline const std::string &Group::name() const {
|
||||
return _name;
|
||||
}
|
||||
|
||||
inline const Group::Members &Group::members() const {
|
||||
return _members;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
666
include/seiscomp/broker/hashset.h
Normal file
666
include/seiscomp/broker/hashset.h
Normal file
@@ -0,0 +1,666 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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 GEMPA_BROKER_HASHSET_H
|
||||
#define GEMPA_BROKER_HASHSET_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
|
||||
#include <seiscomp/broker/api.h>
|
||||
#include <seiscomp/broker/utils/khash.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
|
||||
KHASH_SET_INIT_INT(int)
|
||||
KHASH_SET_INIT_INT64(int64)
|
||||
KHASH_SET_INIT_STR(str)
|
||||
KHASH_MAP_INIT_STR(m_str, void*)
|
||||
|
||||
|
||||
template <typename T>
|
||||
class KHashSet {};
|
||||
|
||||
template <typename K, typename V>
|
||||
class KHashMap {};
|
||||
|
||||
|
||||
template <>
|
||||
class KHashSet<uint32_t> {
|
||||
public:
|
||||
struct iterator {
|
||||
iterator() {}
|
||||
iterator(const iterator &other) : h(other.h), k(other.k) {}
|
||||
iterator(khash_t(int) *h_, unsigned k_) : h(h_), k(k_) {}
|
||||
|
||||
bool operator==(const iterator &other) const {
|
||||
return k == other.k;
|
||||
}
|
||||
|
||||
bool operator!=(const iterator &other) const {
|
||||
return k != other.k;
|
||||
}
|
||||
|
||||
// Prefix
|
||||
iterator &operator++() {
|
||||
++k;
|
||||
while ( k != kh_end(h) && !kh_exist(h, k) )
|
||||
++k;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Postfix
|
||||
iterator operator++(int) {
|
||||
iterator tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
uint32_t operator*() const {
|
||||
return kh_key(h, k);
|
||||
}
|
||||
|
||||
khash_t(int) *h;
|
||||
unsigned k;
|
||||
};
|
||||
|
||||
|
||||
KHashSet() {
|
||||
_h = kh_init(int);
|
||||
}
|
||||
|
||||
~KHashSet() {
|
||||
kh_destroy(int, _h);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
iterator begin() const {
|
||||
unsigned k = kh_begin(_h);
|
||||
while ( k != kh_end(_h) && !kh_exist(_h, k) )
|
||||
++k;
|
||||
return iterator(_h, k);
|
||||
}
|
||||
|
||||
iterator end() const {
|
||||
return iterator(_h, kh_end(_h));
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return kh_size(_h);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
kh_clear(int, _h);
|
||||
}
|
||||
|
||||
int insert(uint32_t v) {
|
||||
int ret;
|
||||
kh_put(int, _h, v, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
iterator find(uint32_t v) const {
|
||||
return iterator(_h, kh_get(int, _h, v));
|
||||
}
|
||||
|
||||
void erase(iterator it) {
|
||||
kh_del(int, _h, it.k);
|
||||
}
|
||||
|
||||
bool contains(uint32_t v) const {
|
||||
return find(v) != end();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
khash_t(int) *_h;
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
class KHashSet<uint64_t> {
|
||||
public:
|
||||
struct iterator {
|
||||
iterator() {}
|
||||
iterator(const iterator &other) : h(other.h), k(other.k) {}
|
||||
iterator(khash_t(int64) *h_, unsigned k_) : h(h_), k(k_) {}
|
||||
|
||||
bool operator==(const iterator &other) const {
|
||||
return k == other.k;
|
||||
}
|
||||
|
||||
bool operator!=(const iterator &other) const {
|
||||
return k != other.k;
|
||||
}
|
||||
|
||||
// Prefix
|
||||
iterator &operator++() {
|
||||
++k;
|
||||
while ( k != kh_end(h) && !kh_exist(h, k) )
|
||||
++k;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Postfix
|
||||
iterator operator++(int) {
|
||||
iterator tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
uint64_t operator*() const {
|
||||
return kh_key(h, k);
|
||||
}
|
||||
|
||||
khash_t(int64) *h;
|
||||
unsigned k;
|
||||
};
|
||||
|
||||
|
||||
KHashSet() {
|
||||
_h = kh_init(int64);
|
||||
}
|
||||
|
||||
~KHashSet() {
|
||||
kh_destroy(int64, _h);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
iterator begin() const {
|
||||
unsigned k = kh_begin(_h);
|
||||
while ( k != kh_end(_h) && !kh_exist(_h, k) )
|
||||
++k;
|
||||
return iterator(_h, k);
|
||||
}
|
||||
|
||||
iterator end() const {
|
||||
return iterator(_h, kh_end(_h));
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return kh_size(_h);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
kh_clear(int64, _h);
|
||||
}
|
||||
|
||||
int insert(uint64_t v) {
|
||||
int ret;
|
||||
kh_put(int64, _h, v, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
iterator find(uint64_t v) const {
|
||||
return iterator(_h, kh_get(int64, _h, v));
|
||||
}
|
||||
|
||||
void erase(iterator it) {
|
||||
kh_del(int64, _h, it.k);
|
||||
}
|
||||
|
||||
bool contains(uint64_t v) const {
|
||||
return find(v) != end();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
khash_t(int64) *_h;
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
class KHashSet<const char*> {
|
||||
public:
|
||||
struct iterator {
|
||||
iterator() {}
|
||||
iterator(const iterator &other) : h(other.h), k(other.k) {}
|
||||
iterator(khash_t(str) *h_, unsigned k_) : h(h_), k(k_) {}
|
||||
|
||||
bool operator==(const iterator &other) const {
|
||||
return k == other.k;
|
||||
}
|
||||
|
||||
bool operator!=(const iterator &other) const {
|
||||
return k != other.k;
|
||||
}
|
||||
|
||||
// Prefix
|
||||
iterator &operator++() {
|
||||
++k;
|
||||
while ( k != kh_end(h) && !kh_exist(h, k) )
|
||||
++k;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Postfix
|
||||
iterator operator++(int) {
|
||||
iterator tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
const char *operator*() const {
|
||||
return kh_key(h, k);
|
||||
}
|
||||
|
||||
khash_t(str) *h;
|
||||
unsigned k;
|
||||
};
|
||||
|
||||
|
||||
KHashSet() {
|
||||
_h = kh_init(str);
|
||||
}
|
||||
|
||||
~KHashSet() {
|
||||
kh_destroy(str, _h);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
iterator begin() const {
|
||||
unsigned k = kh_begin(_h);
|
||||
while ( k != kh_end(_h) && !kh_exist(_h, k) )
|
||||
++k;
|
||||
return iterator(_h, k);
|
||||
}
|
||||
|
||||
iterator end() const {
|
||||
return iterator(_h, kh_end(_h));
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return kh_size(_h);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
kh_clear(str, _h);
|
||||
}
|
||||
|
||||
int insert(const char *v) {
|
||||
int ret;
|
||||
kh_put(str, _h, v, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
iterator find(const char *str) const {
|
||||
return iterator(_h, kh_get(str, _h, str));
|
||||
}
|
||||
|
||||
iterator find(const std::string &str) const {
|
||||
return iterator(_h, kh_get(str, _h, str.c_str()));
|
||||
}
|
||||
|
||||
void erase(iterator it) {
|
||||
kh_del(str, _h, it.k);
|
||||
}
|
||||
|
||||
bool contains(const char *str) const {
|
||||
return find(str) != end();
|
||||
}
|
||||
|
||||
bool contains(const std::string &str) const {
|
||||
return find(str) != end();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
khash_t(str) *_h;
|
||||
};
|
||||
|
||||
|
||||
template <typename V>
|
||||
class KHashMap<const char*, V*> {
|
||||
public:
|
||||
struct iterator {
|
||||
iterator() {}
|
||||
iterator(const iterator &other) : h(other.h), k(other.k) {}
|
||||
iterator(khash_t(m_str) *h_, unsigned k_) : h(h_), k(k_) {}
|
||||
|
||||
bool operator==(const iterator &other) const {
|
||||
return k == other.k;
|
||||
}
|
||||
|
||||
bool operator!=(const iterator &other) const {
|
||||
return k != other.k;
|
||||
}
|
||||
|
||||
// Prefix
|
||||
iterator &operator++() {
|
||||
++k;
|
||||
while ( k != kh_end(h) && !kh_exist(h, k) )
|
||||
++k;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Postfix
|
||||
iterator operator++(int) {
|
||||
iterator tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
const char *operator*() const {
|
||||
return kh_key(h, k);
|
||||
}
|
||||
|
||||
const char *key() const {
|
||||
return kh_key(h, k);
|
||||
}
|
||||
|
||||
V *value() const {
|
||||
return (V*)kh_value(h, k);
|
||||
}
|
||||
|
||||
khash_t(m_str) *h;
|
||||
unsigned k;
|
||||
};
|
||||
|
||||
|
||||
KHashMap() {
|
||||
_h = kh_init(m_str);
|
||||
}
|
||||
|
||||
~KHashMap() {
|
||||
kh_destroy(m_str, _h);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
iterator begin() const {
|
||||
unsigned k = kh_begin(_h);
|
||||
while ( k != kh_end(_h) && !kh_exist(_h, k) )
|
||||
++k;
|
||||
return iterator(_h, k);
|
||||
}
|
||||
|
||||
iterator end() const {
|
||||
return iterator(_h, kh_end(_h));
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return kh_size(_h);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
kh_clear(m_str, _h);
|
||||
}
|
||||
|
||||
int insert(const char *v, V *value) {
|
||||
int ret;
|
||||
khiter_t k = kh_put(m_str, _h, v, &ret);
|
||||
if ( k >= 0 )
|
||||
kh_value(_h, k) = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
iterator find(const char *str) const {
|
||||
return iterator(_h, kh_get(m_str, _h, str));
|
||||
}
|
||||
|
||||
iterator find(const std::string &str) const {
|
||||
return iterator(_h, kh_get(m_str, _h, str.c_str()));
|
||||
}
|
||||
|
||||
void erase(iterator it) {
|
||||
kh_del(m_str, _h, it.k);
|
||||
}
|
||||
|
||||
bool contains(const char *str) const {
|
||||
return find(str) != end();
|
||||
}
|
||||
|
||||
bool contains(const std::string &str) const {
|
||||
return find(str) != end();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
khash_t(m_str) *_h;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename T, int BYTES>
|
||||
class KHashSetPtrBase {};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class KHashSetPtrBase<T, 4> {
|
||||
public:
|
||||
struct iterator {
|
||||
iterator() {}
|
||||
iterator(const iterator &other) : h(other.h), k(other.k) {}
|
||||
iterator(khash_t(int) *h_, unsigned k_) : h(h_), k(k_) {}
|
||||
|
||||
bool operator==(const iterator &other) const {
|
||||
return k == other.k;
|
||||
}
|
||||
|
||||
bool operator!=(const iterator &other) const {
|
||||
return k != other.k;
|
||||
}
|
||||
|
||||
// Prefix
|
||||
iterator &operator++() {
|
||||
++k;
|
||||
while ( k != kh_end(h) && !kh_exist(h, k) )
|
||||
++k;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Postfix
|
||||
iterator operator++(int) {
|
||||
iterator tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
T operator*() const {
|
||||
return (T)kh_key(h, k);
|
||||
}
|
||||
|
||||
khash_t(int) *h;
|
||||
unsigned k;
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
KHashSetPtrBase() {
|
||||
_h = kh_init(int);
|
||||
}
|
||||
|
||||
~KHashSetPtrBase() {
|
||||
kh_destroy(int, _h);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
iterator begin() const {
|
||||
unsigned k = kh_begin(_h);
|
||||
while ( k != kh_end(_h) && !kh_exist(_h, k) )
|
||||
++k;
|
||||
return iterator(_h, k);
|
||||
}
|
||||
|
||||
iterator end() const {
|
||||
return iterator(_h, kh_end(_h));
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return kh_size(_h);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
kh_clear(int, _h);
|
||||
}
|
||||
|
||||
int insert(T v) {
|
||||
int ret;
|
||||
kh_put(int, _h, (uintptr_t)v, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
iterator find(const void *v) const {
|
||||
return iterator(_h, kh_get(int, _h, (uintptr_t)v));
|
||||
}
|
||||
|
||||
void erase(iterator it) {
|
||||
kh_del(int, _h, it.k);
|
||||
}
|
||||
|
||||
bool contains(const void *v) const {
|
||||
return kh_get(int, _h, (uintptr_t)v) != kh_end(_h);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
khash_t(int) *_h;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class KHashSetPtrBase<T, 8> {
|
||||
public:
|
||||
struct iterator {
|
||||
iterator() {}
|
||||
iterator(const iterator &other) : h(other.h), k(other.k) {}
|
||||
iterator(khash_t(int64) *h_, unsigned k_) : h(h_), k(k_) {}
|
||||
|
||||
bool operator==(const iterator &other) const {
|
||||
return k == other.k;
|
||||
}
|
||||
|
||||
bool operator!=(const iterator &other) const {
|
||||
return k != other.k;
|
||||
}
|
||||
|
||||
// Prefix
|
||||
iterator &operator++() {
|
||||
++k;
|
||||
while ( k != kh_end(h) && !kh_exist(h, k) )
|
||||
++k;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Postfix
|
||||
iterator operator++(int) {
|
||||
iterator tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
T operator*() const {
|
||||
return (T)kh_key(h, k);
|
||||
}
|
||||
|
||||
khash_t(int64) *h;
|
||||
unsigned k;
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
KHashSetPtrBase() {
|
||||
_h = kh_init(int64);
|
||||
}
|
||||
|
||||
~KHashSetPtrBase() {
|
||||
kh_destroy(int64, _h);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
iterator begin() const {
|
||||
unsigned k = kh_begin(_h);
|
||||
while ( k != kh_end(_h) && !kh_exist(_h, k) )
|
||||
++k;
|
||||
return iterator(_h, k);
|
||||
}
|
||||
|
||||
iterator end() const {
|
||||
return iterator(_h, kh_end(_h));
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return kh_size(_h);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
kh_clear(int64, _h);
|
||||
}
|
||||
|
||||
int insert(T v) {
|
||||
int ret;
|
||||
kh_put(int64, _h, (uintptr_t)v, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
iterator find(const void *v) const {
|
||||
return iterator(_h, kh_get(int64, _h, (uintptr_t)v));
|
||||
}
|
||||
|
||||
void erase(iterator it) {
|
||||
kh_del(int64, _h, it.k);
|
||||
}
|
||||
|
||||
bool contains(const void *v) const {
|
||||
return kh_get(int64, _h, (uintptr_t)v) != kh_end(_h);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
khash_t(int64) *_h;
|
||||
};
|
||||
|
||||
|
||||
struct Arch {
|
||||
enum {
|
||||
PtrSize = sizeof(intptr_t)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class KHashSet<T*> : public KHashSetPtrBase<T*, Arch::PtrSize> {
|
||||
public:
|
||||
KHashSet() {}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
164
include/seiscomp/broker/message.h
Normal file
164
include/seiscomp/broker/message.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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 GEMPA_BROKER_MESSAGE_H__
|
||||
#define GEMPA_BROKER_MESSAGE_H__
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <seiscomp/core/enumeration.h>
|
||||
#include <seiscomp/wired/buffer.h>
|
||||
|
||||
#include <seiscomp/broker/api.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Messaging {
|
||||
namespace Broker {
|
||||
|
||||
|
||||
class Group;
|
||||
|
||||
|
||||
typedef uint64_t SequenceNumber;
|
||||
#define INVALID_SEQUENCE_NUMBER Seiscomp::Messaging::Broker::SequenceNumber(-1)
|
||||
|
||||
|
||||
MAKEENUM(
|
||||
ContentEncoding,
|
||||
EVALUES(
|
||||
Identity,
|
||||
Deflate,
|
||||
GZip,
|
||||
LZ4
|
||||
),
|
||||
ENAMES(
|
||||
"identity",
|
||||
"deflate",
|
||||
"gzip",
|
||||
"lz4"
|
||||
)
|
||||
);
|
||||
|
||||
MAKEENUM(
|
||||
MimeType,
|
||||
EVALUES(
|
||||
Binary,
|
||||
JSON,
|
||||
BSON,
|
||||
XML,
|
||||
IMPORTED_XML,
|
||||
Text
|
||||
),
|
||||
ENAMES(
|
||||
"application/x-sc-bin",
|
||||
"text/json",
|
||||
"application/x-sc-bson",
|
||||
"application/x-sc-xml",
|
||||
"text/xml",
|
||||
"text/plain"
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Message);
|
||||
/**
|
||||
* @brief The Message class implements the message structure.
|
||||
*
|
||||
* A message contains meta data and a payload. Since each protocol has to
|
||||
* encode the message differently a cached version for each protocol is also
|
||||
* stored. That buffer can be sent without further modifications. This is
|
||||
* in particular helpful if a message is going to be sent to hundreds of
|
||||
* clients connected through the same protocol. The message has to be encoded
|
||||
* only once and not hundred times. This cache is lazy and will only be
|
||||
* populated at the first send operation.
|
||||
*/
|
||||
class SC_BROKER_API Message : public Seiscomp::Core::BaseObject {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Message();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief Decodes a message if object is NULL according to the payload
|
||||
* and format
|
||||
* @return true if msg->object is a valid pointer or false otherwise.
|
||||
*/
|
||||
bool decode();
|
||||
|
||||
/**
|
||||
* @brief Encodes a message if object is not NULL and saves the
|
||||
* encoded buffer in payload.
|
||||
* @return true if payload is not empty, false otherwise.
|
||||
*/
|
||||
bool encode();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Members
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
enum struct Type {
|
||||
Unspecified,
|
||||
Regular,
|
||||
Transient, // From this enumeration messages are not processed
|
||||
Status
|
||||
};
|
||||
|
||||
std::string sender; //!< The sender
|
||||
std::string target; //!< The target group/topic
|
||||
std::string encoding; //!< The encoding of the data
|
||||
std::string mimeType; //!< The mime type of the data
|
||||
std::string payload; //!< The payload bytes
|
||||
Core::BaseObjectPtr object; //!< The decoded object
|
||||
Core::Version schemaVersion; //!< The schema version of the payload after decoding
|
||||
Seiscomp::Core::Time timestamp; //!< The received time
|
||||
Type type; //!< The message type
|
||||
bool selfDiscard; //!< Whether self discard should be checked or not
|
||||
bool processed;
|
||||
/** The assigned sequence number */
|
||||
SequenceNumber sequenceNumber;
|
||||
|
||||
/** Cached encoded version for different protocols */
|
||||
Wired::BufferPtr encodingWebSocket;
|
||||
|
||||
/** Cache of the target group */
|
||||
Group *_internalGroupPtr;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
94
include/seiscomp/broker/messagedispatcher.h
Normal file
94
include/seiscomp/broker/messagedispatcher.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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 GEMPA_BROKER_MESSAGEDISPATCHER_H__
|
||||
#define GEMPA_BROKER_MESSAGEDISPATCHER_H__
|
||||
|
||||
|
||||
#include <seiscomp/broker/api.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Messaging {
|
||||
namespace Broker {
|
||||
|
||||
|
||||
class Client;
|
||||
class Message;
|
||||
class Queue;
|
||||
|
||||
|
||||
/**
|
||||
* @brief The MessageDispatcher class is used to forward processed messages
|
||||
* from another thread.
|
||||
*
|
||||
* Since it is not safe to call publish on all registered subscribers, the
|
||||
* dispatcher class is provide safe handling within a given framework.
|
||||
*/
|
||||
class SC_BROKER_API MessageDispatcher {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
MessageDispatcher() {}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Dispatcher interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief Sends a message thread-safe.
|
||||
* @param sender The sender of the message
|
||||
* @param message The message itself which must not be managed
|
||||
* by the caller.
|
||||
*/
|
||||
virtual void sendMessage(Client *sender, Message *message) = 0;
|
||||
|
||||
/**
|
||||
* @brief Notifies the dispatcher about a new message. If the message
|
||||
* should be published, dispatch() must be called.
|
||||
* @param queue The queue that got a new message to be dispatched
|
||||
*/
|
||||
virtual void messageAvailable(Queue *queue) = 0;
|
||||
|
||||
/**
|
||||
* @brief Dispatches a message from the process-ready-queue.
|
||||
*
|
||||
* This call may block if not issued after the messageAvailable()
|
||||
* signal.
|
||||
* @param queue The target queue
|
||||
*/
|
||||
void flushMessages(Queue *queue) {
|
||||
queue->flushProcessedMessages();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
145
include/seiscomp/broker/messageprocessor.h
Normal file
145
include/seiscomp/broker/messageprocessor.h
Normal file
@@ -0,0 +1,145 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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 GEMPA_BROKER_MESSAGEPROCESSOR_H__
|
||||
#define GEMPA_BROKER_MESSAGEPROCESSOR_H__
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core/interfacefactory.h>
|
||||
#include <seiscomp/config/config.h>
|
||||
|
||||
#include <seiscomp/broker/processor.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Messaging {
|
||||
namespace Broker {
|
||||
|
||||
|
||||
class Client;
|
||||
class Message;
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(MessageProcessor);
|
||||
|
||||
/**
|
||||
* @brief The MessageProcessor class is used inside the broker to process
|
||||
* messages in any way. The most important use case for such a
|
||||
* processor is to store the message in the database if it suffices a
|
||||
* certain format. Once could think of other use cases such as
|
||||
* building statistics.
|
||||
*/
|
||||
class SC_BROKER_API MessageProcessor : public Processor {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
enum Constants {
|
||||
MaxAdditionalParams = 100
|
||||
};
|
||||
|
||||
enum Mode {
|
||||
None = 0x00,
|
||||
Messages = 0x01,
|
||||
Connections = 0x02
|
||||
};
|
||||
|
||||
using KeyValueCStrPair = std::pair<const char*,const char*>;
|
||||
using KeyCStrValues = KeyValueCStrPair *;
|
||||
|
||||
using KeyValuePair = std::pair<std::string,std::string>;
|
||||
using KeyValues = std::vector<KeyValuePair>;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
MessageProcessor();
|
||||
virtual ~MessageProcessor();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public virtual interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
virtual bool acceptConnection(Client *client,
|
||||
const KeyCStrValues inParams, int inParamCount,
|
||||
KeyValues &outParams) = 0;
|
||||
|
||||
virtual void dropConnection(Client *client) = 0;
|
||||
|
||||
virtual bool process(Message *msg) = 0;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
int mode() const { return _mode; }
|
||||
|
||||
/**
|
||||
* @brief Returns whether the processor want to process messages.
|
||||
* @return Flag
|
||||
*/
|
||||
bool isMessageProcessingEnabled() const { return _mode & Messages; }
|
||||
|
||||
/**
|
||||
* @brief Returns whether the processor want to process connections..
|
||||
* @return Flag
|
||||
*/
|
||||
bool isConnectionProcessingEnabled() const { return _mode & Connections; }
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected methods
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
void setMode(int mode);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
int _mode;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_INTERFACE_FACTORY(MessageProcessor);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define REGISTER_BROKER_MESSAGE_PROCESSOR(Class, Service) \
|
||||
Seiscomp::Core::Generic::InterfaceFactory<Seiscomp::Messaging::Broker::MessageProcessor, Class> __##Class##InterfaceFactory__(Service)
|
||||
|
||||
|
||||
#endif
|
||||
103
include/seiscomp/broker/processor.h
Normal file
103
include/seiscomp/broker/processor.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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 GEMPA_BROKER_PROCESSOR_H__
|
||||
#define GEMPA_BROKER_PROCESSOR_H__
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/config/config.h>
|
||||
|
||||
#include <seiscomp/broker/api.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Messaging {
|
||||
namespace Broker {
|
||||
|
||||
|
||||
class Queue;
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Processor);
|
||||
|
||||
class SC_BROKER_API Processor : public Core::BaseObject {
|
||||
public:
|
||||
Processor();
|
||||
virtual ~Processor();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Initiales the configuration of a processor from a config object
|
||||
* and a given parameter name prefix.
|
||||
* @param conf The configuration file object
|
||||
* @param configPrefix The prefix that must be preprended to all
|
||||
* parameters.
|
||||
* @return Success flag.
|
||||
*/
|
||||
virtual bool init(const Config::Config &conf, const std::string &configPrefix) = 0;
|
||||
|
||||
/**
|
||||
* @brief When a processor has been added to a queue, this method will be
|
||||
* called. The default implementation does nothing. This method
|
||||
* can be used to e.g. allocate additional client memory of
|
||||
* the local client heap.
|
||||
* @param queue The queue the processor was attached to.
|
||||
*/
|
||||
virtual bool attach(Queue *queue);
|
||||
|
||||
/**
|
||||
* @brief Shuts down the processor.
|
||||
* @return Success flag.
|
||||
*/
|
||||
virtual bool close() = 0;
|
||||
|
||||
/**
|
||||
* @brief Add information to a state of health message
|
||||
* @param timestamp The timestamp of the information
|
||||
* @param os The output stream to write to
|
||||
*/
|
||||
virtual void getInfo(const Core::Time ×tamp, std::ostream &os) = 0;
|
||||
|
||||
Queue *queue() const;
|
||||
|
||||
|
||||
private:
|
||||
Queue *_queue;
|
||||
|
||||
friend class Queue;
|
||||
};
|
||||
|
||||
|
||||
inline Queue *Processor::queue() const {
|
||||
return _queue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
343
include/seiscomp/broker/protocol.h
Normal file
343
include/seiscomp/broker/protocol.h
Normal file
@@ -0,0 +1,343 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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 GEMPA_BROKER_PROTOCOL_H__
|
||||
#define GEMPA_BROKER_PROTOCOL_H__
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Messaging {
|
||||
namespace Broker {
|
||||
namespace Protocol {
|
||||
|
||||
|
||||
// Defines do not make much sense inside namespaces but they are placed here
|
||||
// to stay close to future variable declarations.
|
||||
|
||||
/**
|
||||
* It follows a list of definitions for all protocol commands and replies and
|
||||
* their headers. They are being used in the code and changing them here will
|
||||
* cause a change in behaviour of the server.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ```
|
||||
* CONNECT
|
||||
* Ack-Window: [number of messages after which an ack will be send from the server]
|
||||
* Membership-Info: 1
|
||||
* Queue: [name of queue]
|
||||
* Client-Name: [name of client]
|
||||
* Subscriptions: [list of groups]
|
||||
* Seq-No: [last seen sequence number]
|
||||
*
|
||||
* ^@
|
||||
* ```
|
||||
*
|
||||
* The *Seq-No* header contains the last sequence number the client has seen from
|
||||
* that queue. That header is optional. If subscriptions are given then the
|
||||
* client will receive an **ENTER** frame for each group it subscribed to. If any
|
||||
* of the requested groups does not exist, an **ERROR** frame is sent and the
|
||||
* connection is closed.
|
||||
*
|
||||
* The order of messages looks as follows:
|
||||
*
|
||||
* 1. CONNECT
|
||||
* 2. CONNECTED
|
||||
* 3. ENTER
|
||||
* 4. RECV
|
||||
*
|
||||
* Step 3 repeats for as many groups as given in the subscription list. Step 4
|
||||
* repeats for all messages received during the lifetime of the connection.
|
||||
*/
|
||||
#define SCMP_PROTO_CMD_CONNECT "CONNECT"
|
||||
#define SCMP_PROTO_CMD_CONNECT_HEADER_QUEUE "Queue"
|
||||
#define SCMP_PROTO_CMD_CONNECT_HEADER_CLIENT_NAME "Client-Name"
|
||||
#define SCMP_PROTO_CMD_CONNECT_HEADER_MEMBERSHIP_INFO "Membership-Info"
|
||||
#define SCMP_PROTO_CMD_CONNECT_HEADER_SELF_DISCARD "Self-Discard"
|
||||
#define SCMP_PROTO_CMD_CONNECT_HEADER_ACK_WINDOW "Ack-Window"
|
||||
#define SCMP_PROTO_CMD_CONNECT_HEADER_SEQ_NUMBER "Seq-No"
|
||||
#define SCMP_PROTO_CMD_CONNECT_HEADER_SUBSCRIPTIONS "Subscriptions"
|
||||
|
||||
/**
|
||||
* ```
|
||||
* DISCONNECT
|
||||
* Receipt: [id]
|
||||
*
|
||||
* ^@
|
||||
* ```
|
||||
*
|
||||
* The DISCONNECT command ask the server to gracefully shutdown the connection
|
||||
* and free all associated resources.
|
||||
*/
|
||||
#define SCMP_PROTO_CMD_DISCONNECT "DISCONNECT"
|
||||
#define SCMP_PROTO_CMD_DISCONNECT_HEADER_RECEIPT "Receipt"
|
||||
|
||||
/**
|
||||
* ```
|
||||
* SUBSCRIBE
|
||||
* Groups: [list of groups]
|
||||
*
|
||||
* ^@
|
||||
* ```
|
||||
* Subscribes to a specific group which must exist on the server. In response
|
||||
* either an **ENTER** or **ERROR** frame will be received.
|
||||
*/
|
||||
#define SCMP_PROTO_CMD_SUBSCRIBE "SUBSCRIBE"
|
||||
#define SCMP_PROTO_CMD_SUBSCRIBE_HEADER_GROUPS "Groups"
|
||||
|
||||
/**
|
||||
* ```
|
||||
* UNSUBSCRIBE
|
||||
* Groups: [list of groups]
|
||||
*
|
||||
* ^@
|
||||
* ```
|
||||
*
|
||||
* Unsubscribes from a specific group which must exist on the server. In
|
||||
* response either a **LEAVE** or **ERROR** frame will be received.
|
||||
*/
|
||||
#define SCMP_PROTO_CMD_UNSUBSCRIBE "UNSUBSCRIBE"
|
||||
#define SCMP_PROTO_CMD_UNSUBSCRIBE_HEADER_GROUPS SCMP_PROTO_CMD_SUBSCRIBE_HEADER_GROUPS
|
||||
|
||||
/**
|
||||
* Sends a message to a group or a client (peer-to-peer).
|
||||
*
|
||||
* ```
|
||||
* SEND
|
||||
* D: [name of group or the client]
|
||||
* T: [MIME type]
|
||||
* E: [transfer encoding]
|
||||
* L: [length of content]
|
||||
*
|
||||
* [payload]^@
|
||||
* ```
|
||||
*
|
||||
* Each message sent will increase the private sequence number counter for this
|
||||
* connection starting with 0. So the first message will get assigned the
|
||||
* sequence number 1. That counter must be maintained by the client and the
|
||||
* server to correctly synchronize acknowledgements. If the message is rejected
|
||||
* an **ERROR** frame will be sent to the client and the connection will be
|
||||
* closed.
|
||||
*/
|
||||
#define SCMP_PROTO_CMD_SEND "SEND"
|
||||
#define SCMP_PROTO_CMD_SEND_HEADER_DESTINATION "D"
|
||||
#define SCMP_PROTO_CMD_SEND_HEADER_CONTENT_LENGTH "L"
|
||||
#define SCMP_PROTO_CMD_SEND_HEADER_ENCODING "E"
|
||||
#define SCMP_PROTO_CMD_SEND_HEADER_MIMETYPE "T"
|
||||
#define SCMP_PROTO_CMD_SEND_HEADER_TRANSIENT "Transient"
|
||||
|
||||
|
||||
/**
|
||||
* A member notifies the server about its state including memory consumption,
|
||||
* cpu usage, uptime and so on. The payload is always a key-value list
|
||||
* separated by '&'.
|
||||
*
|
||||
* ```
|
||||
* STATE
|
||||
* D: [name of group or the client]
|
||||
* L: [length of content]
|
||||
*
|
||||
* hostname=localhost&totalmemory=8589934592&clientmemoryusage=68891443...^@
|
||||
* ```
|
||||
*/
|
||||
#define SCMP_PROTO_CMD_STATE "STATE"
|
||||
#define SCMP_PROTO_CMD_STATE_HEADER_DESTINATION "D"
|
||||
#define SCMP_PROTO_CMD_STATE_HEADER_CONTENT_LENGTH "L"
|
||||
|
||||
#define SCMP_PROTO_CMD_FIRST_CHARS "CDSU"
|
||||
|
||||
/**
|
||||
* ```
|
||||
* CONNECTED
|
||||
* Queue: [name of queue]
|
||||
* Server: SeisComP/2017.334
|
||||
* Version: [server protocol version]
|
||||
* Client-Name: [client name, either auto assigned or requested by the client]
|
||||
* Authentication: [16 byte hex random NaCL nonce prefix]
|
||||
* [32 byte hex NaCL public server key]
|
||||
* [16 byte hex encrypted buffer: "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"]
|
||||
* Groups: [list of available groups]
|
||||
*
|
||||
* ^@
|
||||
* ```
|
||||
*
|
||||
* In return to a **CONNECT** frame the server responds with a **CONNECTED**
|
||||
* frame. It reports the client name in use for this connection and a list of
|
||||
* available groups.
|
||||
*/
|
||||
#define SCMP_PROTO_REPLY_CONNECT "CONNECTED"
|
||||
#define SCMP_PROTO_REPLY_CONNECT_HEADER_VERSION "Version"
|
||||
#define SCMP_PROTO_REPLY_CONNECT_HEADER_SCHEMA_VERSION "Schema-Version"
|
||||
#define SCMP_PROTO_REPLY_CONNECT_HEADER_QUEUE SCMP_PROTO_CMD_CONNECT_HEADER_QUEUE
|
||||
#define SCMP_PROTO_REPLY_CONNECT_HEADER_CLIENT_NAME SCMP_PROTO_CMD_CONNECT_HEADER_CLIENT_NAME
|
||||
#define SCMP_PROTO_REPLY_CONNECT_HEADER_ACK_WINDOW SCMP_PROTO_CMD_CONNECT_HEADER_ACK_WINDOW
|
||||
#define SCMP_PROTO_REPLY_CONNECT_HEADER_GROUPS "Groups"
|
||||
|
||||
/**
|
||||
* The probably most important part of the protocol is receiving a message from
|
||||
* a group or a client (peer-to-peer).
|
||||
*
|
||||
* ```
|
||||
* RECV
|
||||
* C: [client name of sender]
|
||||
* D: [name of group or the client]
|
||||
* T: [MIME type]
|
||||
* E: [transfer encoding]
|
||||
* N: [message sequence number]
|
||||
* L: [length of content]
|
||||
*
|
||||
* [payload]^@
|
||||
* ```
|
||||
*
|
||||
* The payload can be anything, binary data or text. Optionally the *Content-Type*
|
||||
* header is set to inform the client about the format.
|
||||
*/
|
||||
#define SCMP_PROTO_REPLY_SEND "RECV"
|
||||
#define SCMP_PROTO_REPLY_SEND_HEADER_SENDER "C"
|
||||
#define SCMP_PROTO_REPLY_SEND_HEADER_SEQ_NUMBER "N"
|
||||
#define SCMP_PROTO_REPLY_SEND_HEADER_DESTINATION SCMP_PROTO_CMD_SEND_HEADER_DESTINATION
|
||||
#define SCMP_PROTO_REPLY_SEND_HEADER_CONTENT_LENGTH SCMP_PROTO_CMD_SEND_HEADER_CONTENT_LENGTH
|
||||
#define SCMP_PROTO_REPLY_SEND_HEADER_ENCODING SCMP_PROTO_CMD_SEND_HEADER_ENCODING
|
||||
#define SCMP_PROTO_REPLY_SEND_HEADER_MIMETYPE SCMP_PROTO_CMD_SEND_HEADER_MIMETYPE
|
||||
|
||||
/**
|
||||
* ```
|
||||
* ACK
|
||||
* N: [connection specific sequence number]
|
||||
*
|
||||
* ^@
|
||||
* ```
|
||||
*
|
||||
* The server sends according to the configured acknoledgement window an
|
||||
* acknowledgement frame to signal that all messages prior to the given sequence
|
||||
* number have been processed and that the current sequence number is expected
|
||||
* to be the one sent. It will do that as well after 1 second the client
|
||||
* hasn't sent any further messages.
|
||||
*/
|
||||
#define SCMP_PROTO_REPLY_ACK "ACK"
|
||||
#define SCMP_PROTO_REPLY_ACK_HEADER_SEQ_NUMBER SCMP_PROTO_REPLY_SEND_HEADER_SEQ_NUMBER
|
||||
|
||||
/**
|
||||
* ```
|
||||
* RECEIPT
|
||||
* Receipt-Id: [id]
|
||||
*
|
||||
* ^@
|
||||
* ```
|
||||
*
|
||||
* A receipt can basically be sent for anything which has an id. A receipt is
|
||||
* being sent definitely after a disconnect request. In that case the receipt
|
||||
* id is the username.
|
||||
*/
|
||||
#define SCMP_PROTO_REPLY_RECEIPT "RECEIPT"
|
||||
#define SCMP_PROTO_REPLY_RECEIPT_HEADER_ID "Receipt-Id"
|
||||
|
||||
/**
|
||||
* A members enters a group. In response to a **SUBSCRIBE** command, the complete
|
||||
* group information will be sent to the client. Specifically if
|
||||
* ```Member == self```. Otherwise only the group and member information will be
|
||||
* sent from the server to all clients that are subscribed to that group. The
|
||||
* client needs to update its internal cache and the frame body is empty in that
|
||||
* case.
|
||||
*
|
||||
* ```
|
||||
* ENTER
|
||||
* D: [name of group]
|
||||
* C: [name of client]
|
||||
*
|
||||
* clientA, clientB, ...
|
||||
* }^@
|
||||
* ```
|
||||
*/
|
||||
#define SCMP_PROTO_REPLY_ENTER "ENTER"
|
||||
#define SCMP_PROTO_REPLY_ENTER_HEADER_GROUP "D"
|
||||
#define SCMP_PROTO_REPLY_ENTER_HEADER_MEMBER "C"
|
||||
|
||||
/**
|
||||
* A member leaves a group. This message will sent from the server to all clients
|
||||
* that are subscribed to the group in question.
|
||||
*
|
||||
* ```
|
||||
* LEAVE
|
||||
* D: [name of group]
|
||||
* C: [name of client]
|
||||
*
|
||||
* ^@
|
||||
* ```
|
||||
*/
|
||||
#define SCMP_PROTO_REPLY_LEAVE "LEAVE"
|
||||
#define SCMP_PROTO_REPLY_LEAVE_HEADER_GROUP SCMP_PROTO_REPLY_ENTER_HEADER_GROUP
|
||||
#define SCMP_PROTO_REPLY_LEAVE_HEADER_MEMBER SCMP_PROTO_REPLY_ENTER_HEADER_MEMBER
|
||||
|
||||
/**
|
||||
* A member state of health information or simply its state including
|
||||
* memory consumption, cpu usage, uptime and so on. The payload is always
|
||||
* a key-value list separated by '&'.
|
||||
*
|
||||
* ```
|
||||
* STATE
|
||||
* L: [length of content]
|
||||
* D: [name of group or the client]
|
||||
* C: [name of client]
|
||||
*
|
||||
* hostname=localhost&totalmemory=8589934592&clientmemoryusage=68891443...^@
|
||||
* ```
|
||||
*/
|
||||
#define SCMP_PROTO_REPLY_STATE "STATE"
|
||||
#define SCMP_PROTO_REPLY_STATE_HEADER_DESTINATION "D"
|
||||
#define SCMP_PROTO_REPLY_STATE_HEADER_CLIENT "C"
|
||||
#define SCMP_PROTO_REPLY_STATE_HEADER_CONTENT_LENGTH SCMP_PROTO_CMD_SEND_HEADER_CONTENT_LENGTH
|
||||
|
||||
/**
|
||||
* A client was disconnected. This message will sent from the server to all
|
||||
* clients currently connected.
|
||||
*
|
||||
* ```
|
||||
* DISCONNECTED
|
||||
* C: [name of client]
|
||||
*
|
||||
* ^@
|
||||
* ```
|
||||
*/
|
||||
#define SCMP_PROTO_REPLY_DISCONNECTED "DISCONNECTED"
|
||||
#define SCMP_PROTO_REPLY_DISCONNECTED_HEADER_CLIENT SCMP_PROTO_REPLY_STATE_HEADER_CLIENT
|
||||
|
||||
/**
|
||||
* ```
|
||||
* ERROR
|
||||
* N: [connection specific sequence number]
|
||||
*
|
||||
* Error message ...^@
|
||||
* ```
|
||||
*/
|
||||
#define SCMP_PROTO_REPLY_ERROR "ERROR"
|
||||
#define SCMP_PROTO_REPLY_ERROR_HEADER_SEQ_NUMBER SCMP_PROTO_REPLY_SEND_HEADER_SEQ_NUMBER
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
419
include/seiscomp/broker/queue.h
Normal file
419
include/seiscomp/broker/queue.h
Normal file
@@ -0,0 +1,419 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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_BROKER_QUEUE_H__
|
||||
#define SEISCOMP_BROKER_QUEUE_H__
|
||||
|
||||
|
||||
#include <seiscomp/core/enumeration.h>
|
||||
#include <seiscomp/core/message.h>
|
||||
|
||||
#include <seiscomp/broker/messageprocessor.h>
|
||||
#include <seiscomp/broker/hashset.h>
|
||||
#include <seiscomp/broker/group.h>
|
||||
#include <seiscomp/broker/message.h>
|
||||
#include <seiscomp/broker/statistics.h>
|
||||
|
||||
#include <seiscomp/broker/utils/utils.h>
|
||||
#include <seiscomp/broker/utils/circular.h>
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Messaging {
|
||||
namespace Broker {
|
||||
|
||||
|
||||
class Client;
|
||||
class MessageDispatcher;
|
||||
|
||||
DEFINE_SMARTPOINTER(MessageProcessor);
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Queue class implements the central messaging service.
|
||||
*
|
||||
* The Queue receives messages, queues them and distributes them to subscribed
|
||||
* clients.
|
||||
*/
|
||||
class SC_BROKER_API Queue {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
using StringList = std::vector<std::string>;
|
||||
using MessageProcessors = std::vector<MessageProcessorPtr>;
|
||||
|
||||
using KeyValueCStrPair = MessageProcessor::KeyValueCStrPair;
|
||||
using KeyCStrValues = MessageProcessor::KeyCStrValues;
|
||||
|
||||
using KeyValuePair = MessageProcessor::KeyValuePair;
|
||||
using KeyValues = MessageProcessor::KeyValues;
|
||||
|
||||
enum Constants {
|
||||
MaxAdditionalParams = MessageProcessor::MaxAdditionalParams
|
||||
};
|
||||
|
||||
MAKEENUM(
|
||||
Result,
|
||||
EVALUES(
|
||||
Success,
|
||||
InternalError,
|
||||
ClientNameNotUnique,
|
||||
ClientNotAccepted,
|
||||
GroupNameNotUnique,
|
||||
GroupDoesNotExist,
|
||||
GroupAlreadySubscribed,
|
||||
GroupNotSubscribed,
|
||||
MessageNotAccepted,
|
||||
MessageDecodingFailed,
|
||||
MessageEncodingFailed,
|
||||
NotEnoughClientHeap
|
||||
),
|
||||
ENAMES(
|
||||
"Success",
|
||||
"Internal error",
|
||||
"Client name is not unique",
|
||||
"Client was not accepted",
|
||||
"Group name is not unique",
|
||||
"Group does not exist",
|
||||
"Already subscribed to group",
|
||||
"Not subscribed to group",
|
||||
"Message not accepted",
|
||||
"Message could not be decoded",
|
||||
"Message could not be encoded",
|
||||
"Not enough client heap"
|
||||
)
|
||||
);
|
||||
|
||||
const std::string StatusGroup = "STATUS_GROUP";
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Queue(const std::string &name, uint64_t maxPayloadSize);
|
||||
~Queue();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @return The queue name
|
||||
*/
|
||||
const std::string &name() const;
|
||||
|
||||
/**
|
||||
* @brief Adds a message processor to the list of processors.
|
||||
* @param proc The processor instance which is managed by the queue
|
||||
* with a smart pointer.
|
||||
* @return Success flag
|
||||
*/
|
||||
bool add(MessageProcessor *proc);
|
||||
|
||||
/**
|
||||
* @brief Adds a group/topic to the queue.
|
||||
* @param name The name of the group
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
Result addGroup(const std::string &name);
|
||||
|
||||
/**
|
||||
* @brief Returns a list of available group names
|
||||
* @return The list of names
|
||||
*/
|
||||
const StringList &groups() const { return _groupNames; }
|
||||
|
||||
/**
|
||||
* @brief Return the sender name of the queue.
|
||||
* @return A NULL terminated const string
|
||||
*/
|
||||
const char *senderName() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the message dispatcher for thread synchronisation.
|
||||
*
|
||||
* The queue runs a thread to process messages via plugins. If the
|
||||
* message is processed the thread notifies the queue about it. The
|
||||
* queue could now call publish but that is probably not thread-safe
|
||||
* and inefficient to implement on each subscriber. The message
|
||||
* dispatcher receives a notification about a new message and can then
|
||||
* implement any inter-thread communication to publish the message in
|
||||
* the same context as it has been created.
|
||||
*
|
||||
* @param dispatcher The dispatcher instance not managed by the queue.
|
||||
*/
|
||||
void setMessageDispatcher(MessageDispatcher *dispatcher);
|
||||
|
||||
/**
|
||||
* @brief Subscribe a client to a particular group
|
||||
* @param client The client
|
||||
* @param group The name of the group
|
||||
* @return The result code
|
||||
*/
|
||||
Result subscribe(Client *client, const std::string &group);
|
||||
|
||||
/**
|
||||
* @brief Unsubscribes a client from a particular group
|
||||
* @param client The client
|
||||
* @param group The name of the group
|
||||
* @return The result code
|
||||
*/
|
||||
Result unsubscribe(Client *client, const std::string &group);
|
||||
|
||||
/**
|
||||
* @brief Returns a buffered message after a particular sequence number
|
||||
* @param sequenceNumber The sequence number to continue with.
|
||||
*
|
||||
* The returned message must have a sequence number greater than
|
||||
* this parameter or lower if a wrap has occured but never the
|
||||
* same.
|
||||
* @param client The client instance to filter subscriptions for
|
||||
* @return A message pointer or NULL if no message is available
|
||||
*/
|
||||
Message *getMessage(SequenceNumber sequenceNumber,
|
||||
const Client *client) const;
|
||||
|
||||
/**
|
||||
* @brief Pushes a message from a client to the queue
|
||||
*
|
||||
* This method is called from Client subclasses that received a message
|
||||
* through their transport protocol. The message pointer will either
|
||||
* be managed in a smart pointer or deleted. If false is returned the
|
||||
* caller must take care of deleting the message.
|
||||
*
|
||||
* @param sender The sender instance
|
||||
* @param msg The message
|
||||
* @param packetLength The size in bytes of the received packet including
|
||||
* protocol specific header data. This is only
|
||||
* used for statistics.
|
||||
* @return The result code
|
||||
*/
|
||||
Result push(Client *sender, Message *msg, int packetSize = 0);
|
||||
|
||||
/**
|
||||
* @brief Dispatches a message via a message dispatcher. If none is
|
||||
* set then this call is equal to push.
|
||||
* @param sender The sender instance
|
||||
* @param msg The message
|
||||
* @return The result code
|
||||
*/
|
||||
Result dispatch(Client *sender, Message *msg);
|
||||
|
||||
/**
|
||||
* @brief Activates the queue and starts the processing thread.
|
||||
*/
|
||||
void activate();
|
||||
|
||||
/**
|
||||
* @brief Shutdown the queue and finished the processing thread if
|
||||
* running.
|
||||
*
|
||||
* This will also shutdown all processors associated with the queue.
|
||||
*
|
||||
* Note that this call can block depending how many plugins are
|
||||
* running and currently processing a message. This method waits until
|
||||
* the processing thread is finished.
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* @brief Callback to notify the queue about some timeout.
|
||||
*
|
||||
* This function is used to check expiration of outstanding
|
||||
* acknowledgement messages. This function is not thread-safe and
|
||||
* must be called from within the thread the queue is running in.
|
||||
*/
|
||||
void timeout();
|
||||
|
||||
/**
|
||||
* @brief Populates the passed statistics structure.
|
||||
* @param stats[out] The target structure
|
||||
* @param reset[in] Whether to reset the internal statistics or not.
|
||||
*/
|
||||
void getStatisticsSnapshot(QueueStatistics &stats, bool reset = true);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Client memory interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief Allocates additional client heap. Once allocated the heap
|
||||
* cannot be free'd anymore. This is mainly used for plugins
|
||||
* that are initialized once and need to store additional
|
||||
* data in a client structure.
|
||||
* @param bytes The number of bytes to allocate
|
||||
* @return An offset to the local client heap or a negative number
|
||||
* in case of an error. The absolute value (-result) of the
|
||||
* error translates to a status code (@Result).
|
||||
*/
|
||||
int allocateClientHeap(int bytes);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Publisher interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief Registers a client in the queue and sets up the PubSub
|
||||
* connections.
|
||||
*
|
||||
* This is called when the client calls connect and is part of the
|
||||
* PublisherBase interface.
|
||||
* @param client The client to be registered
|
||||
* @param slot The slot
|
||||
* @return The result code
|
||||
*/
|
||||
Result connect(Client *client, const KeyCStrValues params, int paramCount,
|
||||
KeyValues &outParams);
|
||||
|
||||
/**
|
||||
* @brief Deregisters a client from the queue and clears the PubSub
|
||||
* connections.
|
||||
*
|
||||
* This is called when the client calls disconnect and is part of the
|
||||
* PublisherBase interface.
|
||||
* @param client The client to be deregistered
|
||||
* @return The result code
|
||||
*/
|
||||
Result disconnect(Client *client);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Settings interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
uint64_t maxPayloadSize() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
using ProcessingTask = std::pair<Client*,Message*>;
|
||||
using TaskQueue = Utils::BlockingDequeue<ProcessingTask>;
|
||||
|
||||
/**
|
||||
* @brief Publishes a message from a client to all registered clients
|
||||
*
|
||||
* This method is called from Client subclasses that received a message
|
||||
* through their transport protocol.
|
||||
*
|
||||
* @param sender The sender instance
|
||||
* @param msg The message
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool publish(Client *sender, Message *msg);
|
||||
|
||||
/**
|
||||
* @brief Pops all messages from the processing queue and publishes them.
|
||||
*
|
||||
* This call does not block.
|
||||
*/
|
||||
void flushProcessedMessages();
|
||||
|
||||
/**
|
||||
* @brief The processing loop running in a different thread.
|
||||
*/
|
||||
void processingLoop();
|
||||
|
||||
/**
|
||||
* @brief Processes a message e.g. via plugins.
|
||||
* @param task The task to be processed
|
||||
*/
|
||||
void process(ProcessingTask &task);
|
||||
|
||||
/**
|
||||
* @brief Called from the processing thread informing the queue that
|
||||
* the message is processed and can be forwarded to clients.
|
||||
* @param task The task
|
||||
*/
|
||||
void taskReady(const ProcessingTask &task);
|
||||
|
||||
/**
|
||||
* @brief Replaces the incoming message with a response
|
||||
* @param task The task to be updated
|
||||
*/
|
||||
void returnToSender(Message *msg, Core::BaseObject *obj);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
using Groups = std::map<std::string, GroupPtr>;
|
||||
using MessageRing = circular_buffer<MessagePtr>;
|
||||
using ClientNames = KHashSet<const char*>;
|
||||
using Clients = KHashMap<const char*, Client*>;
|
||||
|
||||
std::string _name;
|
||||
MessageProcessors _processors;
|
||||
MessageProcessors _connectionProcessors;
|
||||
MessageProcessors _messageProcessors;
|
||||
MessageDispatcher *_processedMessageDispatcher;
|
||||
SequenceNumber _sequenceNumber;
|
||||
Groups _groups;
|
||||
StringList _groupNames;
|
||||
MessageRing _messages;
|
||||
Clients _clients;
|
||||
std::thread *_messageProcessor;
|
||||
TaskQueue _tasks;
|
||||
TaskQueue _results;
|
||||
Core::Time _created;
|
||||
Core::Time _lastSOHTimestamp;
|
||||
int _allocatedClientHeap;
|
||||
int _sohInterval;
|
||||
int _inactivityLimit;
|
||||
uint64_t _maxPayloadSize;
|
||||
mutable Tx _txMessages;
|
||||
mutable Tx _txBytes;
|
||||
mutable Tx _txPayload;
|
||||
|
||||
|
||||
friend class MessageDispatcher;
|
||||
};
|
||||
|
||||
|
||||
inline const std::string &Queue::name() const {
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
inline uint64_t Queue::maxPayloadSize() const {
|
||||
return _maxPayloadSize;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
109
include/seiscomp/broker/statistics.h
Normal file
109
include/seiscomp/broker/statistics.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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_BROKER_STATISTICS_H__
|
||||
#define SEISCOMP_BROKER_STATISTICS_H__
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/broker/api.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Messaging {
|
||||
namespace Broker {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Simple structure to store transfer counts.
|
||||
* The unit of the counters is not defined. It can be counts or
|
||||
* bytes or something different. That depends on the context.
|
||||
*/
|
||||
struct SC_BROKER_API Tx : Core::BaseObject {
|
||||
Tx() : received(0), sent(0) {}
|
||||
|
||||
double received; //!< Number of items received
|
||||
double sent; //!< Number of items sent
|
||||
|
||||
Tx &operator+=(const Tx &other) {
|
||||
received += other.received;
|
||||
sent += other.sent;
|
||||
return *this;
|
||||
}
|
||||
|
||||
DECLARE_SERIALIZATION {
|
||||
ar
|
||||
& NAMED_OBJECT("recv", received)
|
||||
& NAMED_OBJECT("sent", sent)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct GroupStatistics : Core::BaseObject {
|
||||
std::string name;
|
||||
Tx messages;
|
||||
Tx bytes;
|
||||
Tx payload;
|
||||
|
||||
DECLARE_SERIALIZATION {
|
||||
ar
|
||||
& NAMED_OBJECT("name", name)
|
||||
& NAMED_OBJECT_HINT("messages", messages, Archive::STATIC_TYPE)
|
||||
& NAMED_OBJECT_HINT("bytes", bytes, Archive::STATIC_TYPE)
|
||||
& NAMED_OBJECT_HINT("payload", payload, Archive::STATIC_TYPE)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(QueueStatistics);
|
||||
struct SC_BROKER_API QueueStatistics : Core::BaseObject {
|
||||
typedef std::vector<GroupStatistics> Groups;
|
||||
std::string name;
|
||||
Groups groups;
|
||||
Tx messages;
|
||||
Tx bytes;
|
||||
Tx payload;
|
||||
|
||||
QueueStatistics &operator+=(const QueueStatistics &stats);
|
||||
|
||||
DECLARE_SERIALIZATION {
|
||||
ar
|
||||
& NAMED_OBJECT("name", name)
|
||||
& NAMED_OBJECT_HINT("messages", messages, Archive::STATIC_TYPE)
|
||||
& NAMED_OBJECT_HINT("bytes", bytes, Archive::STATIC_TYPE)
|
||||
& NAMED_OBJECT_HINT("payload", payload, Archive::STATIC_TYPE)
|
||||
& NAMED_OBJECT_HINT("groups", groups, Archive::STATIC_TYPE)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
496
include/seiscomp/broker/utils/circular.h
Normal file
496
include/seiscomp/broker/utils/circular.h
Normal file
@@ -0,0 +1,496 @@
|
||||
/******************************************************************************
|
||||
* Author: Pete Goodliffe
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright 2002 Pete Goodliffe All rights reserved.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Purpose: STL-style circular buffer
|
||||
*
|
||||
* Formatting changed by <Jan Becker, gempa GmbH> jabe@gempa.de
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef CIRCULAR_BUFFER_H
|
||||
#define CIRCULAR_BUFFER_H
|
||||
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Iterators
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Iterator type for the circular_buffer class.
|
||||
*
|
||||
* This one template class provides all variants of forward/reverse
|
||||
* const/non const iterators through plentiful template magic.
|
||||
*
|
||||
* You don't need to instantiate it directly, use the good public functions
|
||||
* availble in circular_buffer.
|
||||
*/
|
||||
template<typename T, //circular_buffer type
|
||||
//(incl const)
|
||||
typename T_nonconst, //with any consts
|
||||
typename elem_type = typename T::value_type> //+ const for const iter
|
||||
class circular_buffer_iterator {
|
||||
public:
|
||||
typedef circular_buffer_iterator<T, T_nonconst, elem_type> self_type;
|
||||
typedef T cbuf_type;
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef typename cbuf_type::value_type value_type;
|
||||
typedef typename cbuf_type::size_type size_type;
|
||||
typedef typename cbuf_type::pointer pointer;
|
||||
typedef typename cbuf_type::const_pointer const_pointer;
|
||||
typedef typename cbuf_type::reference reference;
|
||||
typedef typename cbuf_type::const_reference const_reference;
|
||||
typedef typename cbuf_type::difference_type difference_type;
|
||||
|
||||
circular_buffer_iterator(cbuf_type *b, size_type p)
|
||||
: buf_(b), pos_(p) {}
|
||||
|
||||
// Converting a non-const iterator to a const iterator
|
||||
circular_buffer_iterator(const circular_buffer_iterator<T_nonconst, T_nonconst, typename T_nonconst::value_type> &other)
|
||||
: buf_(other.buf_), pos_(other.pos_) {}
|
||||
|
||||
friend class circular_buffer_iterator<const T, T, const elem_type> ;
|
||||
|
||||
// Use compiler generated copy ctor, copy assignment operator and dtor
|
||||
|
||||
elem_type &operator*() {
|
||||
return (*buf_)[pos_];
|
||||
}
|
||||
|
||||
elem_type *operator->() {
|
||||
return &(operator*());
|
||||
}
|
||||
|
||||
self_type &operator++() {
|
||||
pos_ += 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self_type operator++(int) {
|
||||
self_type tmp(*this);
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
self_type &operator--() {
|
||||
pos_ -= 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self_type operator--(int) {
|
||||
self_type tmp(*this);
|
||||
--(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
self_type operator+(difference_type n) const {
|
||||
self_type tmp(*this);
|
||||
tmp.pos_ += n;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
self_type &operator+=(difference_type n) {
|
||||
pos_ += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self_type operator-(difference_type n) const {
|
||||
self_type tmp(*this);
|
||||
tmp.pos_ -= n;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
self_type &operator-=(difference_type n) {
|
||||
pos_ -= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
difference_type operator-(const self_type &c) const {
|
||||
return pos_ - c.pos_;
|
||||
}
|
||||
|
||||
bool operator==(const self_type &other) const {
|
||||
return pos_ == other.pos_ && buf_ == other.buf_;
|
||||
}
|
||||
bool operator!=(const self_type &other) const {
|
||||
return pos_ != other.pos_ && buf_ == other.buf_;
|
||||
}
|
||||
bool operator>(const self_type &other) const {
|
||||
return pos_ > other.pos_;
|
||||
}
|
||||
bool operator>=(const self_type &other) const {
|
||||
return pos_ >= other.pos_;
|
||||
}
|
||||
bool operator<(const self_type &other) const {
|
||||
return pos_ < other.pos_;
|
||||
}
|
||||
bool operator<=(const self_type &other) const {
|
||||
return pos_ <= other.pos_;
|
||||
}
|
||||
|
||||
private:
|
||||
cbuf_type *buf_;
|
||||
size_type pos_;
|
||||
};
|
||||
|
||||
|
||||
template<typename circular_buffer_iterator_t>
|
||||
circular_buffer_iterator_t operator+(
|
||||
const typename circular_buffer_iterator_t::difference_type &a,
|
||||
const circular_buffer_iterator_t &b) {
|
||||
return circular_buffer_iterator_t(a) + b;
|
||||
}
|
||||
|
||||
template<typename circular_buffer_iterator_t>
|
||||
circular_buffer_iterator_t operator-(
|
||||
const typename circular_buffer_iterator_t::difference_type &a,
|
||||
const circular_buffer_iterator_t &b) {
|
||||
return circular_buffer_iterator_t(a) - b;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* circular_buffer
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* This class provides a circular buffer in the STL style.
|
||||
*
|
||||
* You can add data to the end using the @ref push_back function, read data
|
||||
* using @ref front() and remove data using @ref pop_front().
|
||||
*
|
||||
* The class also provides random access through the @ref operator[]()
|
||||
* function and its random access iterator. Subscripting the array with
|
||||
* an invalid (out of range) index number leads to undefined results, both
|
||||
* for reading and writing.
|
||||
*
|
||||
* This class template accepts three template parameters:
|
||||
* <li> T The type of object contained
|
||||
* <li> always_accept_data_when_full Determines the behaviour of
|
||||
* @ref push_back when the buffer is full.
|
||||
* Set to true new data is always added, the
|
||||
* old "end" data is thrown away.
|
||||
* Set to false, the new data is not added.
|
||||
* No error is returned neither is an
|
||||
* exception raised.
|
||||
* <li> Alloc Allocator type to use (in line with other
|
||||
* STL containers).
|
||||
*
|
||||
* @short STL style circule buffer
|
||||
* @author Pete Goodliffe
|
||||
* @version 1.00
|
||||
*/
|
||||
template<typename T, bool always_accept_data_when_full = true,
|
||||
typename Alloc = std::allocator<T> >
|
||||
class circular_buffer {
|
||||
public:
|
||||
enum {
|
||||
version_major = 1, version_minor = 0
|
||||
};
|
||||
|
||||
// Typedefs
|
||||
typedef circular_buffer<T, always_accept_data_when_full, Alloc> self_type;
|
||||
|
||||
typedef Alloc allocator_type;
|
||||
|
||||
typedef typename Alloc::value_type value_type;
|
||||
typedef typename Alloc::pointer pointer;
|
||||
typedef typename Alloc::const_pointer const_pointer;
|
||||
typedef typename Alloc::reference reference;
|
||||
typedef typename Alloc::const_reference const_reference;
|
||||
|
||||
typedef typename Alloc::size_type size_type;
|
||||
typedef typename Alloc::difference_type difference_type;
|
||||
|
||||
typedef circular_buffer_iterator<self_type, self_type> iterator;
|
||||
typedef circular_buffer_iterator<const self_type, self_type,
|
||||
const value_type> const_iterator;
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
// Lifetime
|
||||
enum {
|
||||
default_capacity = 100
|
||||
};
|
||||
|
||||
explicit circular_buffer(size_type capacity = default_capacity)
|
||||
: array_(alloc_.allocate(capacity))
|
||||
, array_size_(capacity)
|
||||
, head_(1)
|
||||
, tail_(0)
|
||||
, contents_size_(0) {}
|
||||
|
||||
circular_buffer(const circular_buffer &other)
|
||||
: array_(alloc_.allocate(other.array_size_))
|
||||
, array_size_(other.array_size_), head_(other.head_)
|
||||
, tail_(other.tail_), contents_size_(other.contents_size_) {
|
||||
try {
|
||||
assign_into(other.begin(), other.end());
|
||||
}
|
||||
catch ( ... ) {
|
||||
destroy_all_elements();
|
||||
alloc_.deallocate(array_, array_size_);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template<class InputIterator>
|
||||
circular_buffer(InputIterator from, InputIterator to)
|
||||
: array_(alloc_.allocate(1)), array_size_(1)
|
||||
, head_(1), tail_(0), contents_size_(0) {
|
||||
circular_buffer tmp;
|
||||
tmp.assign_into_reserving(from, to);
|
||||
swap(tmp);
|
||||
}
|
||||
|
||||
~circular_buffer() {
|
||||
destroy_all_elements();
|
||||
alloc_.deallocate(array_, array_size_);
|
||||
}
|
||||
|
||||
circular_buffer &operator=(const self_type &other) {
|
||||
circular_buffer tmp(other);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(circular_buffer &other) {
|
||||
std::swap(array_, other.array_);
|
||||
std::swap(array_size_, other.array_size_);
|
||||
std::swap(head_, other.head_);
|
||||
std::swap(tail_, other.tail_);
|
||||
std::swap(contents_size_, other.contents_size_);
|
||||
}
|
||||
|
||||
allocator_type get_allocator() const {
|
||||
return alloc_;
|
||||
}
|
||||
|
||||
// Iterators
|
||||
iterator begin() {
|
||||
return iterator(this, 0);
|
||||
}
|
||||
|
||||
iterator end() {
|
||||
return iterator(this, size());
|
||||
}
|
||||
|
||||
const_iterator begin() const {
|
||||
return const_iterator(this, 0);
|
||||
}
|
||||
|
||||
const_iterator end() const {
|
||||
return const_iterator(this, size());
|
||||
}
|
||||
|
||||
reverse_iterator rbegin() {
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
|
||||
reverse_iterator rend() {
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
|
||||
const_reverse_iterator rbegin() const {
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
const_reverse_iterator rend() const {
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
// Size
|
||||
size_type size() const {
|
||||
return contents_size_;
|
||||
}
|
||||
|
||||
size_type capacity() const {
|
||||
return array_size_;
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return !contents_size_;
|
||||
}
|
||||
|
||||
size_type max_size() const {
|
||||
return alloc_.max_size();
|
||||
}
|
||||
|
||||
void reserve(size_type new_size) {
|
||||
if ( capacity() < new_size ) {
|
||||
circular_buffer tmp(new_size);
|
||||
tmp.assign_into(begin(), end());
|
||||
swap(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// Accessing
|
||||
reference front() {
|
||||
return array_[head_];
|
||||
}
|
||||
|
||||
reference back() {
|
||||
return array_[tail_];
|
||||
}
|
||||
|
||||
const_reference front() const {
|
||||
return array_[head_];
|
||||
}
|
||||
|
||||
const_reference back() const {
|
||||
return array_[tail_];
|
||||
}
|
||||
|
||||
void push_back(const value_type &item) {
|
||||
size_type next = next_tail();
|
||||
if ( contents_size_ == array_size_ ) {
|
||||
if ( always_accept_data_when_full ) {
|
||||
array_[next] = item;
|
||||
increment_head();
|
||||
}
|
||||
}
|
||||
else {
|
||||
alloc_.construct(array_ + next, item);
|
||||
}
|
||||
increment_tail();
|
||||
}
|
||||
|
||||
void pop_front() {
|
||||
size_type destroy_pos = head_;
|
||||
increment_head();
|
||||
alloc_.destroy(array_ + destroy_pos);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
for ( size_type n = 0; n < contents_size_; ++n ) {
|
||||
alloc_.destroy(array_ + index_to_subscript(n));
|
||||
}
|
||||
head_ = 1;
|
||||
tail_ = contents_size_ = 0;
|
||||
}
|
||||
|
||||
reference operator[](size_type n) {
|
||||
return at_unchecked(n);
|
||||
}
|
||||
|
||||
const_reference operator[](size_type n) const {
|
||||
return at_unchecked(n);
|
||||
}
|
||||
|
||||
reference at(size_type n) {
|
||||
return at_checked(n);
|
||||
}
|
||||
|
||||
const_reference at(size_type n) const {
|
||||
return at_checked(n);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
reference at_unchecked(size_type index) const {
|
||||
return array_[index_to_subscript(index)];
|
||||
}
|
||||
|
||||
reference at_checked(size_type index) const {
|
||||
if ( index >= contents_size_ ) {
|
||||
throw std::out_of_range("index out of bounds");
|
||||
}
|
||||
return at_unchecked(index);
|
||||
}
|
||||
|
||||
// Rounds an unbounded to an index into array_
|
||||
size_type normalise(size_type n) const {
|
||||
return n % array_size_;
|
||||
}
|
||||
|
||||
// Converts external index to an array subscript
|
||||
size_type index_to_subscript(size_type index) const {
|
||||
return normalise(index + head_);
|
||||
}
|
||||
|
||||
void increment_tail() {
|
||||
++contents_size_;
|
||||
tail_ = next_tail();
|
||||
}
|
||||
|
||||
size_type next_tail() {
|
||||
return (tail_ + 1 == array_size_) ? 0 : tail_ + 1;
|
||||
}
|
||||
|
||||
void increment_head() {
|
||||
// precondition: !empty()
|
||||
++head_;
|
||||
--contents_size_;
|
||||
if ( head_ == array_size_ )
|
||||
head_ = 0;
|
||||
}
|
||||
|
||||
template<typename f_iter>
|
||||
void assign_into(f_iter from, f_iter to) {
|
||||
if ( contents_size_ )
|
||||
clear();
|
||||
while ( from != to ) {
|
||||
push_back(*from);
|
||||
++from;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename f_iter>
|
||||
void assign_into_reserving(f_iter from, f_iter to) {
|
||||
if ( contents_size_ )
|
||||
clear();
|
||||
|
||||
while ( from != to ) {
|
||||
if ( contents_size_ == array_size_ ) {
|
||||
reserve(static_cast<size_type>(array_size_ * 1.5));
|
||||
}
|
||||
|
||||
push_back(*from);
|
||||
++from;
|
||||
}
|
||||
}
|
||||
|
||||
void destroy_all_elements() {
|
||||
for ( size_type n = 0; n < contents_size_; ++n ) {
|
||||
alloc_.destroy(array_ + index_to_subscript(n));
|
||||
}
|
||||
}
|
||||
|
||||
allocator_type alloc_;
|
||||
value_type *array_;
|
||||
size_type array_size_;
|
||||
size_type head_;
|
||||
size_type tail_;
|
||||
size_type contents_size_;
|
||||
};
|
||||
|
||||
|
||||
template<typename T, bool consume_policy, typename Alloc>
|
||||
bool operator==(const circular_buffer<T, consume_policy, Alloc> &a,
|
||||
const circular_buffer<T, consume_policy, Alloc> &b) {
|
||||
return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
|
||||
}
|
||||
|
||||
template<typename T, bool consume_policy, typename Alloc>
|
||||
bool operator!=(const circular_buffer<T, consume_policy, Alloc> &a,
|
||||
const circular_buffer<T, consume_policy, Alloc> &b) {
|
||||
return a.size() != b.size() || !std::equal(a.begin(), a.end(), b.begin());
|
||||
}
|
||||
|
||||
template<typename T, bool consume_policy, typename Alloc>
|
||||
bool operator<(const circular_buffer<T, consume_policy, Alloc> &a,
|
||||
const circular_buffer<T, consume_policy, Alloc> &b) {
|
||||
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
627
include/seiscomp/broker/utils/khash.h
Normal file
627
include/seiscomp/broker/utils/khash.h
Normal file
@@ -0,0 +1,627 @@
|
||||
/* The MIT License
|
||||
|
||||
Copyright (c) 2008, 2009, 2011 by Attractive Chaos <attractor@live.co.uk>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
An example:
|
||||
|
||||
#include "khash.h"
|
||||
KHASH_MAP_INIT_INT(32, char)
|
||||
int main() {
|
||||
int ret, is_missing;
|
||||
khiter_t k;
|
||||
khash_t(32) *h = kh_init(32);
|
||||
k = kh_put(32, h, 5, &ret);
|
||||
kh_value(h, k) = 10;
|
||||
k = kh_get(32, h, 10);
|
||||
is_missing = (k == kh_end(h));
|
||||
k = kh_get(32, h, 5);
|
||||
kh_del(32, h, k);
|
||||
for (k = kh_begin(h); k != kh_end(h); ++k)
|
||||
if (kh_exist(h, k)) kh_value(h, k) = 1;
|
||||
kh_destroy(32, h);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
2013-05-02 (0.2.8):
|
||||
|
||||
* Use quadratic probing. When the capacity is power of 2, stepping function
|
||||
i*(i+1)/2 guarantees to traverse each bucket. It is better than double
|
||||
hashing on cache performance and is more robust than linear probing.
|
||||
|
||||
In theory, double hashing should be more robust than quadratic probing.
|
||||
However, my implementation is probably not for large hash tables, because
|
||||
the second hash function is closely tied to the first hash function,
|
||||
which reduce the effectiveness of double hashing.
|
||||
|
||||
Reference: http://research.cs.vt.edu/AVresearch/hashing/quadratic.php
|
||||
|
||||
2011-12-29 (0.2.7):
|
||||
|
||||
* Minor code clean up; no actual effect.
|
||||
|
||||
2011-09-16 (0.2.6):
|
||||
|
||||
* The capacity is a power of 2. This seems to dramatically improve the
|
||||
speed for simple keys. Thank Zilong Tan for the suggestion. Reference:
|
||||
|
||||
- http://code.google.com/p/ulib/
|
||||
- http://nothings.org/computer/judy/
|
||||
|
||||
* Allow to optionally use linear probing which usually has better
|
||||
performance for random input. Double hashing is still the default as it
|
||||
is more robust to certain non-random input.
|
||||
|
||||
* Added Wang's integer hash function (not used by default). This hash
|
||||
function is more robust to certain non-random input.
|
||||
|
||||
2011-02-14 (0.2.5):
|
||||
|
||||
* Allow to declare global functions.
|
||||
|
||||
2009-09-26 (0.2.4):
|
||||
|
||||
* Improve portability
|
||||
|
||||
2008-09-19 (0.2.3):
|
||||
|
||||
* Corrected the example
|
||||
* Improved interfaces
|
||||
|
||||
2008-09-11 (0.2.2):
|
||||
|
||||
* Improved speed a little in kh_put()
|
||||
|
||||
2008-09-10 (0.2.1):
|
||||
|
||||
* Added kh_clear()
|
||||
* Fixed a compiling error
|
||||
|
||||
2008-09-02 (0.2.0):
|
||||
|
||||
* Changed to token concatenation which increases flexibility.
|
||||
|
||||
2008-08-31 (0.1.2):
|
||||
|
||||
* Fixed a bug in kh_get(), which has not been tested previously.
|
||||
|
||||
2008-08-31 (0.1.1):
|
||||
|
||||
* Added destructor
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __AC_KHASH_H
|
||||
#define __AC_KHASH_H
|
||||
|
||||
/*!
|
||||
@header
|
||||
|
||||
Generic hash table library.
|
||||
*/
|
||||
|
||||
#define AC_VERSION_KHASH_H "0.2.8"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* compiler specific configuration */
|
||||
|
||||
#if UINT_MAX == 0xffffffffu
|
||||
typedef unsigned int khint32_t;
|
||||
#elif ULONG_MAX == 0xffffffffu
|
||||
typedef unsigned long khint32_t;
|
||||
#endif
|
||||
|
||||
#if ULONG_MAX == ULLONG_MAX
|
||||
typedef unsigned long khint64_t;
|
||||
#else
|
||||
typedef unsigned long long khint64_t;
|
||||
#endif
|
||||
|
||||
#ifndef kh_inline
|
||||
#ifdef _MSC_VER
|
||||
#define kh_inline __inline
|
||||
#else
|
||||
#define kh_inline inline
|
||||
#endif
|
||||
#endif /* kh_inline */
|
||||
|
||||
#ifndef klib_unused
|
||||
#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3)
|
||||
#define klib_unused __attribute__ ((__unused__))
|
||||
#else
|
||||
#define klib_unused
|
||||
#endif
|
||||
#endif /* klib_unused */
|
||||
|
||||
typedef khint32_t khint_t;
|
||||
typedef khint_t khiter_t;
|
||||
|
||||
#define __ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2)
|
||||
#define __ac_isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1)
|
||||
#define __ac_iseither(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&3)
|
||||
#define __ac_set_isdel_false(flag, i) (flag[i>>4]&=~(1ul<<((i&0xfU)<<1)))
|
||||
#define __ac_set_isempty_false(flag, i) (flag[i>>4]&=~(2ul<<((i&0xfU)<<1)))
|
||||
#define __ac_set_isboth_false(flag, i) (flag[i>>4]&=~(3ul<<((i&0xfU)<<1)))
|
||||
#define __ac_set_isdel_true(flag, i) (flag[i>>4]|=1ul<<((i&0xfU)<<1))
|
||||
|
||||
#define __ac_fsize(m) ((m) < 16? 1 : (m)>>4)
|
||||
|
||||
#ifndef kroundup32
|
||||
#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
|
||||
#endif
|
||||
|
||||
#ifndef kcalloc
|
||||
#define kcalloc(N,Z) calloc(N,Z)
|
||||
#endif
|
||||
#ifndef kmalloc
|
||||
#define kmalloc(Z) malloc(Z)
|
||||
#endif
|
||||
#ifndef krealloc
|
||||
#define krealloc(P,Z) realloc(P,Z)
|
||||
#endif
|
||||
#ifndef kfree
|
||||
#define kfree(P) free(P)
|
||||
#endif
|
||||
|
||||
static const double __ac_HASH_UPPER = 0.77;
|
||||
|
||||
#define __KHASH_TYPE(name, khkey_t, khval_t) \
|
||||
typedef struct kh_##name##_s { \
|
||||
khint_t n_buckets, size, n_occupied, upper_bound; \
|
||||
khint32_t *flags; \
|
||||
khkey_t *keys; \
|
||||
khval_t *vals; \
|
||||
} kh_##name##_t;
|
||||
|
||||
#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \
|
||||
extern kh_##name##_t *kh_init_##name(void); \
|
||||
extern void kh_destroy_##name(kh_##name##_t *h); \
|
||||
extern void kh_clear_##name(kh_##name##_t *h); \
|
||||
extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
|
||||
extern int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
|
||||
extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \
|
||||
extern void kh_del_##name(kh_##name##_t *h, khint_t x);
|
||||
|
||||
#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
|
||||
SCOPE kh_##name##_t *kh_init_##name(void) { \
|
||||
return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
|
||||
} \
|
||||
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
||||
{ \
|
||||
if (h) { \
|
||||
kfree((void *)h->keys); kfree(h->flags); \
|
||||
kfree((void *)h->vals); \
|
||||
kfree(h); \
|
||||
} \
|
||||
} \
|
||||
SCOPE void kh_clear_##name(kh_##name##_t *h) \
|
||||
{ \
|
||||
if (h && h->flags) { \
|
||||
memset(h->flags, 0xaa, __ac_fsize(h->n_buckets) * sizeof(khint32_t)); \
|
||||
h->size = h->n_occupied = 0; \
|
||||
} \
|
||||
} \
|
||||
SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
|
||||
{ \
|
||||
if (h->n_buckets) { \
|
||||
khint_t k, i, last, mask, step = 0; \
|
||||
mask = h->n_buckets - 1; \
|
||||
k = __hash_func(key); i = k & mask; \
|
||||
last = i; \
|
||||
while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \
|
||||
i = (i + (++step)) & mask; \
|
||||
if (i == last) return h->n_buckets; \
|
||||
} \
|
||||
return __ac_iseither(h->flags, i)? h->n_buckets : i; \
|
||||
} else return 0; \
|
||||
} \
|
||||
SCOPE int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
|
||||
{ /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \
|
||||
khint32_t *new_flags = 0; \
|
||||
khint_t j = 1; \
|
||||
{ \
|
||||
kroundup32(new_n_buckets); \
|
||||
if (new_n_buckets < 4) new_n_buckets = 4; \
|
||||
if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \
|
||||
else { /* hash table size to be changed (shrink or expand); rehash */ \
|
||||
new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
|
||||
if (!new_flags) return -1; \
|
||||
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
|
||||
if (h->n_buckets < new_n_buckets) { /* expand */ \
|
||||
khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
|
||||
if (!new_keys) { kfree(new_flags); return -1; } \
|
||||
h->keys = new_keys; \
|
||||
if (kh_is_map) { \
|
||||
khval_t *new_vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
|
||||
if (!new_vals) { kfree(new_flags); return -1; } \
|
||||
h->vals = new_vals; \
|
||||
} \
|
||||
} /* otherwise shrink */ \
|
||||
} \
|
||||
} \
|
||||
if (j) { /* rehashing is needed */ \
|
||||
for (j = 0; j != h->n_buckets; ++j) { \
|
||||
if (__ac_iseither(h->flags, j) == 0) { \
|
||||
khkey_t key = h->keys[j]; \
|
||||
khval_t val; \
|
||||
khint_t new_mask; \
|
||||
new_mask = new_n_buckets - 1; \
|
||||
if (kh_is_map) val = h->vals[j]; \
|
||||
__ac_set_isdel_true(h->flags, j); \
|
||||
while (1) { /* kick-out process; sort of like in Cuckoo hashing */ \
|
||||
khint_t k, i, step = 0; \
|
||||
k = __hash_func(key); \
|
||||
i = k & new_mask; \
|
||||
while (!__ac_isempty(new_flags, i)) i = (i + (++step)) & new_mask; \
|
||||
__ac_set_isempty_false(new_flags, i); \
|
||||
if (i < h->n_buckets && __ac_iseither(h->flags, i) == 0) { /* kick out the existing element */ \
|
||||
{ khkey_t tmp = h->keys[i]; h->keys[i] = key; key = tmp; } \
|
||||
if (kh_is_map) { khval_t tmp = h->vals[i]; h->vals[i] = val; val = tmp; } \
|
||||
__ac_set_isdel_true(h->flags, i); /* mark it as deleted in the old hash table */ \
|
||||
} else { /* write the element and jump out of the loop */ \
|
||||
h->keys[i] = key; \
|
||||
if (kh_is_map) h->vals[i] = val; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \
|
||||
h->keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
|
||||
if (kh_is_map) h->vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
|
||||
} \
|
||||
kfree(h->flags); /* free the working space */ \
|
||||
h->flags = new_flags; \
|
||||
h->n_buckets = new_n_buckets; \
|
||||
h->n_occupied = h->size; \
|
||||
h->upper_bound = (khint_t)(h->n_buckets * __ac_HASH_UPPER + 0.5); \
|
||||
} \
|
||||
return 0; \
|
||||
} \
|
||||
SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
|
||||
{ \
|
||||
khint_t x; \
|
||||
if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \
|
||||
if (h->n_buckets > (h->size<<1)) { \
|
||||
if (kh_resize_##name(h, h->n_buckets - 1) < 0) { /* clear "deleted" elements */ \
|
||||
*ret = -1; return h->n_buckets; \
|
||||
} \
|
||||
} else if (kh_resize_##name(h, h->n_buckets + 1) < 0) { /* expand the hash table */ \
|
||||
*ret = -1; return h->n_buckets; \
|
||||
} \
|
||||
} /* TODO: to implement automatically shrinking; resize() already support shrinking */ \
|
||||
{ \
|
||||
khint_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \
|
||||
x = site = h->n_buckets; k = __hash_func(key); i = k & mask; \
|
||||
if (__ac_isempty(h->flags, i)) x = i; /* for speed up */ \
|
||||
else { \
|
||||
last = i; \
|
||||
while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \
|
||||
if (__ac_isdel(h->flags, i)) site = i; \
|
||||
i = (i + (++step)) & mask; \
|
||||
if (i == last) { x = site; break; } \
|
||||
} \
|
||||
if (x == h->n_buckets) { \
|
||||
if (__ac_isempty(h->flags, i) && site != h->n_buckets) x = site; \
|
||||
else x = i; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
if (__ac_isempty(h->flags, x)) { /* not present at all */ \
|
||||
h->keys[x] = key; \
|
||||
__ac_set_isboth_false(h->flags, x); \
|
||||
++h->size; ++h->n_occupied; \
|
||||
*ret = 1; \
|
||||
} else if (__ac_isdel(h->flags, x)) { /* deleted */ \
|
||||
h->keys[x] = key; \
|
||||
__ac_set_isboth_false(h->flags, x); \
|
||||
++h->size; \
|
||||
*ret = 2; \
|
||||
} else *ret = 0; /* Don't touch h->keys[x] if present and not deleted */ \
|
||||
return x; \
|
||||
} \
|
||||
SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
|
||||
{ \
|
||||
if (x != h->n_buckets && !__ac_iseither(h->flags, x)) { \
|
||||
__ac_set_isdel_true(h->flags, x); \
|
||||
--h->size; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define KHASH_DECLARE(name, khkey_t, khval_t) \
|
||||
__KHASH_TYPE(name, khkey_t, khval_t) \
|
||||
__KHASH_PROTOTYPES(name, khkey_t, khval_t)
|
||||
|
||||
#define KHASH_INIT2(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
|
||||
__KHASH_TYPE(name, khkey_t, khval_t) \
|
||||
__KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
|
||||
|
||||
#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
|
||||
KHASH_INIT2(name, static kh_inline klib_unused, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
|
||||
|
||||
/* --- BEGIN OF HASH FUNCTIONS --- */
|
||||
|
||||
/*! @function
|
||||
@abstract Integer hash function
|
||||
@param key The integer [khint32_t]
|
||||
@return The hash value [khint_t]
|
||||
*/
|
||||
#define kh_int_hash_func(key) (khint32_t)(key)
|
||||
/*! @function
|
||||
@abstract Integer comparison function
|
||||
*/
|
||||
#define kh_int_hash_equal(a, b) ((a) == (b))
|
||||
/*! @function
|
||||
@abstract 64-bit integer hash function
|
||||
@param key The integer [khint64_t]
|
||||
@return The hash value [khint_t]
|
||||
*/
|
||||
#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11)
|
||||
/*! @function
|
||||
@abstract 64-bit integer comparison function
|
||||
*/
|
||||
#define kh_int64_hash_equal(a, b) ((a) == (b))
|
||||
/*! @function
|
||||
@abstract const char* hash function
|
||||
@param s Pointer to a null terminated string
|
||||
@return The hash value
|
||||
*/
|
||||
static kh_inline khint_t __ac_X31_hash_string(const char *s)
|
||||
{
|
||||
khint_t h = (khint_t)*s;
|
||||
if (h) for (++s ; *s; ++s) h = (h << 5) - h + (khint_t)*s;
|
||||
return h;
|
||||
}
|
||||
/*! @function
|
||||
@abstract Another interface to const char* hash function
|
||||
@param key Pointer to a null terminated string [const char*]
|
||||
@return The hash value [khint_t]
|
||||
*/
|
||||
#define kh_str_hash_func(key) __ac_X31_hash_string(key)
|
||||
/*! @function
|
||||
@abstract Const char* comparison function
|
||||
*/
|
||||
#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0)
|
||||
|
||||
static kh_inline khint_t __ac_Wang_hash(khint_t key)
|
||||
{
|
||||
key += ~(key << 15);
|
||||
key ^= (key >> 10);
|
||||
key += (key << 3);
|
||||
key ^= (key >> 6);
|
||||
key += ~(key << 11);
|
||||
key ^= (key >> 16);
|
||||
return key;
|
||||
}
|
||||
#define kh_int_hash_func2(k) __ac_Wang_hash((khint_t)key)
|
||||
|
||||
/* --- END OF HASH FUNCTIONS --- */
|
||||
|
||||
/* Other convenient macros... */
|
||||
|
||||
/*!
|
||||
@abstract Type of the hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
*/
|
||||
#define khash_t(name) kh_##name##_t
|
||||
|
||||
/*! @function
|
||||
@abstract Initiate a hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@return Pointer to the hash table [khash_t(name)*]
|
||||
*/
|
||||
#define kh_init(name) kh_init_##name()
|
||||
|
||||
/*! @function
|
||||
@abstract Destroy a hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
*/
|
||||
#define kh_destroy(name, h) kh_destroy_##name(h)
|
||||
|
||||
/*! @function
|
||||
@abstract Reset a hash table without deallocating memory.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
*/
|
||||
#define kh_clear(name, h) kh_clear_##name(h)
|
||||
|
||||
/*! @function
|
||||
@abstract Resize a hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param s New size [khint_t]
|
||||
*/
|
||||
#define kh_resize(name, h, s) kh_resize_##name(h, s)
|
||||
|
||||
/*! @function
|
||||
@abstract Insert a key to the hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param k Key [type of keys]
|
||||
@param r Extra return code: -1 if the operation failed;
|
||||
0 if the key is present in the hash table;
|
||||
1 if the bucket is empty (never used); 2 if the element in
|
||||
the bucket has been deleted [int*]
|
||||
@return Iterator to the inserted element [khint_t]
|
||||
*/
|
||||
#define kh_put(name, h, k, r) kh_put_##name(h, k, r)
|
||||
|
||||
/*! @function
|
||||
@abstract Retrieve a key from the hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param k Key [type of keys]
|
||||
@return Iterator to the found element, or kh_end(h) if the element is absent [khint_t]
|
||||
*/
|
||||
#define kh_get(name, h, k) kh_get_##name(h, k)
|
||||
|
||||
/*! @function
|
||||
@abstract Remove a key from the hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param k Iterator to the element to be deleted [khint_t]
|
||||
*/
|
||||
#define kh_del(name, h, k) kh_del_##name(h, k)
|
||||
|
||||
/*! @function
|
||||
@abstract Test whether a bucket contains data.
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param x Iterator to the bucket [khint_t]
|
||||
@return 1 if containing data; 0 otherwise [int]
|
||||
*/
|
||||
#define kh_exist(h, x) (!__ac_iseither((h)->flags, (x)))
|
||||
|
||||
/*! @function
|
||||
@abstract Get key given an iterator
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param x Iterator to the bucket [khint_t]
|
||||
@return Key [type of keys]
|
||||
*/
|
||||
#define kh_key(h, x) ((h)->keys[x])
|
||||
|
||||
/*! @function
|
||||
@abstract Get value given an iterator
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param x Iterator to the bucket [khint_t]
|
||||
@return Value [type of values]
|
||||
@discussion For hash sets, calling this results in segfault.
|
||||
*/
|
||||
#define kh_val(h, x) ((h)->vals[x])
|
||||
|
||||
/*! @function
|
||||
@abstract Alias of kh_val()
|
||||
*/
|
||||
#define kh_value(h, x) ((h)->vals[x])
|
||||
|
||||
/*! @function
|
||||
@abstract Get the start iterator
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@return The start iterator [khint_t]
|
||||
*/
|
||||
#define kh_begin(h) (khint_t)(0)
|
||||
|
||||
/*! @function
|
||||
@abstract Get the end iterator
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@return The end iterator [khint_t]
|
||||
*/
|
||||
#define kh_end(h) ((h)->n_buckets)
|
||||
|
||||
/*! @function
|
||||
@abstract Get the number of elements in the hash table
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@return Number of elements in the hash table [khint_t]
|
||||
*/
|
||||
#define kh_size(h) ((h)->size)
|
||||
|
||||
/*! @function
|
||||
@abstract Get the number of buckets in the hash table
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@return Number of buckets in the hash table [khint_t]
|
||||
*/
|
||||
#define kh_n_buckets(h) ((h)->n_buckets)
|
||||
|
||||
/*! @function
|
||||
@abstract Iterate over the entries in the hash table
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param kvar Variable to which key will be assigned
|
||||
@param vvar Variable to which value will be assigned
|
||||
@param code Block of code to execute
|
||||
*/
|
||||
#define kh_foreach(h, kvar, vvar, code) { khint_t __i; \
|
||||
for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \
|
||||
if (!kh_exist(h,__i)) continue; \
|
||||
(kvar) = kh_key(h,__i); \
|
||||
(vvar) = kh_val(h,__i); \
|
||||
code; \
|
||||
} }
|
||||
|
||||
/*! @function
|
||||
@abstract Iterate over the values in the hash table
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param vvar Variable to which value will be assigned
|
||||
@param code Block of code to execute
|
||||
*/
|
||||
#define kh_foreach_value(h, vvar, code) { khint_t __i; \
|
||||
for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \
|
||||
if (!kh_exist(h,__i)) continue; \
|
||||
(vvar) = kh_val(h,__i); \
|
||||
code; \
|
||||
} }
|
||||
|
||||
/* More conenient interfaces */
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash set containing integer keys
|
||||
@param name Name of the hash table [symbol]
|
||||
*/
|
||||
#define KHASH_SET_INIT_INT(name) \
|
||||
KHASH_INIT(name, khint32_t, char, 0, kh_int_hash_func, kh_int_hash_equal)
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing integer keys
|
||||
@param name Name of the hash table [symbol]
|
||||
@param khval_t Type of values [type]
|
||||
*/
|
||||
#define KHASH_MAP_INIT_INT(name, khval_t) \
|
||||
KHASH_INIT(name, khint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal)
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing 64-bit integer keys
|
||||
@param name Name of the hash table [symbol]
|
||||
*/
|
||||
#define KHASH_SET_INIT_INT64(name) \
|
||||
KHASH_INIT(name, khint64_t, char, 0, kh_int64_hash_func, kh_int64_hash_equal)
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing 64-bit integer keys
|
||||
@param name Name of the hash table [symbol]
|
||||
@param khval_t Type of values [type]
|
||||
*/
|
||||
#define KHASH_MAP_INIT_INT64(name, khval_t) \
|
||||
KHASH_INIT(name, khint64_t, khval_t, 1, kh_int64_hash_func, kh_int64_hash_equal)
|
||||
|
||||
typedef const char *kh_cstr_t;
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing const char* keys
|
||||
@param name Name of the hash table [symbol]
|
||||
*/
|
||||
#define KHASH_SET_INIT_STR(name) \
|
||||
KHASH_INIT(name, kh_cstr_t, char, 0, kh_str_hash_func, kh_str_hash_equal)
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing const char* keys
|
||||
@param name Name of the hash table [symbol]
|
||||
@param khval_t Type of values [type]
|
||||
*/
|
||||
#define KHASH_MAP_INIT_STR(name, khval_t) \
|
||||
KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal)
|
||||
|
||||
#endif /* __AC_KHASH_H */
|
||||
442
include/seiscomp/broker/utils/utils.h
Normal file
442
include/seiscomp/broker/utils/utils.h
Normal file
@@ -0,0 +1,442 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* Author: Jan Becker *
|
||||
* Email: jabe@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 GEMPA_MESSAGESERVER_UTILS_H__
|
||||
#define GEMPA_MESSAGESERVER_UTILS_H__
|
||||
|
||||
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
#include <seiscomp/broker/api.h>
|
||||
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <type_traits>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Utils {
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Randomizer class generated random data of arbitrary length.
|
||||
*
|
||||
* This class utilized /dev/urandom under Unix. Other operating systems are
|
||||
* not yet supported. Randomizer is implemented as a singleton. The usage
|
||||
* is as simple as:
|
||||
*
|
||||
* \code
|
||||
* if ( !Randomizer::Instance().fillData(data, len) )
|
||||
* cerr << "Failed to generate random data" << endl;
|
||||
* \endcode
|
||||
*
|
||||
* A helper template method Randomizer::fill is provided which takes an
|
||||
* argument of arbitrary type and fills it with random data.
|
||||
*
|
||||
* \code
|
||||
* int id;
|
||||
* if ( !Randomizer::Instance().fill(id) )
|
||||
* cerr << "Failed to generate id" << endl;
|
||||
* \endcode
|
||||
*/
|
||||
class SC_BROKER_API Randomizer {
|
||||
// ----------------------------------------------------------------------
|
||||
// Destruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! D'tor
|
||||
~Randomizer();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief Returns the singleton instance.
|
||||
* @return The singleton instance
|
||||
*/
|
||||
static Randomizer &Instance() { return _instance; }
|
||||
|
||||
/**
|
||||
* @brief Fills a value with random data.
|
||||
* @param target The value to be filled.
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
template <typename T>
|
||||
bool fill(T &target);
|
||||
|
||||
/**
|
||||
* @brief Fills a block of data with random data
|
||||
* @param data The pointer to the memory block
|
||||
* @param len The length in bytes of the memory block
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool fillData(void *data, size_t len);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
//! Private constructor
|
||||
Randomizer();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
static Randomizer _instance;
|
||||
FILE *_randomFd;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool Randomizer::fill(T &target) {
|
||||
return fillData(&target, sizeof(target));
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
class BlockingDequeue : private boost::noncopyable {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
typedef std::unique_lock<std::mutex> lock;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
BlockingDequeue();
|
||||
BlockingDequeue(int n);
|
||||
~BlockingDequeue();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Blocking interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
void resize(int n);
|
||||
|
||||
bool canPush() const;
|
||||
bool push(T v);
|
||||
|
||||
bool canPop() const;
|
||||
T pop();
|
||||
|
||||
bool pop(T &);
|
||||
|
||||
void close();
|
||||
void reopen();
|
||||
|
||||
size_t size() const;
|
||||
|
||||
void lockBuffer();
|
||||
void unlockBuffer();
|
||||
|
||||
//! Requires lockBuffer to be called
|
||||
size_t buffered() const;
|
||||
|
||||
//! Requires lockBuffer to be called
|
||||
T &operator[](size_t idx);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
volatile int _begin, _end;
|
||||
volatile size_t _buffered;
|
||||
volatile bool _closed;
|
||||
std::vector<T> _buffer;
|
||||
std::condition_variable _notFull, _notEmpty;
|
||||
mutable std::mutex _monitor;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename T, int IsPtr>
|
||||
struct BlockingDequeueHelper {};
|
||||
|
||||
template <typename T>
|
||||
struct BlockingDequeueHelper<T,0> {
|
||||
static void clean(const std::vector<T> &) {}
|
||||
static T defaultValue() { return T(); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct BlockingDequeueHelper<T,1> {
|
||||
static void clean(const std::vector<T> &b) {
|
||||
for ( size_t i = 0; i < b.size(); ++i ) {
|
||||
if ( b[i] ) delete b[i];
|
||||
}
|
||||
}
|
||||
|
||||
static T defaultValue() { return NULL; }
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
BlockingDequeue<T>::BlockingDequeue() :
|
||||
_begin(0), _end(0),
|
||||
_buffered(0), _closed(false), _buffer(0)
|
||||
{}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
BlockingDequeue<T>::BlockingDequeue(int n) :
|
||||
_begin(0), _end(0),
|
||||
_buffered(0), _closed(false), _buffer(n)
|
||||
{}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
BlockingDequeue<T>::~BlockingDequeue() {
|
||||
close();
|
||||
BlockingDequeueHelper<T, std::is_pointer<T>::value>::clean(_buffer);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void BlockingDequeue<T>::resize(int n) {
|
||||
lock lk(_monitor);
|
||||
_buffer.resize(n);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool BlockingDequeue<T>::canPush() const {
|
||||
lock lk(_monitor);
|
||||
|
||||
if ( _closed )
|
||||
throw Core::GeneralException("Queue has been closed");
|
||||
|
||||
return _buffered < _buffer.size();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool BlockingDequeue<T>::push(T v) {
|
||||
lock lk(_monitor);
|
||||
while (_buffered == _buffer.size() && !_closed)
|
||||
_notFull.wait(lk);
|
||||
if ( _closed ) {
|
||||
_notEmpty.notify_all();
|
||||
return false;
|
||||
}
|
||||
_buffer[_end] = v;
|
||||
_end = (_end+1) % _buffer.size();
|
||||
++_buffered;
|
||||
_notEmpty.notify_all();
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool BlockingDequeue<T>::canPop() const {
|
||||
lock lk(_monitor);
|
||||
|
||||
if ( _closed )
|
||||
throw Core::GeneralException("Queue has been closed");
|
||||
|
||||
return _buffered > 0;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
T BlockingDequeue<T>::pop() {
|
||||
lock lk(_monitor);
|
||||
while (_buffered == 0 && !_closed) {
|
||||
_notEmpty.wait(lk);
|
||||
}
|
||||
if ( _closed )
|
||||
throw Core::GeneralException("Queue has been closed");
|
||||
T v = _buffer[_begin];
|
||||
_buffer[_begin] = BlockingDequeueHelper<T, std::is_pointer<T>::value>::defaultValue();
|
||||
_begin = (_begin+1) % _buffer.size();
|
||||
--_buffered;
|
||||
_notFull.notify_all();
|
||||
return v;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool BlockingDequeue<T>::pop(T &v) {
|
||||
lock lk(_monitor);
|
||||
|
||||
if ( _closed )
|
||||
throw Core::GeneralException("Queue has been closed");
|
||||
|
||||
if ( _buffered > 0 ) {
|
||||
v = _buffer[_begin];
|
||||
_buffer[_begin] = BlockingDequeueHelper<T, std::is_pointer<T>::value>::defaultValue();
|
||||
_begin = (_begin+1) % _buffer.size();
|
||||
--_buffered;
|
||||
_notFull.notify_all();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void BlockingDequeue<T>::close() {
|
||||
lock lk(_monitor);
|
||||
if ( _closed ) return;
|
||||
_closed = true;
|
||||
_notFull.notify_all();
|
||||
_notEmpty.notify_all();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void BlockingDequeue<T>::reopen() {
|
||||
lock lk(_monitor);
|
||||
_closed = false;
|
||||
if ( !_buffered )
|
||||
_notFull.notify_all();
|
||||
else
|
||||
_notEmpty.notify_all();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
size_t BlockingDequeue<T>::size() const {
|
||||
lock lk(_monitor);
|
||||
return _buffered;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void BlockingDequeue<T>::lockBuffer() {
|
||||
_monitor.lock();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void BlockingDequeue<T>::unlockBuffer() {
|
||||
_monitor.unlock();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
size_t BlockingDequeue<T>::buffered() const {
|
||||
return _buffered;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
T &BlockingDequeue<T>::operator[](size_t idx) {
|
||||
idx += _begin;
|
||||
if ( idx >= _buffer.size() )
|
||||
idx -= _buffer.size();
|
||||
|
||||
return _buffer[idx];
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
17
include/seiscomp/client.h
Normal file
17
include/seiscomp/client.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SC_SYSTEM_CLIENT_API_H
|
||||
#define SC_SYSTEM_CLIENT_API_H
|
||||
|
||||
#if defined(WIN32) && (defined(SC_SYSTEM_CLIENT_SHARED) || defined(SC_ALL_SHARED))
|
||||
# if defined(SC_SYSTEM_CLIENT_EXPORTS)
|
||||
# define SC_SYSTEM_CLIENT_API __declspec(dllexport)
|
||||
# define SC_SYSTEM_CLIENT_TEMPLATE_EXPORT
|
||||
# else
|
||||
# define SC_SYSTEM_CLIENT_API __declspec(dllimport)
|
||||
# define SC_SYSTEM_CLIENT_TEMPLATE_EXPORT extern
|
||||
# endif
|
||||
#else
|
||||
# define SC_SYSTEM_CLIENT_API
|
||||
# define SC_SYSTEM_CLIENT_TEMPLATE_EXPORT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
780
include/seiscomp/client/application.h
Normal file
780
include/seiscomp/client/application.h
Normal file
@@ -0,0 +1,780 @@
|
||||
/***************************************************************************
|
||||
* 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_CLIENT_APPLICATION_H
|
||||
#define SEISCOMP_CLIENT_APPLICATION_H
|
||||
|
||||
|
||||
#include <seiscomp/system/application.h>
|
||||
|
||||
#include <seiscomp/core/message.h>
|
||||
|
||||
#include <seiscomp/client/queue.h>
|
||||
#include <seiscomp/client/monitor.h>
|
||||
#include <seiscomp/client/inventory.h>
|
||||
#include <seiscomp/client.h>
|
||||
|
||||
#include <seiscomp/datamodel/databasequery.h>
|
||||
#include <seiscomp/datamodel/notifier.h>
|
||||
#include <seiscomp/datamodel/configmodule.h>
|
||||
|
||||
#include <seiscomp/math/coord.h>
|
||||
|
||||
#include <seiscomp/messaging/connection.h>
|
||||
|
||||
#include <seiscomp/utils/timer.h>
|
||||
#include <seiscomp/utils/stringfirewall.h>
|
||||
|
||||
#include <set>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
#define SCCoreApp (Seiscomp::Client::Application::Instance())
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
namespace Logging {
|
||||
class Output;
|
||||
}
|
||||
|
||||
namespace Client {
|
||||
|
||||
|
||||
MAKEENUM(
|
||||
ApplicationStatus,
|
||||
EVALUES(
|
||||
STARTED,
|
||||
FINISHED
|
||||
),
|
||||
ENAMES(
|
||||
"started",
|
||||
"finished"
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
class SC_SYSTEM_CLIENT_API ApplicationStatusMessage : public Core::Message {
|
||||
DECLARE_SC_CLASS(ApplicationStatusMessage);
|
||||
DECLARE_SERIALIZATION;
|
||||
|
||||
public:
|
||||
ApplicationStatusMessage();
|
||||
ApplicationStatusMessage(const std::string &module,
|
||||
ApplicationStatus status);
|
||||
|
||||
ApplicationStatusMessage(const std::string &module,
|
||||
const std::string &username,
|
||||
ApplicationStatus status);
|
||||
|
||||
|
||||
public:
|
||||
virtual bool empty() const;
|
||||
|
||||
const std::string &module() const;
|
||||
const std::string &username() const;
|
||||
ApplicationStatus status() const;
|
||||
|
||||
|
||||
private:
|
||||
std::string _module;
|
||||
std::string _username;
|
||||
ApplicationStatus _status;
|
||||
};
|
||||
|
||||
|
||||
struct SC_SYSTEM_CLIENT_API Notification {
|
||||
//! Declares the application internal notification types.
|
||||
//! Custom types can be used with negative values.
|
||||
enum Type {
|
||||
Object,
|
||||
Disconnect,
|
||||
Reconnect,
|
||||
Close,
|
||||
Timeout,
|
||||
AcquisitionFinished,
|
||||
StateOfHealth
|
||||
};
|
||||
|
||||
Notification() : object(nullptr), type(Object) {}
|
||||
Notification(Core::BaseObject * o) : object(o), type(Object) {}
|
||||
Notification(int t) : object(nullptr), type(t) {}
|
||||
Notification(int t, Core::BaseObject * o) : object(o), type(t) {}
|
||||
|
||||
Core::BaseObject *object;
|
||||
int type;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Application class to write commandline clients easily which are
|
||||
* connected to the messaging and need database access.
|
||||
*
|
||||
* In addition to @ref System::Application it adds the method
|
||||
* @ref handleMessage which must be implemented to handle receives
|
||||
* messages. An additional abstraction layer is implemented which already
|
||||
* checks the message for notifier objects, extracts them and calls respective
|
||||
* callbacks:
|
||||
* * @ref addObject()
|
||||
* * @ref removeObject()
|
||||
* * @ref updateObject()
|
||||
*/
|
||||
class SC_SYSTEM_CLIENT_API Application : public System::Application {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
typedef ObjectMonitor::Log ObjectLog;
|
||||
|
||||
//! Initialization stages used when reporting errors
|
||||
enum ClientStage {
|
||||
MESSAGING = System::Application::ST_QUANTITY,
|
||||
DATABASE = System::Application::ST_QUANTITY + 1,
|
||||
CONFIGMODULE = System::Application::ST_QUANTITY + 2,
|
||||
INVENTORY = System::Application::ST_QUANTITY + 3,
|
||||
CST_QUANTITY
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
Application(int argc, char **argv);
|
||||
~Application();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public functions
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the configured agencyID
|
||||
const std::string &agencyID() const;
|
||||
|
||||
//! Returns the configured author
|
||||
const std::string &author() const;
|
||||
|
||||
/**
|
||||
* Returns according to the configured white- and blacklist of
|
||||
* agencyID's whether the passed agencyID is allowed or not
|
||||
* @param agencyID The agencyID to check
|
||||
* @return The boolean result
|
||||
*/
|
||||
bool isAgencyIDAllowed(const std::string &agencyID) const;
|
||||
|
||||
/**
|
||||
* Returns !isAgencyIDAllowed(agencyID)
|
||||
* @param agencyID The agencyID to check
|
||||
* @return !isAgencyIDAllowed(agencyID)
|
||||
*/
|
||||
bool isAgencyIDBlocked(const std::string &agencyID) const;
|
||||
|
||||
/**
|
||||
* Exit the application and set the returnCode.
|
||||
* @param returnCode The value returned from exec()
|
||||
*/
|
||||
virtual void exit(int returnCode);
|
||||
|
||||
//! Returns the application's messaging connection interface
|
||||
Client::Connection *connection() const;
|
||||
|
||||
//! Returns the configured database type
|
||||
const std::string &databaseType() const;
|
||||
|
||||
//! Returns the configured database connection parameters
|
||||
const std::string &databaseParameters() const;
|
||||
|
||||
//! Returns the application's database interface
|
||||
IO::DatabaseInterface *database() const;
|
||||
|
||||
void setDatabaseURI(const std::string &uri);
|
||||
//! Returns the application's database URI
|
||||
const std::string &databaseURI() const;
|
||||
|
||||
//! Returns the application's database query interface
|
||||
DataModel::DatabaseQuery *query() const;
|
||||
|
||||
void setRecordStreamURL(const std::string &url);
|
||||
//! Returns the configures recordstream URL to be used by
|
||||
//! RecordStream::Open()
|
||||
const std::string &recordStreamURL() const;
|
||||
|
||||
//! Returns the list of configured points of interest
|
||||
const std::vector<Math::Geo::CityD> &cities() const;
|
||||
|
||||
//! Returns the nearest city with respect to lat/lon and
|
||||
//! a given maximum distance and minimum population
|
||||
const Math::Geo::CityD *nearestCity(double lat, double lon,
|
||||
double maxDist, double minPopulation,
|
||||
double *dist, double *azi) const;
|
||||
|
||||
//! Returns the config module object if available
|
||||
DataModel::ConfigModule *configModule() const;
|
||||
|
||||
//! Returns the state of a station
|
||||
bool isStationEnabled(const std::string& networkCode,
|
||||
const std::string& stationCode);
|
||||
|
||||
//! Returns the messaging-server
|
||||
const std::string &messagingURL() const;
|
||||
|
||||
|
||||
//! Returns the filename of the OpenSSL certificate or
|
||||
//! the certificate data Base64 encoded. The Base64 encoded
|
||||
//! data starts with the special DataTag.
|
||||
//! If no certificate is used the method returns an empty
|
||||
//! string.
|
||||
const std::string &messagingCertificate() const;
|
||||
|
||||
//! Enables a timer that calls every n seconds the
|
||||
//! handleTimeout() methods
|
||||
//! A value of 0 seconds disables the timer
|
||||
void enableTimer(unsigned int seconds);
|
||||
|
||||
//! Disables the timer
|
||||
void disableTimer();
|
||||
|
||||
//! Sends a notification to the application. If used in derived
|
||||
//! classes to send custom notifications use negative notification
|
||||
//! types and reimplement dispatchNotification(...).
|
||||
void sendNotification(const Notification &);
|
||||
|
||||
bool waitEvent();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Initialization configuration methods
|
||||
// These methods have to be called before the init() method.
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Sets the primary messaging group
|
||||
void setPrimaryMessagingGroup(const std::string&);
|
||||
|
||||
//! Returns the set primary messaging group
|
||||
const std::string &primaryMessagingGroup() const;
|
||||
|
||||
//! Sets the username used for the messaging connection
|
||||
void setMessagingUsername(const std::string&);
|
||||
|
||||
/**
|
||||
* Adds a group to subscribe to. This is only a default group.
|
||||
* If another group or groups are given via commandline or config
|
||||
* file this subscription will be overriden completely.
|
||||
*/
|
||||
void addMessagingSubscription(const std::string&);
|
||||
|
||||
//! Initialize the database, default = true, true
|
||||
void setDatabaseEnabled(bool enable, bool tryToFetch);
|
||||
bool isDatabaseEnabled() const;
|
||||
|
||||
//! Returns whether the inventory should be loaded from a
|
||||
//! file (false) or from the database (true)
|
||||
bool isInventoryDatabaseEnabled() const;
|
||||
|
||||
//! Returns whether the config module should be loaded from a
|
||||
//! file (false) or from the database (true)
|
||||
bool isConfigDatabaseEnabled() const;
|
||||
|
||||
//! Initialize the messaging, default = true
|
||||
void setMessagingEnabled(bool enable);
|
||||
bool isMessagingEnabled() const;
|
||||
|
||||
/**
|
||||
* @brief Toggles receiption of messaging membership messages. The
|
||||
* default is false.
|
||||
* @param enable Flag
|
||||
*/
|
||||
void setMembershipMessagesEnabled(bool enable);
|
||||
bool areMembershipMessagesEnabled() const;
|
||||
|
||||
//! Enables/disables sending of start/stop messages.
|
||||
//! If enabled, a start message (at startup) and a
|
||||
//! stop message (at shutdown) will be sent to the
|
||||
//! STATUS group. Default = false
|
||||
void setStartStopMessagesEnabled(bool enable);
|
||||
bool areStartStopMessagesEnabled() const;
|
||||
|
||||
//! Enables/disables auto shutdown caused by
|
||||
//! the shutdown of a definable master module or
|
||||
//! master username. If both values are set the
|
||||
//! one coming first is used.
|
||||
void setAutoShutdownEnabled(bool enable);
|
||||
bool isAutoShutdownEnabled() const;
|
||||
|
||||
//! Enables recordstream URL option, default = true
|
||||
void setRecordStreamEnabled(bool enable);
|
||||
bool isRecordStreamEnabled() const;
|
||||
|
||||
//! Load the stations from the inventory at startup, default = false
|
||||
void setLoadStationsEnabled(bool enable);
|
||||
bool isLoadStationsEnabled() const;
|
||||
|
||||
//! Load the complete inventory at startup, default = false
|
||||
void setLoadInventoryEnabled(bool enable);
|
||||
bool isLoadInventoryEnabled() const;
|
||||
|
||||
//! Load the configmodule from the database at startup, default = false
|
||||
void setLoadConfigModuleEnabled(bool enable);
|
||||
bool isLoadConfigModuleEnabled() const;
|
||||
|
||||
//! Load the cities.xml file, default = false
|
||||
void setLoadCitiesEnabled(bool enable);
|
||||
bool isLoadCitiesEnabled() const;
|
||||
|
||||
//! Load the custom defined fep regions in ~/.seiscomp/fep or
|
||||
//! ~/seiscomp/trunk/share/fep, default = false
|
||||
void setLoadRegionsEnabled(bool enable);
|
||||
bool isLoadRegionsEnabled() const;
|
||||
|
||||
//! Sets whether the received notifier are applied automatically
|
||||
//! or not, default: true
|
||||
|
||||
/**
|
||||
* Sets whether the received notifier are applied automatically
|
||||
* or not, default: true
|
||||
* When AutoApplyNotifier is enabled a received message will
|
||||
* be handled in two passes:
|
||||
* 1. pass: Apply all attached notifier
|
||||
* 2. pass: Interpret all notifier
|
||||
*
|
||||
* So when using an object in an interprete callback it is
|
||||
* garantueed that all child objects that also has been sent
|
||||
* inside the message are attached to it.
|
||||
*/
|
||||
void setAutoApplyNotifierEnabled(bool enable);
|
||||
bool isAutoApplyNotifierEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets whether the received notifier will be interpreted or not.
|
||||
* Default: true
|
||||
* When this option is enabled, the callback methods
|
||||
* addObject(), updateObject() and removeObject() will be
|
||||
* called after a notifier has been received.
|
||||
*/
|
||||
void setInterpretNotifierEnabled(bool enable);
|
||||
bool isInterpretNotifierEnabled() const;
|
||||
|
||||
/** Returns whether a custom publicID pattern has been configured
|
||||
or not */
|
||||
bool hasCustomPublicIDPattern() const;
|
||||
|
||||
/**
|
||||
* Sets the number of retries if a connection fails.
|
||||
* The default value is 0xFFFFFFFF and should be understood
|
||||
* as "keep on trying".
|
||||
*/
|
||||
void setConnectionRetries(unsigned int);
|
||||
|
||||
//! Sets the config module name to use when reading
|
||||
//! the database configuration. An empty module name
|
||||
//! means: read all available modules.
|
||||
//! The default module is "trunk".
|
||||
void setConfigModuleName(const std::string &module);
|
||||
const std::string &configModuleName() const;
|
||||
|
||||
//! Sets the master module used when auto shutdown
|
||||
//! is activated.
|
||||
void setShutdownMasterModule(const std::string &module);
|
||||
|
||||
//! Sets the master username used when auto shutdown
|
||||
//! is activated.
|
||||
void setShutdownMasterUsername(const std::string &username);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public methods
|
||||
// These methods have to be called after the init() method.
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Adds a logger for an input object flow.
|
||||
* This method must be called after Application::init().
|
||||
* The returned pointer is managed by the Application and must not
|
||||
* be deleted.
|
||||
*/
|
||||
ObjectLog *
|
||||
addInputObjectLog(const std::string &name,
|
||||
const std::string &channel = "");
|
||||
|
||||
/**
|
||||
* Adds a logger for an output object flow.
|
||||
* This method must be called after Application::init().
|
||||
* The returned pointer is managed by the Application and must not
|
||||
* be deleted.
|
||||
*/
|
||||
ObjectLog *
|
||||
addOutputObjectLog(const std::string &name,
|
||||
const std::string &channel = "");
|
||||
|
||||
/**
|
||||
* Logs input/output object throughput.
|
||||
* @param log Pointer returned by addInputObjectLog or addOutputObjectLog
|
||||
* @param timestamp The timestamp to be logged
|
||||
*/
|
||||
void logObject(ObjectLog *log, const Core::Time ×tamp,
|
||||
size_t count = 1);
|
||||
|
||||
/**
|
||||
* Reloads the application inventory from either an XML file or
|
||||
* the database.
|
||||
*/
|
||||
bool reloadInventory();
|
||||
|
||||
/**
|
||||
* Reloads the application configuration (bindings) from either an
|
||||
* XML file or the database.
|
||||
*/
|
||||
bool reloadBindings();
|
||||
|
||||
/**
|
||||
* @brief Injects a message from outside. The message will actually
|
||||
* take the same path as when it would have been received via
|
||||
* the messaging.
|
||||
* @param msg The message. The ownership if left to the caller.
|
||||
* @param pkt The optional network packet. The ownership is left to
|
||||
* the caller.
|
||||
*/
|
||||
void injectMessage(Core::Message *msg, Packet *pkt = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Routes a notifier to either add/update or removeObject.
|
||||
* @param notifier The notifier pointer which must not be nullptr
|
||||
*/
|
||||
void handleNotifier(DataModel::Notifier *notifier);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Static public members
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the pointer to the application's instance.
|
||||
static Application *Instance();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected functions
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
virtual bool validateParameters() override;
|
||||
virtual bool handlePreFork() override;
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
/**
|
||||
* Starts the mainloop until exit() or quit() is called.
|
||||
* The default implementation waits for messages in blocking mode
|
||||
* and calls handleMessage() whenever a new message arrives.
|
||||
*/
|
||||
virtual bool run() override;
|
||||
|
||||
//! This method gets called when all messages has been read or
|
||||
//! the connection is invalid
|
||||
virtual void idle();
|
||||
|
||||
//! Cleanup method called before exec() returns.
|
||||
virtual void done() override;
|
||||
|
||||
//! Opens the configuration file and reads the state variables
|
||||
virtual bool initConfiguration() override;
|
||||
|
||||
//! Initialized the database
|
||||
virtual bool initDatabase();
|
||||
|
||||
//! Sets the database interface and creates a database query object
|
||||
void setDatabase(IO::DatabaseInterface* db);
|
||||
|
||||
/**
|
||||
* Reads the requested subscriptions from the configuration file
|
||||
* and apply them to the messaging connection.
|
||||
*/
|
||||
virtual bool initSubscriptions();
|
||||
|
||||
const std::set<std::string> &subscribedGroups() const;
|
||||
|
||||
/**
|
||||
* Called when the application received the AcquisitionFinished event.
|
||||
* This is most likely send from the readRecords thread of the
|
||||
* StreamApplication. The default implementation does nothing.
|
||||
*/
|
||||
virtual void handleEndAcquisition();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Messaging handlers
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
virtual bool dispatch(Core::BaseObject*);
|
||||
|
||||
//! Custom dispatch method for notifications with negative (< 0)
|
||||
//! types. The default implementation return false.
|
||||
virtual bool dispatchNotification(int type, Core::BaseObject*);
|
||||
|
||||
/**
|
||||
* Reads messages from the connection.
|
||||
* @return true, if successfull, false if not. When returning false,
|
||||
* the mainloop will stop and the program is going to
|
||||
* terminate.
|
||||
*/
|
||||
bool readMessages();
|
||||
|
||||
void stateOfHealth();
|
||||
|
||||
/**
|
||||
* This method gets called when a previously started timer timeout's.
|
||||
* The timer has to be started by enableTimer(timeout).
|
||||
*/
|
||||
virtual void handleTimeout();
|
||||
|
||||
/**
|
||||
* This method is called when close event is sent to the application.
|
||||
* The default handler returns true and causes the event queue to
|
||||
* shutdown and to exit the application.
|
||||
* It false is returned the close event is ignored.
|
||||
*/
|
||||
virtual bool handleClose();
|
||||
|
||||
/**
|
||||
* This methods gets called when an auto shutdown has been
|
||||
* initiated. The default implementation just quits.
|
||||
*/
|
||||
virtual void handleAutoShutdown();
|
||||
|
||||
/**
|
||||
* This methods gets called when an the log interval is reached
|
||||
* and the application should prepare its logging information. This
|
||||
* method can be used to sync logs.
|
||||
* The default implementation does nothing.
|
||||
*/
|
||||
virtual void handleMonitorLog(const Core::Time ×tamp);
|
||||
|
||||
/**
|
||||
* This method gets called after the connection got lost.
|
||||
*/
|
||||
virtual void handleDisconnect();
|
||||
|
||||
/**
|
||||
* This method gets called after the connection got reestablished.
|
||||
*/
|
||||
virtual void handleReconnect();
|
||||
|
||||
/**
|
||||
* Handles receiption of a network packet which is a candidate
|
||||
* for message decoding. Special service messages such as ENTER or
|
||||
* LEAVE will not cause a message to be created. This method is always
|
||||
* called *before* a message should be handled.
|
||||
*/
|
||||
virtual void handleNetworkMessage(const Client::Packet *msg);
|
||||
|
||||
/**
|
||||
* This method gets called whenever a new message arrives. Derived
|
||||
* classes have to implement this method to receive messages.
|
||||
* To enable autoapplying and notifier interpreting call this method
|
||||
* inside the reimplemented version.
|
||||
* @param msg The message. A smartpointer may be stored for
|
||||
* future use. The pointer must not be deleted!
|
||||
*/
|
||||
virtual void handleMessage(Core::Message *msg);
|
||||
|
||||
//! Callback for interpret notifier
|
||||
virtual void addObject(const std::string &parentID, DataModel::Object*) {}
|
||||
|
||||
//! Callback for interpret notifier
|
||||
virtual void removeObject(const std::string &parentID, DataModel::Object*) {}
|
||||
|
||||
//! Callback for interpret notifier
|
||||
virtual void updateObject(const std::string &parentID, DataModel::Object*) {}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private functions
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
bool initMessaging();
|
||||
|
||||
bool loadConfig(const std::string &configDB);
|
||||
bool loadInventory(const std::string &inventoryDB);
|
||||
|
||||
void startMessageThread();
|
||||
void runMessageThread();
|
||||
|
||||
bool processEvent();
|
||||
|
||||
void timeout();
|
||||
void stateOfHealthTimeout();
|
||||
|
||||
void monitorLog(const Core::Time ×tamp, std::ostream &os);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
DataModel::DatabaseQueryPtr _query;
|
||||
DataModel::ConfigModulePtr _configModule;
|
||||
|
||||
std::vector<Math::Geo::CityD> _cities;
|
||||
std::set<std::string> _messagingSubscriptions;
|
||||
|
||||
|
||||
private:
|
||||
static Application *_instance;
|
||||
|
||||
|
||||
protected:
|
||||
using StringVector = std::vector<std::string>;
|
||||
|
||||
struct AppSettings : AbstractSettings {
|
||||
int objectLogTimeWindow{60};
|
||||
|
||||
std::string agencyID{"UNSET"};
|
||||
std::string author{"@appname@@@@hostname@"};
|
||||
|
||||
bool enableLoadRegions{false};
|
||||
std::string customPublicIDPattern;
|
||||
std::string configModuleName{"trunk"};
|
||||
|
||||
bool enableFetchDatabase{true};
|
||||
bool enableLoadStations{false};
|
||||
bool enableLoadInventory{false};
|
||||
bool enableLoadConfigModule{false};
|
||||
bool enableAutoApplyNotifier{true};
|
||||
bool enableInterpretNotifier{true};
|
||||
|
||||
unsigned int retryCount{0xFFFFFFFF};
|
||||
|
||||
Util::StringFirewall networkTypeFirewall;
|
||||
Util::StringFirewall stationTypeFirewall;
|
||||
|
||||
struct SOH {
|
||||
void accept(SettingsLinker &linker);
|
||||
|
||||
int interval{60};
|
||||
} soh;
|
||||
|
||||
struct Database {
|
||||
void accept(SettingsLinker &linker);
|
||||
|
||||
bool enable{true};
|
||||
bool showDrivers{false};
|
||||
|
||||
std::string type;
|
||||
std::string parameters;
|
||||
std::string URI;
|
||||
|
||||
std::string inventoryDB;
|
||||
std::string configDB;
|
||||
} database;
|
||||
|
||||
struct Inventory {
|
||||
void accept(SettingsLinker &linker);
|
||||
|
||||
StringVector netTypeAllowlist;
|
||||
StringVector netTypeBlocklist;
|
||||
StringVector staTypeAllowlist;
|
||||
StringVector staTypeBlocklist;
|
||||
} inventory;
|
||||
|
||||
// Messaging
|
||||
struct Messaging {
|
||||
void accept(SettingsLinker &linker);
|
||||
|
||||
bool enable{true};
|
||||
bool membershipMessages{false};
|
||||
|
||||
std::string user;
|
||||
std::string URL{"localhost/production"};
|
||||
std::string primaryGroup{Protocol::LISTENER_GROUP};
|
||||
std::string contentType;
|
||||
unsigned int timeout{3};
|
||||
std::string certificate;
|
||||
|
||||
StringVector subscriptions;
|
||||
|
||||
} messaging;
|
||||
|
||||
struct Client {
|
||||
void accept(SettingsLinker &linker);
|
||||
|
||||
bool startStopMessages{false};
|
||||
bool autoShutdown{false};
|
||||
std::string shutdownMasterModule;
|
||||
std::string shutdownMasterUsername;
|
||||
} client;
|
||||
|
||||
struct RecordStream {
|
||||
void accept(SettingsLinker &linker);
|
||||
|
||||
bool enable{false};
|
||||
bool showDrivers{false};
|
||||
|
||||
std::string URI;
|
||||
std::string file;
|
||||
std::string fileType;
|
||||
} recordstream;
|
||||
|
||||
struct Processing {
|
||||
void accept(SettingsLinker &linker);
|
||||
|
||||
StringVector agencyAllowlist;
|
||||
StringVector agencyBlocklist;
|
||||
Util::StringFirewall firewall;
|
||||
StringVector magnitudeAliases;
|
||||
|
||||
} processing;
|
||||
|
||||
struct Cities {
|
||||
void accept(SettingsLinker &linker);
|
||||
|
||||
bool enable{false};
|
||||
std::string db;
|
||||
} cities;
|
||||
|
||||
void accept(SettingsLinker &linker) override;
|
||||
};
|
||||
|
||||
AppSettings _settings;
|
||||
|
||||
ObjectMonitor *_inputMonitor;
|
||||
ObjectMonitor *_outputMonitor;
|
||||
|
||||
ThreadedQueue<Notification> _queue;
|
||||
std::thread *_messageThread;
|
||||
|
||||
ConnectionPtr _connection;
|
||||
IO::DatabaseInterfacePtr _database;
|
||||
Util::Timer _userTimer;
|
||||
Util::Timer _sohTimer;
|
||||
Core::Time _sohLastUpdate;
|
||||
|
||||
std::mutex _objectLogMutex;
|
||||
};
|
||||
|
||||
|
||||
inline bool Application::waitEvent() {
|
||||
return processEvent();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
81
include/seiscomp/client/configdb.h
Normal file
81
include/seiscomp/client/configdb.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/***************************************************************************
|
||||
* 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_CLIENT_CONFIG_H
|
||||
#define SEISCOMP_CLIENT_CONFIG_H
|
||||
|
||||
|
||||
#include <seiscomp/datamodel/config.h>
|
||||
#include <seiscomp/datamodel/configmodule.h>
|
||||
#include <seiscomp/datamodel/configstation.h>
|
||||
#include <seiscomp/datamodel/parameterset.h>
|
||||
#include <seiscomp/datamodel/databasereader.h>
|
||||
#include <seiscomp/client.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Client {
|
||||
|
||||
|
||||
class SC_SYSTEM_CLIENT_API ConfigDB {
|
||||
private:
|
||||
ConfigDB();
|
||||
|
||||
public:
|
||||
static ConfigDB* Instance();
|
||||
static void Reset();
|
||||
|
||||
void load(DataModel::DatabaseReader* reader,
|
||||
const OPT(std::string)& moduleName = Seiscomp::Core::None,
|
||||
const OPT(std::string)& networkCode = Seiscomp::Core::None,
|
||||
const OPT(std::string)& stationCode = Seiscomp::Core::None,
|
||||
const OPT(std::string)& setupName = Seiscomp::Core::None,
|
||||
const std::set<std::string>& parameterNames = std::set<std::string>());
|
||||
|
||||
void load(const char *xml);
|
||||
|
||||
DataModel::Config *config();
|
||||
|
||||
private:
|
||||
std::map<int, DataModel::ConfigModulePtr> _configModules;
|
||||
std::map<int, DataModel::ConfigStationPtr> _configStations;
|
||||
std::map<int, DataModel::ParameterSetPtr> _parameterSets;
|
||||
DataModel::ConfigPtr _config;
|
||||
static ConfigDB *_instance;
|
||||
|
||||
DataModel::DatabaseIterator getConfigObjects(DataModel::DatabaseReader* reader,
|
||||
const Core::RTTI& classType,
|
||||
const OPT(std::string)& moduleName,
|
||||
const OPT(std::string)& networkCode,
|
||||
const OPT(std::string)& stationCode,
|
||||
const OPT(std::string)& setupName,
|
||||
const std::set<std::string>& parameterNames);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
156
include/seiscomp/client/inventory.h
Normal file
156
include/seiscomp/client/inventory.h
Normal file
@@ -0,0 +1,156 @@
|
||||
/***************************************************************************
|
||||
* 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_CLIENT_INVENTORY_H
|
||||
#define SEISCOMP_CLIENT_INVENTORY_H
|
||||
|
||||
|
||||
#include <seiscomp/datamodel/inventory.h>
|
||||
#include <seiscomp/datamodel/pick.h>
|
||||
#include <seiscomp/datamodel/databasereader.h>
|
||||
#include <seiscomp/datamodel/utils.h>
|
||||
#include <seiscomp/utils/stringfirewall.h>
|
||||
#include <seiscomp/client.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Client {
|
||||
|
||||
|
||||
struct SC_SYSTEM_CLIENT_API StationLocation {
|
||||
StationLocation();
|
||||
StationLocation(double lat, double lon, double elevation);
|
||||
|
||||
double latitude;
|
||||
double longitude;
|
||||
double elevation;
|
||||
};
|
||||
|
||||
|
||||
typedef std::vector<Seiscomp::DataModel::Station*> StationList;
|
||||
|
||||
class SC_SYSTEM_CLIENT_API Inventory {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
//! Private c'tor. This class implements the singleton pattern and
|
||||
//! can be accessed through the static Instance() method.
|
||||
Inventory();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
static Inventory* Instance();
|
||||
static void Reset();
|
||||
|
||||
void load(const char *filename);
|
||||
void load(DataModel::DatabaseReader*);
|
||||
void setInventory(DataModel::Inventory*);
|
||||
|
||||
int filter(const Util::StringFirewall *networkTypeFW,
|
||||
const Util::StringFirewall *stationTypeFW);
|
||||
|
||||
void loadStations(DataModel::DatabaseReader*);
|
||||
|
||||
//! Returns the station location for a network- and stationcode and
|
||||
//! a time. If the station has not been found a ValueException will
|
||||
//! be thrown.
|
||||
StationLocation stationLocation(const std::string& networkCode,
|
||||
const std::string& stationCode,
|
||||
const Core::Time&) const;
|
||||
|
||||
//! Returns the station for a network- and stationcode and
|
||||
//! a time. If the station has not been found nullptr will be returned.
|
||||
DataModel::Station* getStation(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const Core::Time &,
|
||||
DataModel::InventoryError *error = nullptr) const;
|
||||
|
||||
//! Returns the sensorlocation for a network-, station- and locationcode and
|
||||
//! a time. If the sensorlocation has not been found nullptr will be returned.
|
||||
DataModel::SensorLocation* getSensorLocation(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const Core::Time &,
|
||||
DataModel::InventoryError *error = nullptr) const;
|
||||
|
||||
//! Returns the stream for a network-, station-, location- and channelcode and
|
||||
//! a time. If the stream has not been found nullptr will be returned.
|
||||
DataModel::Stream* getStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Core::Time &,
|
||||
DataModel::InventoryError *error = nullptr) const;
|
||||
|
||||
//! Returns the three streams (vertical, horizontal1, horizontal2) corresponding
|
||||
//! to the given network-, station-, location- and channel code
|
||||
DataModel::ThreeComponents getThreeComponents(const std::string& networkCode,
|
||||
const std::string& stationCode,
|
||||
const std::string& locationCode,
|
||||
const std::string& channelCode,
|
||||
const Core::Time&) const;
|
||||
|
||||
//! Returns the station used for a pick. If the station has not been found
|
||||
//! nullptr will be returned.
|
||||
DataModel::Station* getStation(const DataModel::Pick*) const;
|
||||
|
||||
//! Returns the sensor location used for a pick. If the sensor location has
|
||||
//! not been found nullptr will be returned.
|
||||
DataModel::SensorLocation* getSensorLocation(const DataModel::Pick*) const;
|
||||
|
||||
DataModel::Stream* getStream(const DataModel::Pick*) const;
|
||||
|
||||
//! Returns the three streams (vertical, horizontal1, horizontal2) corresponding
|
||||
//! to the picked stream.
|
||||
DataModel::ThreeComponents getThreeComponents(const DataModel::Pick*) const;
|
||||
|
||||
double getGain(const std::string& networkCode,
|
||||
const std::string& stationCode,
|
||||
const std::string& locationCode,
|
||||
const std::string& channelCode,
|
||||
const Core::Time&);
|
||||
|
||||
//! Returns all defined stations for the given time
|
||||
int getAllStations(StationList&, const Core::Time&);
|
||||
|
||||
DataModel::Inventory* inventory();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
DataModel::InventoryPtr _inventory;
|
||||
static Inventory _instance;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
114
include/seiscomp/client/monitor.h
Normal file
114
include/seiscomp/client/monitor.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/***************************************************************************
|
||||
* 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_UTILS_MONITOR_H
|
||||
#define SEISCOMP_UTILS_MONITOR_H
|
||||
|
||||
#include <seiscomp/client.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Client {
|
||||
|
||||
|
||||
//! A running average calculator that logs the number of
|
||||
//! objects/thingies in a certain interval. The accuracy is
|
||||
//! a second.
|
||||
class SC_SYSTEM_CLIENT_API RunningAverage {
|
||||
public:
|
||||
RunningAverage(int timeSpanInSeconds);
|
||||
|
||||
|
||||
public:
|
||||
int timeSpan() const { return _timeSpan; }
|
||||
|
||||
void push(const Core::Time &time, size_t count = 1);
|
||||
|
||||
//! Returns the current count per time span.
|
||||
int count(const Core::Time &time) const;
|
||||
|
||||
//! Returns the value (average) per time span.
|
||||
double value(const Core::Time &time) const;
|
||||
|
||||
//! Returns the timestamp of the last values pushed
|
||||
Core::Time last() const;
|
||||
|
||||
void dumpBins() const;
|
||||
|
||||
|
||||
private:
|
||||
Core::Time _first;
|
||||
Core::Time _last;
|
||||
size_t _timeSpan;
|
||||
double _scale;
|
||||
mutable
|
||||
double _shift;
|
||||
mutable
|
||||
std::vector<size_t> _bins;
|
||||
size_t _front;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CLIENT_API ObjectMonitor {
|
||||
public:
|
||||
typedef RunningAverage Log;
|
||||
|
||||
ObjectMonitor(int timeSpanInSeconds);
|
||||
~ObjectMonitor();
|
||||
|
||||
|
||||
public:
|
||||
Log *add(const std::string &name, const std::string &channel = "");
|
||||
void update(const Core::Time &time);
|
||||
|
||||
|
||||
public:
|
||||
struct Test {
|
||||
std::string name;
|
||||
std::string channel;
|
||||
Core::Time updateTime;
|
||||
size_t count;
|
||||
Log *test;
|
||||
};
|
||||
|
||||
typedef std::list<Test> Tests;
|
||||
typedef Tests::const_iterator const_iterator;
|
||||
|
||||
const_iterator begin() const;
|
||||
const_iterator end() const;
|
||||
|
||||
size_t size() const;
|
||||
|
||||
|
||||
private:
|
||||
Tests _tests;
|
||||
int _timeSpan;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
157
include/seiscomp/client/queue.h
Normal file
157
include/seiscomp/client/queue.h
Normal file
@@ -0,0 +1,157 @@
|
||||
/***************************************************************************
|
||||
* 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_CLIENT_QUEUE_H
|
||||
#define SEISCOMP_CLIENT_QUEUE_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Client {
|
||||
|
||||
class QueueClosedException : public Core::GeneralException {
|
||||
public:
|
||||
QueueClosedException() : Core::GeneralException("Queue has been closed") {}
|
||||
QueueClosedException(const std::string& str ) : Core::GeneralException(str) {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class ThreadedQueue {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
typedef std::unique_lock<std::mutex> lock;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Non copyable
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
ThreadedQueue(const ThreadedQueue&) = delete;
|
||||
ThreadedQueue &operator=(const ThreadedQueue&) = delete;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
ThreadedQueue();
|
||||
ThreadedQueue(int n);
|
||||
~ThreadedQueue();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief Resizes the queue to hold a maximum of n items before
|
||||
* blocking.
|
||||
* @param n The number of items to queue before blocking occurs.
|
||||
*/
|
||||
void resize(int n);
|
||||
|
||||
/**
|
||||
* @brief Checks whether the queue can take new items without blocking.
|
||||
* @return true if non-blocking push is possible, false otherwise.
|
||||
*/
|
||||
bool canPush() const;
|
||||
|
||||
/**
|
||||
* @brief Appends a new item to the end of the queue. If the queue is
|
||||
* full then it will block until a consumer has popped an item.
|
||||
* @param v The new item.
|
||||
* @return true if successful, false if queue is closed.
|
||||
*/
|
||||
bool push(T v);
|
||||
|
||||
/**
|
||||
* @brief Checks with equality operator if the item is already queued
|
||||
* and if not, pushes it to the end of the queue.
|
||||
* @param v The new item.
|
||||
* @return true if successful which also covers the case that the item
|
||||
* is already queued. False if the queue is closed.
|
||||
*/
|
||||
bool pushUnique(T v);
|
||||
|
||||
/**
|
||||
* @brief Checks whether an item can be popped or not.
|
||||
* Actually it returns whether the queue is empty or not.
|
||||
* @return true if not empty, false if empty.
|
||||
*/
|
||||
bool canPop() const;
|
||||
|
||||
/**
|
||||
* @brief Pops an items from the queue. If the queue is empty then
|
||||
* it blocks until a producer pushed an item.
|
||||
* @return The popped item.
|
||||
*/
|
||||
T pop();
|
||||
|
||||
/**
|
||||
* @brief Close the queue and cause all subsequent calls to push and
|
||||
* pop to fail.
|
||||
*/
|
||||
void close();
|
||||
|
||||
/**
|
||||
* @brief Returns whether the queue is closed or not.
|
||||
* @return The closed flag.
|
||||
*/
|
||||
bool isClosed() const;
|
||||
|
||||
/**
|
||||
* @brief Query the number of queued items.
|
||||
* @return The number of currently queued items.
|
||||
*/
|
||||
size_t size() const;
|
||||
|
||||
/**
|
||||
* @brief Resets the queue which incorporates resetting the buffer
|
||||
* insertations and the closed state.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
volatile int _begin, _end;
|
||||
volatile size_t _buffered;
|
||||
volatile bool _closed;
|
||||
std::vector<T> _buffer;
|
||||
std::condition_variable _notFull, _notEmpty;
|
||||
mutable std::mutex _monitor;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
266
include/seiscomp/client/queue.ipp
Normal file
266
include/seiscomp/client/queue.ipp
Normal file
@@ -0,0 +1,266 @@
|
||||
/***************************************************************************
|
||||
* 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_CLIENT_QUEUE_IPP
|
||||
#define SEISCOMP_CLIENT_QUEUE_IPP
|
||||
|
||||
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Client {
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T, int IsPtr>
|
||||
struct QueueHelper {};
|
||||
|
||||
template <typename T>
|
||||
struct QueueHelper<T,0> {
|
||||
static void clean(const std::vector<T> &) {}
|
||||
static T defaultValue() { return T(); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct QueueHelper<T,1> {
|
||||
static void clean(const std::vector<T> &b) {
|
||||
for ( size_t i = 0; i < b.size(); ++i ) {
|
||||
if ( b[i] ) delete b[i];
|
||||
}
|
||||
}
|
||||
|
||||
static T defaultValue() { return nullptr; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
ThreadedQueue<T>::ThreadedQueue() :
|
||||
_begin(0), _end(0),
|
||||
_buffered(0), _closed(false), _buffer(0)
|
||||
{}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
ThreadedQueue<T>::ThreadedQueue(int n) :
|
||||
_begin(0), _end(0),
|
||||
_buffered(0), _closed(false), _buffer(n)
|
||||
{}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
ThreadedQueue<T>::~ThreadedQueue() {
|
||||
close();
|
||||
QueueHelper<T, std::is_pointer<T>::value>::clean(_buffer);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void ThreadedQueue<T>::resize(int n) {
|
||||
lock lk(_monitor);
|
||||
_buffer.resize(n);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool ThreadedQueue<T>::canPush() const {
|
||||
lock lk(_monitor);
|
||||
|
||||
if ( _closed )
|
||||
throw QueueClosedException();
|
||||
|
||||
return _buffered < _buffer.size();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool ThreadedQueue<T>::push(T v) {
|
||||
lock lk(_monitor);
|
||||
while (_buffered == _buffer.size() && !_closed)
|
||||
_notFull.wait(lk);
|
||||
if ( _closed ) {
|
||||
_notEmpty.notify_all();
|
||||
return false;
|
||||
}
|
||||
_buffer[_end] = v;
|
||||
_end = (_end+1) % _buffer.size();
|
||||
++_buffered;
|
||||
_notEmpty.notify_all();
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool ThreadedQueue<T>::pushUnique(T v) {
|
||||
lock lk(_monitor);
|
||||
// Find existing item
|
||||
auto it = _begin;
|
||||
while ( it != _end ) {
|
||||
if ( _buffer[it] == v ) {
|
||||
return true;
|
||||
}
|
||||
it = (it + 1) % _buffer.size();
|
||||
}
|
||||
|
||||
while (_buffered == _buffer.size() && !_closed)
|
||||
_notFull.wait(lk);
|
||||
if ( _closed ) {
|
||||
_notEmpty.notify_all();
|
||||
return false;
|
||||
}
|
||||
_buffer[_end] = v;
|
||||
_end = (_end+1) % _buffer.size();
|
||||
++_buffered;
|
||||
_notEmpty.notify_all();
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool ThreadedQueue<T>::canPop() const {
|
||||
lock lk(_monitor);
|
||||
|
||||
if ( _closed )
|
||||
throw QueueClosedException();
|
||||
|
||||
return _buffered > 0;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
T ThreadedQueue<T>::pop() {
|
||||
lock lk(_monitor);
|
||||
while (_buffered == 0 && !_closed) {
|
||||
_notEmpty.wait(lk);
|
||||
}
|
||||
if ( _closed )
|
||||
throw QueueClosedException();
|
||||
T v = _buffer[_begin];
|
||||
_buffer[_begin] = QueueHelper<T, std::is_pointer<T>::value>::defaultValue();
|
||||
_begin = (_begin+1) % _buffer.size();
|
||||
--_buffered;
|
||||
_notFull.notify_all();
|
||||
return v;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void ThreadedQueue<T>::close() {
|
||||
lock lk(_monitor);
|
||||
if ( _closed ) return;
|
||||
_closed = true;
|
||||
_notFull.notify_all();
|
||||
_notEmpty.notify_all();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
bool ThreadedQueue<T>::isClosed() const {
|
||||
lock lk(_monitor);
|
||||
return _closed;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
size_t ThreadedQueue<T>::size() const {
|
||||
lock lk(_monitor);
|
||||
return _buffered;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void ThreadedQueue<T>::reset() {
|
||||
lock lk(_monitor);
|
||||
_closed = false;
|
||||
_begin = _end = 0;
|
||||
_buffered = 0;
|
||||
QueueHelper<T, std::is_pointer<T>::value>::clean(_buffer);
|
||||
std::fill(_buffer.begin(), _buffer.end(), QueueHelper<T, std::is_pointer<T>::value>::defaultValue());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
142
include/seiscomp/client/streamapplication.h
Normal file
142
include/seiscomp/client/streamapplication.h
Normal file
@@ -0,0 +1,142 @@
|
||||
/***************************************************************************
|
||||
* 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_CLIENT_STREAM_APPLICATION_H
|
||||
#define SEISCOMP_CLIENT_STREAM_APPLICATION_H
|
||||
|
||||
|
||||
#include <seiscomp/client/application.h>
|
||||
#include <seiscomp/core/record.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Client {
|
||||
|
||||
|
||||
class SC_SYSTEM_CLIENT_API StreamApplication : public Application {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
StreamApplication(int argc, char **argv);
|
||||
~StreamApplication();
|
||||
|
||||
|
||||
public:
|
||||
bool openStream();
|
||||
void closeStream();
|
||||
|
||||
IO::RecordStream* recordStream() const;
|
||||
|
||||
bool addStation(const std::string& networkCode,
|
||||
const std::string& stationCode);
|
||||
bool addStream(const std::string& networkCode,
|
||||
const std::string& stationCode,
|
||||
const std::string& locationCode,
|
||||
const std::string& channelCode);
|
||||
|
||||
void setStartTime(const Seiscomp::Core::Time&);
|
||||
void setEndTime(const Seiscomp::Core::Time&);
|
||||
bool setTimeWindow(const Seiscomp::Core::TimeWindow&);
|
||||
|
||||
//! Sets whether to start the acquisition automatically
|
||||
//! before the run loop or not. This method has to be called before run().
|
||||
//! The default is true. If set to false then the acquisition needs
|
||||
//! to be started with readRecords or startRecordThread and
|
||||
//! autoCloseOnAcquisitionFinished is also set to false.
|
||||
void setAutoAcquisitionStart(bool);
|
||||
|
||||
//! Sets the application close flag when acquisition is finished.
|
||||
//! The default is true as auto start is true. If setAutoAcquisitionStart
|
||||
//! is changed this flag is set as well.
|
||||
void setAutoCloseOnAcquisitionFinished(bool);
|
||||
|
||||
//! Sets the storage hint of incoming records.
|
||||
//! The default is: DATA_ONLY
|
||||
void setRecordInputHint(Record::Hint hint);
|
||||
|
||||
//! Sets the data type of read records.
|
||||
//! The default is: FLOAT
|
||||
void setRecordDatatype(Array::DataType datatype);
|
||||
|
||||
//! Returns the data type of the internal record sample buffer
|
||||
Array::DataType recordDataType() const { return _recordDatatype; }
|
||||
|
||||
void startRecordThread();
|
||||
void waitForRecordThread();
|
||||
bool isRecordThreadActive() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
bool init();
|
||||
bool run();
|
||||
void done();
|
||||
void exit(int returnCode);
|
||||
|
||||
bool dispatch(Core::BaseObject* obj);
|
||||
|
||||
void readRecords(bool sendEndNotification);
|
||||
|
||||
//! This method gets called when the acquisition is finished
|
||||
//! The default implementation closes the objects queue and
|
||||
//! finishes the application
|
||||
virtual void acquisitionFinished();
|
||||
|
||||
//! This method gets called when a new record has been received
|
||||
//! by recordstream thread.
|
||||
//! The default implementation stores it in the threaded object
|
||||
//! queue which gets read by the main thread.
|
||||
//! The input record is not managed and ownership is transferred
|
||||
//! to this method.
|
||||
virtual bool storeRecord(Record *rec);
|
||||
|
||||
//! This method gets called when a record has been popped from
|
||||
//! the event queue in the main thread. The ownership of the
|
||||
//! pointer is transferred to this method. An empty function
|
||||
//! body override would cause a memory leak.
|
||||
virtual void handleRecord(Record *rec) = 0;
|
||||
|
||||
//! Logs the received records for the last period
|
||||
virtual void handleMonitorLog(const Core::Time ×tamp);
|
||||
|
||||
|
||||
private:
|
||||
bool _startAcquisition;
|
||||
bool _closeOnAcquisitionFinished;
|
||||
Record::Hint _recordInputHint;
|
||||
Array::DataType _recordDatatype;
|
||||
IO::RecordStreamPtr _recordStream;
|
||||
std::thread *_recordThread;
|
||||
size_t _receivedRecords;
|
||||
ObjectLog *_logRecords;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
17
include/seiscomp/config/api.h
Normal file
17
include/seiscomp/config/api.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SC_CONFIG_API_H
|
||||
#define SC_CONFIG_API_H
|
||||
|
||||
#if defined(WIN32) && (defined(SC_CONFIG_SHARED) || defined(SC_ALL_SHARED))
|
||||
# if defined(SC_CONFIG_EXPORTS)
|
||||
# define SC_CONFIG_API __declspec(dllexport)
|
||||
# define SC_CONFIG_TEMPLATE_EXPORT
|
||||
# else
|
||||
# define SC_CONFIG_API __declspec(dllimport)
|
||||
# define SC_CONFIG_TEMPLATE_EXPORT extern
|
||||
# endif
|
||||
#else
|
||||
# define SC_CONFIG_API
|
||||
# define SC_CONFIG_TEMPLATE_EXPORT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
349
include/seiscomp/config/config.h
Normal file
349
include/seiscomp/config/config.h
Normal file
@@ -0,0 +1,349 @@
|
||||
/***************************************************************************
|
||||
* 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_CONFIG_H__
|
||||
#define __SEISCOMP_CONFIG_H__
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
|
||||
#include <seiscomp/config/log.h>
|
||||
#include <seiscomp/config/exceptions.h>
|
||||
#include <seiscomp/config/symboltable.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Config {
|
||||
|
||||
/**
|
||||
* Mapping of configuration variable to type
|
||||
*/
|
||||
typedef std::map<std::string, std::string> Variables;
|
||||
|
||||
|
||||
/**
|
||||
* This is a class for reading and writing configuration files. Currently the
|
||||
* following datatypes are supported: bool, int, double and std::string as well as
|
||||
* lists of the datatypes
|
||||
*/
|
||||
class SC_CONFIG_API Config {
|
||||
// ------------------------------------------------------------------------
|
||||
// X'struction
|
||||
// ------------------------------------------------------------------------
|
||||
public:
|
||||
Config();
|
||||
~Config();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------------
|
||||
public:
|
||||
/** When names are queried and this check is enabled, it will
|
||||
* throw an exception if the same name is defined in a later stage
|
||||
* with respect to case insensitive name comparison.
|
||||
* This allows to check for parameter inconsistencies that are
|
||||
* hard to track otherwise.
|
||||
*/
|
||||
void setCaseSensitivityCheck(bool);
|
||||
|
||||
/** Reads the given configuration file.
|
||||
* @param file name of the configuration files
|
||||
* @param stage Optional stage value to be set to each read symbol
|
||||
* @param raw Raw mode which does not resolv references like ${var}
|
||||
* @return true on success
|
||||
*/
|
||||
bool readConfig(const std::string& file, int stage=-1, bool raw=false);
|
||||
|
||||
/** Writes the configuration to the given configuration file.
|
||||
* @param file name of the configuarion files
|
||||
* @param localOnly write only value read from this file and
|
||||
* new entries
|
||||
* @return true on success
|
||||
*/
|
||||
bool writeConfig(const std::string& file, bool localOny = true,
|
||||
bool multilineLists = false);
|
||||
|
||||
/** Writes the configuration to the file which was given to
|
||||
* readConfing
|
||||
* @return true on success
|
||||
*/
|
||||
bool writeConfig(bool localOnly = true);
|
||||
|
||||
/** Sets the current logger. The ownership does not go to the config
|
||||
* object. It is up to the caller to free resources.
|
||||
* @param logger A logger implementation
|
||||
*/
|
||||
void setLogger(Logger *logger);
|
||||
|
||||
/** Returns the symboltabel as string */
|
||||
std::string symbolsToString();
|
||||
|
||||
/** Returns the names of parameters */
|
||||
std::vector<std::string> names() const;
|
||||
|
||||
/** Returns the names of the visited files */
|
||||
std::string visitedFilesToString();
|
||||
|
||||
//! Gets an integer from the configuration file
|
||||
//! @param name name of the element
|
||||
//! @return value
|
||||
int getInt(const std::string& name) const;
|
||||
int getInt(const std::string& name, bool* error) const;
|
||||
bool getInt(int& value, const std::string& name) const;
|
||||
|
||||
bool setInt(const std::string& name, int value);
|
||||
|
||||
/** Gets a double from the configuration file
|
||||
* @param name name of the element
|
||||
* @return double
|
||||
*/
|
||||
double getDouble(const std::string& name) const;
|
||||
double getDouble(const std::string& name, bool* error) const;
|
||||
bool getDouble(double& value, const std::string& name) const;
|
||||
|
||||
bool setDouble(const std::string& name, double value);
|
||||
|
||||
/** Gets an boolean from the configuration file
|
||||
* @param name name of the element
|
||||
* @return boolean
|
||||
*/
|
||||
bool getBool(const std::string& name) const;
|
||||
bool getBool(const std::string& name, bool* error) const;
|
||||
bool getBool(bool& value, const std::string& name) const;
|
||||
|
||||
bool setBool(const std::string& name, bool value);
|
||||
|
||||
/** Gets a string from the configuration file
|
||||
* @param name name of the element
|
||||
* @return string
|
||||
*/
|
||||
std::string getString(const std::string& name) const;
|
||||
std::string getString(const std::string& name, bool* error) const;
|
||||
bool getString(std::string& value, const std::string& name) const;
|
||||
|
||||
bool setString(const std::string& name, const std::string& value);
|
||||
|
||||
/** Removes the symbol with the given name from the symboltable.
|
||||
* @param name Symbol to be removed
|
||||
*/
|
||||
bool remove(const std::string& name);
|
||||
|
||||
std::vector<int> getInts(const std::string& name) const;
|
||||
|
||||
std::vector<int> getInts(const std::string& name, bool* error) const;
|
||||
|
||||
bool setInts(const std::string& name, const std::vector<int>& values);
|
||||
|
||||
std::vector<double> getDoubles(const std::string& name) const;
|
||||
|
||||
std::vector<double> getDoubles(const std::string& name, bool* error) const;
|
||||
|
||||
bool setDoubles(const std::string& name, const std::vector<double>& values);
|
||||
|
||||
std::vector<bool> getBools(const std::string& name) const;
|
||||
|
||||
std::vector<bool> getBools(const std::string& name, bool* error) const;
|
||||
|
||||
bool setBools(const std::string& name, const std::vector<bool>& values);
|
||||
|
||||
std::vector<std::string> getStrings(const std::string& name) const;
|
||||
std::vector<std::string> getStrings(const std::string& name, bool* error) const;
|
||||
bool getStrings(std::vector<std::string>& value, const std::string& name) const;
|
||||
|
||||
bool setStrings(const std::string& name, const std::vector<std::string>& values);
|
||||
|
||||
SymbolTable *symbolTable() const;
|
||||
|
||||
/** Evaluates a rvalue string and writes the output in result.
|
||||
* The symbol table is taken from this instance.
|
||||
* @param rvalue The value string to be parsed
|
||||
* @param result The result string vector
|
||||
* @param resolveReference Should references be resolved or not (eg
|
||||
* environment variables).
|
||||
* @return Success or error
|
||||
*/
|
||||
bool eval(const std::string &rvalue,
|
||||
std::vector<std::string> &result,
|
||||
bool resolveReferences = true,
|
||||
std::string *errmsg = NULL);
|
||||
|
||||
/** Evaluates a rvalue string and writes the output in result.
|
||||
* The symbol table is taken from this instance.
|
||||
* @param rvalue The value string to be parsed
|
||||
* @param result The result string vector
|
||||
* @param resolveReference Should references be resolved or not (eg
|
||||
* environment variables).
|
||||
* @param The symbol table to be used to resolve references if enabled.
|
||||
* @return Success or error
|
||||
*/
|
||||
static bool Eval(const std::string &rvalue,
|
||||
std::vector<std::string> &result,
|
||||
bool resolveReferences = true,
|
||||
SymbolTable *symtab = NULL,
|
||||
std::string *errmsg = NULL);
|
||||
|
||||
/** Writes the values of a symbol to an output stream. No new line
|
||||
* is appended.
|
||||
*/
|
||||
static void writeValues(std::ostream &os, const Symbol *symbol,
|
||||
bool multilineLists = false);
|
||||
|
||||
/** Writes the content of the symbol to an output stream. No new line
|
||||
* is appended.
|
||||
*/
|
||||
static void writeContent(std::ostream &os, const Symbol *symbol,
|
||||
bool multilineLists = false);
|
||||
|
||||
/** Writes a symbol to an output stream including the symbol
|
||||
* name and a equal sign. A new line is appended.
|
||||
*/
|
||||
static void writeSymbol(std::ostream &os, const Symbol *symbol,
|
||||
bool multilineLists = false);
|
||||
|
||||
/**
|
||||
* @brief Escapes an identifier (symbol name).
|
||||
* @return The escaped string
|
||||
*/
|
||||
static std::string escapeIdentifier(const std::string &);
|
||||
|
||||
/** Enables/disables tracking of configuration variables.
|
||||
*/
|
||||
void trackVariables(bool enabled);
|
||||
|
||||
/** Returns all configuration variables read by an application mapped
|
||||
* to a type
|
||||
*/
|
||||
const Variables& getVariables() const;
|
||||
|
||||
/**
|
||||
* @brief Escapes a string value that it can be stored in the
|
||||
* configuration file without further modifications.
|
||||
* @return The escaped string inside double quotes if necessary
|
||||
*/
|
||||
std::string escape(const std::string &) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------------
|
||||
public:
|
||||
Config &operator=(Config &&other);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
/** Parses the given file
|
||||
* @return true on success false on failure
|
||||
*/
|
||||
bool parseFile(std::istream &is); // virtual candidate
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ------------------------------------------------------------------------
|
||||
private:
|
||||
void init();
|
||||
bool handleEntry(const std::string& entry, const std::string& comment);
|
||||
bool handleInclude(const std::string& fileName);
|
||||
void handleAssignment(const std::string& name, const std::string& content,
|
||||
std::vector<std::string>& values,
|
||||
const std::string& comment);
|
||||
std::vector<std::string> tokenize(const std::string& entry);
|
||||
static bool reference(const std::string &name,
|
||||
std::vector<std::string> &value,
|
||||
const SymbolTable *symtab);
|
||||
static bool parseRValue(const std::string& entry,
|
||||
std::vector<std::string>& parsedValues,
|
||||
const SymbolTable *symtab,
|
||||
bool resolveReferences,
|
||||
bool rawMode,
|
||||
std::string *errmsg);
|
||||
|
||||
bool readInternalConfig(const std::string &file, SymbolTable *symbolTable,
|
||||
const std::string &namespacePrefix,
|
||||
int stage = -1, bool raw = false);
|
||||
|
||||
template <typename T>
|
||||
T get(const std::string& name) const;
|
||||
|
||||
template <typename T>
|
||||
T get(const std::string& name, bool* error) const;
|
||||
|
||||
template <typename T>
|
||||
bool get(T& value, const std::string& name) const;
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> getVec(const std::string& name) const;
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> getVec(const std::string& name, bool* error) const;
|
||||
|
||||
template <typename T>
|
||||
void add(const std::string& name, const T& value);
|
||||
|
||||
template <typename T>
|
||||
void add(const std::string& name, const std::vector<T>& values);
|
||||
|
||||
/** Sets an value in the configuration file
|
||||
* @param element name of the element
|
||||
* @param value value for the element */
|
||||
template <typename T>
|
||||
bool set(const std::string& name, const T& value);
|
||||
|
||||
template <typename T>
|
||||
bool set(const std::string& name, const std::vector<T>& values);
|
||||
|
||||
inline void addVariable(const std::string &name, const char *type) const;
|
||||
|
||||
void releaseSymbolTable();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Private data members
|
||||
// ------------------------------------------------------------------------
|
||||
private:
|
||||
typedef std::deque<std::string> Namespaces;
|
||||
int _stage;
|
||||
int _line;
|
||||
bool _resolveReferences;
|
||||
std::string _fileName;
|
||||
Namespaces _namespaces;
|
||||
std::string _namespacePrefix;
|
||||
std::string _defaultNamespacePrefix;
|
||||
Logger *_logger;
|
||||
|
||||
SymbolTable *_symbolTable;
|
||||
bool _trackVariables;
|
||||
Variables _variables;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Config
|
||||
} // namespace Seiscomp
|
||||
|
||||
#endif
|
||||
220
include/seiscomp/config/config.ipp
Normal file
220
include/seiscomp/config/config.ipp
Normal file
@@ -0,0 +1,220 @@
|
||||
/***************************************************************************
|
||||
* 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>
|
||||
void Config::add(const std::string &name, const T &value) {
|
||||
Symbol symbol;
|
||||
symbol.name = name;
|
||||
symbol.values.push_back(Private::toString(value));
|
||||
symbol.uri = "";
|
||||
|
||||
_symbolTable->add(symbol);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <>
|
||||
void Config::add<std::string>(const std::string &name, const std::string &value) {
|
||||
Symbol symbol;
|
||||
symbol.name = name;
|
||||
symbol.values.push_back(value);
|
||||
symbol.uri = "";
|
||||
|
||||
_symbolTable->add(symbol);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <typename T>
|
||||
void Config::add(const std::string &name, const std::vector<T> &values) {
|
||||
Symbol symbol;
|
||||
symbol.name = name;
|
||||
for ( size_t i = 0; i < values.size(); ++i ) {
|
||||
symbol.values.push_back(Private::toString(values[i]));
|
||||
}
|
||||
symbol.uri = "";
|
||||
|
||||
_symbolTable->add(symbol);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <>
|
||||
void Config::add<std::string>(const std::string &name, const std::vector<std::string> &values) {
|
||||
Symbol symbol;
|
||||
symbol.name = name;
|
||||
for ( size_t i = 0; i < values.size(); ++i ) {
|
||||
symbol.values.push_back(values[i]);
|
||||
}
|
||||
symbol.uri = "";
|
||||
|
||||
_symbolTable->add(symbol);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <typename T>
|
||||
bool Config::set(const std::string &name, const T &value) {
|
||||
Symbol* symbol = _symbolTable->get(name);
|
||||
if ( !symbol ) {
|
||||
add<T>(name, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
symbol->values.clear();
|
||||
symbol->values.push_back(Private::toString(value));
|
||||
symbol->uri = "";
|
||||
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <typename T>
|
||||
bool Config::set(const std::string &name, const std::vector<T> &values) {
|
||||
Symbol *symbol = _symbolTable->get(name);
|
||||
if ( !symbol ) {
|
||||
add<T>(name, values);
|
||||
return true;
|
||||
}
|
||||
|
||||
symbol->values.clear();
|
||||
for ( size_t i = 0; i < values.size(); ++i ) {
|
||||
symbol->values.push_back(Private::toString(values[i]));
|
||||
}
|
||||
|
||||
symbol->uri = "";
|
||||
return true;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <typename T>
|
||||
T Config::get(const std::string& name) const {
|
||||
const Symbol *symbol = _symbolTable->get(name);
|
||||
if ( !symbol ) {
|
||||
throw OptionNotFoundException(name);
|
||||
}
|
||||
|
||||
T value = T();
|
||||
if ( !Private::fromString(value, symbol->values[0]) ) {
|
||||
throw TypeConversionException(symbol->values[0]);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <typename T>
|
||||
std::vector<T> Config::getVec(const std::string& name) const {
|
||||
const Symbol *symbol = _symbolTable->get(name);
|
||||
if ( !symbol ) {
|
||||
throw OptionNotFoundException(name);
|
||||
}
|
||||
|
||||
std::vector<T> values;
|
||||
for ( size_t i = 0; i < symbol->values.size(); ++i ) {
|
||||
T tmp = T();
|
||||
if ( !Private::fromString(tmp, symbol->values[i]) ) {
|
||||
throw TypeConversionException(symbol->values[i]);
|
||||
}
|
||||
values.push_back(tmp);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <typename T>
|
||||
T Config::get(const std::string &name, bool *error) const {
|
||||
*error = false;
|
||||
try {
|
||||
return get<T>(name);
|
||||
}
|
||||
catch (...) {
|
||||
*error = true;
|
||||
return T();
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <typename T>
|
||||
bool Config::get(T &value, const std::string &name) const {
|
||||
try {
|
||||
value = get<T>(name);
|
||||
return true;
|
||||
}
|
||||
catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
template <typename T>
|
||||
std::vector<T> Config::getVec(const std::string &name, bool *error) const {
|
||||
*error = false;
|
||||
try {
|
||||
return getVec<T>(name);
|
||||
}
|
||||
catch (...) {
|
||||
*error = true;
|
||||
return std::vector<T>();
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
80
include/seiscomp/config/exceptions.h
Normal file
80
include/seiscomp/config/exceptions.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/***************************************************************************
|
||||
* 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_CONFIG_EXCEPTIONS_H__
|
||||
#define __SEISCOMP_CONFIG_EXCEPTIONS_H__
|
||||
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <seiscomp/config/api.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Config {
|
||||
|
||||
|
||||
class SC_CONFIG_API Exception : public std::exception {
|
||||
public:
|
||||
Exception() : _what("Configuration exception") {}
|
||||
Exception(const std::string &str) : _what(str) {}
|
||||
Exception(const char *str) : _what(str) {}
|
||||
virtual ~Exception() throw() {}
|
||||
|
||||
const char *what() const throw() { return _what.c_str(); }
|
||||
|
||||
private:
|
||||
std::string _what;
|
||||
};
|
||||
|
||||
|
||||
class SC_CONFIG_API OptionNotFoundException : public Exception {
|
||||
public:
|
||||
OptionNotFoundException() : Exception("Option not found") { }
|
||||
OptionNotFoundException(const std::string& str) : Exception("Option not found for: " + str) { }
|
||||
};
|
||||
|
||||
|
||||
class SC_CONFIG_API TypeConversionException : public Exception {
|
||||
public:
|
||||
TypeConversionException() : Exception("Type conversion error") { }
|
||||
TypeConversionException(const std::string& str) : Exception("Type conversion error: " + str) { }
|
||||
};
|
||||
|
||||
|
||||
class SC_CONFIG_API SyntaxException : public Exception {
|
||||
public:
|
||||
SyntaxException() : Exception("Syntax error") { }
|
||||
SyntaxException(const std::string& str) : Exception("Syntax error: " + str) { }
|
||||
};
|
||||
|
||||
|
||||
class SC_CONFIG_API CaseSensitivityException : public Exception {
|
||||
public:
|
||||
CaseSensitivityException() : Exception("Case-insensitiv names are ambiguous") { }
|
||||
CaseSensitivityException(const std::string &str) : Exception("Case-insensitiv names are ambiguous: " + str) { }
|
||||
};
|
||||
|
||||
|
||||
} // namespace Config
|
||||
} // namespace Seiscomp
|
||||
|
||||
|
||||
#endif
|
||||
67
include/seiscomp/config/log.h
Normal file
67
include/seiscomp/config/log.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/***************************************************************************
|
||||
* 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_CONFIG_LOG_H__
|
||||
#define __SEISCOMP_CONFIG_LOG_H__
|
||||
|
||||
|
||||
#include <seiscomp/config/api.h>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Config {
|
||||
|
||||
|
||||
enum LogLevel {
|
||||
ERROR,
|
||||
WARNING,
|
||||
INFO,
|
||||
DEBUG
|
||||
};
|
||||
|
||||
|
||||
struct SC_CONFIG_API Logger {
|
||||
virtual ~Logger();
|
||||
virtual void log(LogLevel, const char *filename, int line, const char *msg);
|
||||
};
|
||||
|
||||
|
||||
extern char log_msg_buffer[1024];
|
||||
|
||||
|
||||
#define CONFIG_LOG_CHANNEL(chan, msg, ...) \
|
||||
if ( _logger ) {\
|
||||
snprintf(log_msg_buffer, 1023, msg, __VA_ARGS__);\
|
||||
_logger->log(chan, _fileName.c_str(), _line, log_msg_buffer);\
|
||||
}
|
||||
|
||||
|
||||
#define CONFIG_ERROR(msg, ...) CONFIG_LOG_CHANNEL(ERROR, msg, __VA_ARGS__)
|
||||
#define CONFIG_WARNING(msg, ...) CONFIG_LOG_CHANNEL(WARNING, msg, __VA_ARGS__)
|
||||
#define CONFIG_INFO(msg, ...) CONFIG_LOG_CHANNEL(INFO, msg, __VA_ARGS__)
|
||||
#define CONFIG_DEBUG(msg, ...) CONFIG_LOG_CHANNEL(DEBUG, msg, __VA_ARGS__)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
135
include/seiscomp/config/symboltable.h
Normal file
135
include/seiscomp/config/symboltable.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_CONFIG_SYMBOLTABLE__
|
||||
#define __SEISCOMP_CONFIG_SYMBOLTABLE__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
#include <seiscomp/config/log.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace Config {
|
||||
|
||||
|
||||
struct SC_CONFIG_API Symbol {
|
||||
typedef std::vector<std::string> Values;
|
||||
|
||||
Symbol(const std::string& name, const std::string& ns,
|
||||
const std::vector<std::string>& values,
|
||||
const std::string& uri,
|
||||
const std::string& comment,
|
||||
int stage = -1);
|
||||
Symbol();
|
||||
|
||||
void set(const std::string& name, const std::string& ns,
|
||||
const std::vector<std::string>& values,
|
||||
const std::string& uri,
|
||||
const std::string& comment,
|
||||
int stage = -1);
|
||||
|
||||
bool operator ==(const Symbol& symbol) const;
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
std::string name;
|
||||
std::string ns;
|
||||
std::string content;
|
||||
Values values;
|
||||
std::string uri;
|
||||
std::string comment;
|
||||
int stage;
|
||||
int line;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class SC_CONFIG_API SymbolTable {
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, Symbol> Symbols;
|
||||
typedef std::vector<Symbol*> SymbolOrder;
|
||||
typedef std::map<std::string, Symbols::iterator> CISymbols;
|
||||
|
||||
public:
|
||||
typedef SymbolOrder::const_iterator iterator;
|
||||
typedef std::set<std::string> IncludedFiles;
|
||||
typedef IncludedFiles::iterator file_iterator;
|
||||
|
||||
public:
|
||||
SymbolTable();
|
||||
|
||||
|
||||
public:
|
||||
void setCaseSensitivityCheck(bool);
|
||||
void setLogger(Logger *);
|
||||
Logger *logger();
|
||||
|
||||
void add(const std::string& name, const std::string &ns,
|
||||
const std::string& content,
|
||||
const std::vector<std::string>& values,
|
||||
const std::string& uri,
|
||||
const std::string& comment = "",
|
||||
int stage=-1, int line=-1);
|
||||
|
||||
void add(const Symbol& symbol);
|
||||
|
||||
Symbol* get(const std::string& name);
|
||||
const Symbol* get(const std::string& name) const;
|
||||
|
||||
bool remove(const std::string& name);
|
||||
|
||||
int incrementObjectCount();
|
||||
int decrementObjectCount();
|
||||
int objectCount() const;
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
bool hasFileBeenIncluded(const std::string& fileName);
|
||||
void addToIncludedFiles(const std::string& fileName);
|
||||
|
||||
file_iterator includesBegin();
|
||||
file_iterator includesEnd();
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
|
||||
private:
|
||||
//! Returns true if an inconsistent definition has been found
|
||||
bool checkCI(const std::string &name, const Symbol *) const;
|
||||
|
||||
private:
|
||||
bool _csCheck;
|
||||
Symbols _symbols;
|
||||
CISymbols _cisymbols;
|
||||
SymbolOrder _symbolOrder;
|
||||
IncludedFiles _includedFiles;
|
||||
int _objectCount;
|
||||
Logger *_logger;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Config
|
||||
} // namespace Seiscomp
|
||||
|
||||
#endif
|
||||
17
include/seiscomp/core.h
Normal file
17
include/seiscomp/core.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SC_SYSTEM_CORE_API_H
|
||||
#define SC_SYSTEM_CORE_API_H
|
||||
|
||||
#if defined(WIN32) && (defined(SC_SYSTEM_CORE_SHARED) || defined(SC_ALL_SHARED))
|
||||
# if defined(SC_SYSTEM_CORE_EXPORTS)
|
||||
# define SC_SYSTEM_CORE_API __declspec(dllexport)
|
||||
# define SC_SYSTEM_CORE_TEMPLATE_EXPORT
|
||||
# else
|
||||
# define SC_SYSTEM_CORE_API __declspec(dllimport)
|
||||
# define SC_SYSTEM_CORE_TEMPLATE_EXPORT extern
|
||||
# endif
|
||||
#else
|
||||
# define SC_SYSTEM_CORE_API
|
||||
# define SC_SYSTEM_CORE_TEMPLATE_EXPORT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
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
|
||||
194
include/seiscomp/datamodel/access.h
Normal file
194
include/seiscomp/datamodel/access.h
Normal file
@@ -0,0 +1,194 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_ACCESS_H
|
||||
#define SEISCOMP_DATAMODEL_ACCESS_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Access);
|
||||
|
||||
class Routing;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API AccessIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
AccessIndex();
|
||||
AccessIndex(const std::string& networkCode,
|
||||
const std::string& stationCode,
|
||||
const std::string& locationCode,
|
||||
const std::string& streamCode,
|
||||
const std::string& user,
|
||||
Seiscomp::Core::Time start);
|
||||
|
||||
//! Copy constructor
|
||||
AccessIndex(const AccessIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const AccessIndex&) const;
|
||||
bool operator!=(const AccessIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string networkCode;
|
||||
std::string stationCode;
|
||||
std::string locationCode;
|
||||
std::string streamCode;
|
||||
std::string user;
|
||||
Seiscomp::Core::Time start;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief This type describes an ArcLink access rule
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API Access : public Object {
|
||||
DECLARE_SC_CLASS(Access)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
Access();
|
||||
|
||||
//! Copy constructor
|
||||
Access(const Access& other);
|
||||
|
||||
//! Destructor
|
||||
~Access() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
Access& operator=(const Access& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const Access& other) const;
|
||||
bool operator!=(const Access& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const Access& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Network code
|
||||
void setNetworkCode(const std::string& networkCode);
|
||||
const std::string& networkCode() const;
|
||||
|
||||
//! Station code (empty for any station)
|
||||
void setStationCode(const std::string& stationCode);
|
||||
const std::string& stationCode() const;
|
||||
|
||||
//! Location code (empty for any location)
|
||||
void setLocationCode(const std::string& locationCode);
|
||||
const std::string& locationCode() const;
|
||||
|
||||
//! Stream (Channel) code (empty for any stream)
|
||||
void setStreamCode(const std::string& streamCode);
|
||||
const std::string& streamCode() const;
|
||||
|
||||
//! Username (e-mail) or part of it (must match the end)
|
||||
void setUser(const std::string& user);
|
||||
const std::string& user() const;
|
||||
|
||||
//! Start of validity
|
||||
void setStart(Seiscomp::Core::Time start);
|
||||
Seiscomp::Core::Time start() const;
|
||||
|
||||
//! End of validity
|
||||
void setEnd(const OPT(Seiscomp::Core::Time)& end);
|
||||
Seiscomp::Core::Time end() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const AccessIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const Access* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Routing* routing() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
AccessIndex _index;
|
||||
|
||||
// Attributes
|
||||
OPT(Seiscomp::Core::Time) _end;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
313
include/seiscomp/datamodel/amplitude.h
Normal file
313
include/seiscomp/datamodel/amplitude.h
Normal file
@@ -0,0 +1,313 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_AMPLITUDE_H
|
||||
#define SEISCOMP_DATAMODEL_AMPLITUDE_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/realquantity.h>
|
||||
#include <seiscomp/datamodel/timewindow.h>
|
||||
#include <seiscomp/datamodel/waveformstreamid.h>
|
||||
#include <seiscomp/datamodel/timequantity.h>
|
||||
#include <seiscomp/datamodel/types.h>
|
||||
#include <seiscomp/datamodel/creationinfo.h>
|
||||
#include <vector>
|
||||
#include <seiscomp/datamodel/comment.h>
|
||||
#include <seiscomp/datamodel/notifier.h>
|
||||
#include <seiscomp/datamodel/publicobject.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Amplitude);
|
||||
DEFINE_SMARTPOINTER(Comment);
|
||||
|
||||
class EventParameters;
|
||||
|
||||
|
||||
/**
|
||||
* \brief This class represents a quantification of the waveform
|
||||
* \brief anomaly, usually
|
||||
* \brief a single amplitude measurement or a measurement of the
|
||||
* \brief visible signal
|
||||
* \brief duration for duration magnitudes.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API Amplitude : public PublicObject {
|
||||
DECLARE_SC_CLASS(Amplitude)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Protected constructor
|
||||
Amplitude();
|
||||
|
||||
public:
|
||||
//! Copy constructor
|
||||
Amplitude(const Amplitude& other);
|
||||
|
||||
//! Constructor with publicID
|
||||
Amplitude(const std::string& publicID);
|
||||
|
||||
//! Destructor
|
||||
~Amplitude() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Creators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static Amplitude* Create();
|
||||
static Amplitude* Create(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Lookup
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static Amplitude* Find(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
//! No changes regarding child objects are made
|
||||
Amplitude& operator=(const Amplitude& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const Amplitude& other) const;
|
||||
bool operator!=(const Amplitude& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const Amplitude& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! String that describes the type of amplitude using the
|
||||
//! nomenclature
|
||||
//! from Storchak et al. (2003). Possible values include
|
||||
//! unspecified
|
||||
//! amplitude reading (A), amplitude reading for local
|
||||
//! magnitude (ML),
|
||||
//! amplitude reading for body wave magnitude (MB), amplitude
|
||||
//! reading
|
||||
//! for surface wave magnitude (MS), and time of visible end of
|
||||
//! record
|
||||
//! for duration magnitude (MD). It has a maximum length of 16
|
||||
//! characters.
|
||||
void setType(const std::string& type);
|
||||
const std::string& type() const;
|
||||
|
||||
//! Measured amplitude value for the given waveformID. Note
|
||||
//! that this
|
||||
//! attribute can describe different physical quantities,
|
||||
//! depending on
|
||||
//! the type of the amplitude. These can be, e.g.,
|
||||
//! displacement, velocity,
|
||||
//! or a period. If the only amplitude information is a period,
|
||||
//! it has
|
||||
//! to specified here, not in the period attribute. The latter
|
||||
//! can be used
|
||||
//! if the amplitude measurement contains information on, e.g.,
|
||||
//! displacement and an additional period. Since the physical
|
||||
//! quantity
|
||||
//! described by this attribute is not fixed, the unit of
|
||||
//! measurement
|
||||
//! cannot be defined in advance. However, the quantity has to
|
||||
//! be
|
||||
//! specified in SI base units. The enumeration given in
|
||||
//! attribute unit
|
||||
//! provides the most likely units that could be needed here.
|
||||
//! For clarity, using the optional unit attribute is highly
|
||||
//! encouraged.
|
||||
void setAmplitude(const OPT(RealQuantity)& amplitude);
|
||||
RealQuantity& amplitude();
|
||||
const RealQuantity& amplitude() const;
|
||||
|
||||
//! Description of the time window used for amplitude
|
||||
//! measurement.
|
||||
//! Recommended for duration magnitudes.
|
||||
void setTimeWindow(const OPT(TimeWindow)& timeWindow);
|
||||
TimeWindow& timeWindow();
|
||||
const TimeWindow& timeWindow() const;
|
||||
|
||||
//! Dominant period in the timeWindow in case of amplitude
|
||||
//! measurements.
|
||||
//! Not used for duration magnitude. The unit is seconds.
|
||||
void setPeriod(const OPT(RealQuantity)& period);
|
||||
RealQuantity& period();
|
||||
const RealQuantity& period() const;
|
||||
|
||||
//! Signal-to-noise ratio of the spectrogram at the location
|
||||
//! the amplitude was measured.
|
||||
void setSnr(const OPT(double)& snr);
|
||||
double snr() const;
|
||||
|
||||
//! This attribute provides the most likely measurement units
|
||||
//! for the
|
||||
//! physical quantity described in the amplitude attribute.
|
||||
//! Possible values are specified as combinations of SI base
|
||||
//! units.
|
||||
void setUnit(const std::string& unit);
|
||||
const std::string& unit() const;
|
||||
|
||||
//! Refers to the publicID of an associated Pick object.
|
||||
void setPickID(const std::string& pickID);
|
||||
const std::string& pickID() const;
|
||||
|
||||
//! Identifies the waveform stream on which the amplitude was
|
||||
//! measured.
|
||||
void setWaveformID(const OPT(WaveformStreamID)& waveformID);
|
||||
WaveformStreamID& waveformID();
|
||||
const WaveformStreamID& waveformID() const;
|
||||
|
||||
//! Identifies the filter or filter setup used for filtering
|
||||
//! the waveform stream referenced by waveformID.
|
||||
void setFilterID(const std::string& filterID);
|
||||
const std::string& filterID() const;
|
||||
|
||||
void setMethodID(const std::string& methodID);
|
||||
const std::string& methodID() const;
|
||||
|
||||
//! Scaling time for amplitude measurement.
|
||||
void setScalingTime(const OPT(TimeQuantity)& scalingTime);
|
||||
TimeQuantity& scalingTime();
|
||||
const TimeQuantity& scalingTime() const;
|
||||
|
||||
//! Type of magnitude the amplitude measurement is used for.
|
||||
//! For valid
|
||||
//! values see class Magnitude. String value with a maximum
|
||||
//! length of
|
||||
//! 16 characters.
|
||||
void setMagnitudeHint(const std::string& magnitudeHint);
|
||||
const std::string& magnitudeHint() const;
|
||||
|
||||
//! Evaluation mode of Amplitude.
|
||||
void setEvaluationMode(const OPT(EvaluationMode)& evaluationMode);
|
||||
EvaluationMode evaluationMode() const;
|
||||
|
||||
//! CreationInfo for the Amplitude object.
|
||||
void setCreationInfo(const OPT(CreationInfo)& creationInfo);
|
||||
CreationInfo& creationInfo();
|
||||
const CreationInfo& creationInfo() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Add an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been added
|
||||
* @return false The object has not been added
|
||||
* because it already exists in the list
|
||||
* or it already has another parent
|
||||
*/
|
||||
bool add(Comment* obj);
|
||||
|
||||
/**
|
||||
* Removes an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been removed
|
||||
* @return false The object has not been removed
|
||||
* because it does not exist in the list
|
||||
*/
|
||||
bool remove(Comment* obj);
|
||||
|
||||
/**
|
||||
* Removes an object of a particular class.
|
||||
* @param i The object index
|
||||
* @return true The object has been removed
|
||||
* @return false The index is out of bounds
|
||||
*/
|
||||
bool removeComment(size_t i);
|
||||
bool removeComment(const CommentIndex& i);
|
||||
|
||||
//! Retrieve the number of objects of a particular class
|
||||
size_t commentCount() const;
|
||||
|
||||
//! Index access
|
||||
//! @return The object at index i
|
||||
Comment* comment(size_t i) const;
|
||||
Comment* comment(const CommentIndex& i) const;
|
||||
|
||||
//! Find an object by its unique attribute(s)
|
||||
|
||||
EventParameters* eventParameters() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
//! Implement PublicObject interface
|
||||
bool updateChild(Object *child) override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Attributes
|
||||
std::string _type;
|
||||
OPT(RealQuantity) _amplitude;
|
||||
OPT(TimeWindow) _timeWindow;
|
||||
OPT(RealQuantity) _period;
|
||||
OPT(double) _snr;
|
||||
std::string _unit;
|
||||
std::string _pickID;
|
||||
OPT(WaveformStreamID) _waveformID;
|
||||
std::string _filterID;
|
||||
std::string _methodID;
|
||||
OPT(TimeQuantity) _scalingTime;
|
||||
std::string _magnitudeHint;
|
||||
OPT(EvaluationMode) _evaluationMode;
|
||||
OPT(CreationInfo) _creationInfo;
|
||||
|
||||
// Aggregations
|
||||
std::vector<CommentPtr> _comments;
|
||||
|
||||
DECLARE_SC_CLASSFACTORY_FRIEND(Amplitude);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
155
include/seiscomp/datamodel/amplitudereference.h
Normal file
155
include/seiscomp/datamodel/amplitudereference.h
Normal file
@@ -0,0 +1,155 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_AMPLITUDEREFERENCE_H
|
||||
#define SEISCOMP_DATAMODEL_AMPLITUDEREFERENCE_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(AmplitudeReference);
|
||||
|
||||
class Reading;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API AmplitudeReferenceIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
AmplitudeReferenceIndex();
|
||||
AmplitudeReferenceIndex(const std::string& amplitudeID);
|
||||
|
||||
//! Copy constructor
|
||||
AmplitudeReferenceIndex(const AmplitudeReferenceIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const AmplitudeReferenceIndex&) const;
|
||||
bool operator!=(const AmplitudeReferenceIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string amplitudeID;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API AmplitudeReference : public Object {
|
||||
DECLARE_SC_CLASS(AmplitudeReference)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
AmplitudeReference();
|
||||
|
||||
//! Copy constructor
|
||||
AmplitudeReference(const AmplitudeReference& other);
|
||||
|
||||
//! Custom constructor
|
||||
AmplitudeReference(const std::string& amplitudeID);
|
||||
|
||||
//! Destructor
|
||||
~AmplitudeReference() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
AmplitudeReference& operator=(const AmplitudeReference& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const AmplitudeReference& other) const;
|
||||
bool operator!=(const AmplitudeReference& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const AmplitudeReference& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setAmplitudeID(const std::string& amplitudeID);
|
||||
const std::string& amplitudeID() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const AmplitudeReferenceIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const AmplitudeReference* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Reading* reading() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
AmplitudeReferenceIndex _index;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
160
include/seiscomp/datamodel/arclinklog.h
Normal file
160
include/seiscomp/datamodel/arclinklog.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_DATAMODEL_ARCLINKLOG_H
|
||||
#define SEISCOMP_DATAMODEL_ARCLINKLOG_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <seiscomp/datamodel/arclinkrequest.h>
|
||||
#include <seiscomp/datamodel/arclinkuser.h>
|
||||
#include <seiscomp/datamodel/notifier.h>
|
||||
#include <seiscomp/datamodel/publicobject.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ArclinkLog);
|
||||
DEFINE_SMARTPOINTER(ArclinkRequest);
|
||||
DEFINE_SMARTPOINTER(ArclinkUser);
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkLog : public PublicObject {
|
||||
DECLARE_SC_CLASS(ArclinkLog)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ArclinkLog();
|
||||
|
||||
//! Copy constructor
|
||||
ArclinkLog(const ArclinkLog& other);
|
||||
|
||||
//! Destructor
|
||||
~ArclinkLog() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
//! No changes regarding child objects are made
|
||||
ArclinkLog& operator=(const ArclinkLog& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ArclinkLog& other) const;
|
||||
bool operator!=(const ArclinkLog& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ArclinkLog& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Add an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been added
|
||||
* @return false The object has not been added
|
||||
* because it already exists in the list
|
||||
* or it already has another parent
|
||||
*/
|
||||
bool add(ArclinkRequest* obj);
|
||||
bool add(ArclinkUser* obj);
|
||||
|
||||
/**
|
||||
* Removes an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been removed
|
||||
* @return false The object has not been removed
|
||||
* because it does not exist in the list
|
||||
*/
|
||||
bool remove(ArclinkRequest* obj);
|
||||
bool remove(ArclinkUser* obj);
|
||||
|
||||
/**
|
||||
* Removes an object of a particular class.
|
||||
* @param i The object index
|
||||
* @return true The object has been removed
|
||||
* @return false The index is out of bounds
|
||||
*/
|
||||
bool removeArclinkRequest(size_t i);
|
||||
bool removeArclinkRequest(const ArclinkRequestIndex& i);
|
||||
bool removeArclinkUser(size_t i);
|
||||
bool removeArclinkUser(const ArclinkUserIndex& i);
|
||||
|
||||
//! Retrieve the number of objects of a particular class
|
||||
size_t arclinkRequestCount() const;
|
||||
size_t arclinkUserCount() const;
|
||||
|
||||
//! Index access
|
||||
//! @return The object at index i
|
||||
ArclinkRequest* arclinkRequest(size_t i) const;
|
||||
ArclinkRequest* arclinkRequest(const ArclinkRequestIndex& i) const;
|
||||
|
||||
ArclinkUser* arclinkUser(size_t i) const;
|
||||
ArclinkUser* arclinkUser(const ArclinkUserIndex& i) const;
|
||||
|
||||
//! Find an object by its unique attribute(s)
|
||||
ArclinkRequest* findArclinkRequest(const std::string& publicID) const;
|
||||
ArclinkUser* findArclinkUser(const std::string& publicID) const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
//! Implement PublicObject interface
|
||||
bool updateChild(Object *child) override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Aggregations
|
||||
std::vector<ArclinkRequestPtr> _arclinkRequests;
|
||||
std::vector<ArclinkUserPtr> _arclinkUsers;
|
||||
|
||||
DECLARE_SC_CLASSFACTORY_FRIEND(ArclinkLog);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
32
include/seiscomp/datamodel/arclinklog_package.h
Normal file
32
include/seiscomp/datamodel/arclinklog_package.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_ARCLINKLOG_PACKAGE_H__
|
||||
#define SEISCOMP_DATAMODEL_ARCLINKLOG_PACKAGE_H__
|
||||
|
||||
|
||||
#include <seiscomp/datamodel/arclinkuser.h>
|
||||
#include <seiscomp/datamodel/arclinkstatusline.h>
|
||||
#include <seiscomp/datamodel/arclinkrequestline.h>
|
||||
#include <seiscomp/datamodel/arclinkrequest.h>
|
||||
#include <seiscomp/datamodel/arclinklog.h>
|
||||
|
||||
|
||||
#endif
|
||||
284
include/seiscomp/datamodel/arclinkrequest.h
Normal file
284
include/seiscomp/datamodel/arclinkrequest.h
Normal file
@@ -0,0 +1,284 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_ARCLINKREQUEST_H
|
||||
#define SEISCOMP_DATAMODEL_ARCLINKREQUEST_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/datamodel/arclinkrequestsummary.h>
|
||||
#include <vector>
|
||||
#include <seiscomp/datamodel/arclinkstatusline.h>
|
||||
#include <seiscomp/datamodel/arclinkrequestline.h>
|
||||
#include <seiscomp/datamodel/notifier.h>
|
||||
#include <seiscomp/datamodel/publicobject.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ArclinkRequest);
|
||||
DEFINE_SMARTPOINTER(ArclinkStatusLine);
|
||||
DEFINE_SMARTPOINTER(ArclinkRequestLine);
|
||||
|
||||
class ArclinkLog;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkRequestIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ArclinkRequestIndex();
|
||||
ArclinkRequestIndex(Seiscomp::Core::Time created,
|
||||
const std::string& requestID,
|
||||
const std::string& userID);
|
||||
|
||||
//! Copy constructor
|
||||
ArclinkRequestIndex(const ArclinkRequestIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const ArclinkRequestIndex&) const;
|
||||
bool operator!=(const ArclinkRequestIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Seiscomp::Core::Time created;
|
||||
std::string requestID;
|
||||
std::string userID;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkRequest : public PublicObject {
|
||||
DECLARE_SC_CLASS(ArclinkRequest)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Protected constructor
|
||||
ArclinkRequest();
|
||||
|
||||
public:
|
||||
//! Copy constructor
|
||||
ArclinkRequest(const ArclinkRequest& other);
|
||||
|
||||
//! Constructor with publicID
|
||||
ArclinkRequest(const std::string& publicID);
|
||||
|
||||
//! Destructor
|
||||
~ArclinkRequest() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Creators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static ArclinkRequest* Create();
|
||||
static ArclinkRequest* Create(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Lookup
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static ArclinkRequest* Find(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
//! No changes regarding child objects are made
|
||||
ArclinkRequest& operator=(const ArclinkRequest& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ArclinkRequest& other) const;
|
||||
bool operator!=(const ArclinkRequest& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ArclinkRequest& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setRequestID(const std::string& requestID);
|
||||
const std::string& requestID() const;
|
||||
|
||||
void setUserID(const std::string& userID);
|
||||
const std::string& userID() const;
|
||||
|
||||
void setUserIP(const std::string& userIP);
|
||||
const std::string& userIP() const;
|
||||
|
||||
void setClientID(const std::string& clientID);
|
||||
const std::string& clientID() const;
|
||||
|
||||
void setClientIP(const std::string& clientIP);
|
||||
const std::string& clientIP() const;
|
||||
|
||||
void setType(const std::string& type);
|
||||
const std::string& type() const;
|
||||
|
||||
void setCreated(Seiscomp::Core::Time created);
|
||||
Seiscomp::Core::Time created() const;
|
||||
|
||||
void setStatus(const std::string& status);
|
||||
const std::string& status() const;
|
||||
|
||||
void setMessage(const std::string& message);
|
||||
const std::string& message() const;
|
||||
|
||||
void setLabel(const std::string& label);
|
||||
const std::string& label() const;
|
||||
|
||||
void setHeader(const std::string& header);
|
||||
const std::string& header() const;
|
||||
|
||||
void setSummary(const OPT(ArclinkRequestSummary)& summary);
|
||||
ArclinkRequestSummary& summary();
|
||||
const ArclinkRequestSummary& summary() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const ArclinkRequestIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const ArclinkRequest* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Add an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been added
|
||||
* @return false The object has not been added
|
||||
* because it already exists in the list
|
||||
* or it already has another parent
|
||||
*/
|
||||
bool add(ArclinkStatusLine* obj);
|
||||
bool add(ArclinkRequestLine* obj);
|
||||
|
||||
/**
|
||||
* Removes an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been removed
|
||||
* @return false The object has not been removed
|
||||
* because it does not exist in the list
|
||||
*/
|
||||
bool remove(ArclinkStatusLine* obj);
|
||||
bool remove(ArclinkRequestLine* obj);
|
||||
|
||||
/**
|
||||
* Removes an object of a particular class.
|
||||
* @param i The object index
|
||||
* @return true The object has been removed
|
||||
* @return false The index is out of bounds
|
||||
*/
|
||||
bool removeArclinkStatusLine(size_t i);
|
||||
bool removeArclinkStatusLine(const ArclinkStatusLineIndex& i);
|
||||
bool removeArclinkRequestLine(size_t i);
|
||||
bool removeArclinkRequestLine(const ArclinkRequestLineIndex& i);
|
||||
|
||||
//! Retrieve the number of objects of a particular class
|
||||
size_t arclinkStatusLineCount() const;
|
||||
size_t arclinkRequestLineCount() const;
|
||||
|
||||
//! Index access
|
||||
//! @return The object at index i
|
||||
ArclinkStatusLine* arclinkStatusLine(size_t i) const;
|
||||
ArclinkStatusLine* arclinkStatusLine(const ArclinkStatusLineIndex& i) const;
|
||||
|
||||
ArclinkRequestLine* arclinkRequestLine(size_t i) const;
|
||||
ArclinkRequestLine* arclinkRequestLine(const ArclinkRequestLineIndex& i) const;
|
||||
|
||||
//! Find an object by its unique attribute(s)
|
||||
|
||||
ArclinkLog* arclinkLog() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
//! Implement PublicObject interface
|
||||
bool updateChild(Object *child) override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
ArclinkRequestIndex _index;
|
||||
|
||||
// Attributes
|
||||
std::string _userIP;
|
||||
std::string _clientID;
|
||||
std::string _clientIP;
|
||||
std::string _type;
|
||||
std::string _status;
|
||||
std::string _message;
|
||||
std::string _label;
|
||||
std::string _header;
|
||||
OPT(ArclinkRequestSummary) _summary;
|
||||
|
||||
// Aggregations
|
||||
std::vector<ArclinkStatusLinePtr> _arclinkStatusLines;
|
||||
std::vector<ArclinkRequestLinePtr> _arclinkRequestLines;
|
||||
|
||||
DECLARE_SC_CLASSFACTORY_FRIEND(ArclinkRequest);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
189
include/seiscomp/datamodel/arclinkrequestline.h
Normal file
189
include/seiscomp/datamodel/arclinkrequestline.h
Normal file
@@ -0,0 +1,189 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_ARCLINKREQUESTLINE_H
|
||||
#define SEISCOMP_DATAMODEL_ARCLINKREQUESTLINE_H
|
||||
|
||||
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/datamodel/waveformstreamid.h>
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/arclinkstatusline.h>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ArclinkRequestLine);
|
||||
|
||||
class ArclinkRequest;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkRequestLineIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ArclinkRequestLineIndex();
|
||||
ArclinkRequestLineIndex(Seiscomp::Core::Time start,
|
||||
Seiscomp::Core::Time end,
|
||||
const WaveformStreamID& streamID);
|
||||
|
||||
//! Copy constructor
|
||||
ArclinkRequestLineIndex(const ArclinkRequestLineIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const ArclinkRequestLineIndex&) const;
|
||||
bool operator!=(const ArclinkRequestLineIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Seiscomp::Core::Time start;
|
||||
Seiscomp::Core::Time end;
|
||||
WaveformStreamID streamID;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkRequestLine : public Object {
|
||||
DECLARE_SC_CLASS(ArclinkRequestLine)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ArclinkRequestLine();
|
||||
|
||||
//! Copy constructor
|
||||
ArclinkRequestLine(const ArclinkRequestLine& other);
|
||||
|
||||
//! Destructor
|
||||
~ArclinkRequestLine() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
ArclinkRequestLine& operator=(const ArclinkRequestLine& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ArclinkRequestLine& other) const;
|
||||
bool operator!=(const ArclinkRequestLine& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ArclinkRequestLine& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setStart(Seiscomp::Core::Time start);
|
||||
Seiscomp::Core::Time start() const;
|
||||
|
||||
void setEnd(Seiscomp::Core::Time end);
|
||||
Seiscomp::Core::Time end() const;
|
||||
|
||||
void setStreamID(const WaveformStreamID& streamID);
|
||||
WaveformStreamID& streamID();
|
||||
const WaveformStreamID& streamID() const;
|
||||
|
||||
void setRestricted(const OPT(bool)& restricted);
|
||||
bool restricted() const;
|
||||
|
||||
void setShared(const OPT(bool)& shared);
|
||||
bool shared() const;
|
||||
|
||||
void setNetClass(const std::string& netClass);
|
||||
const std::string& netClass() const;
|
||||
|
||||
void setConstraints(const std::string& constraints);
|
||||
const std::string& constraints() const;
|
||||
|
||||
void setStatus(const ArclinkStatusLine& status);
|
||||
ArclinkStatusLine& status();
|
||||
ArclinkStatusLine status() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const ArclinkRequestLineIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const ArclinkRequestLine* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
ArclinkRequest* arclinkRequest() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
ArclinkRequestLineIndex _index;
|
||||
|
||||
// Attributes
|
||||
OPT(bool) _restricted;
|
||||
OPT(bool) _shared;
|
||||
std::string _netClass;
|
||||
std::string _constraints;
|
||||
ArclinkStatusLine _status;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
100
include/seiscomp/datamodel/arclinkrequestsummary.h
Normal file
100
include/seiscomp/datamodel/arclinkrequestsummary.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_ARCLINKREQUESTSUMMARY_H
|
||||
#define SEISCOMP_DATAMODEL_ARCLINKREQUESTSUMMARY_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ArclinkRequestSummary);
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkRequestSummary : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(ArclinkRequestSummary)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ArclinkRequestSummary();
|
||||
|
||||
//! Copy constructor
|
||||
ArclinkRequestSummary(const ArclinkRequestSummary& other);
|
||||
|
||||
//! Destructor
|
||||
~ArclinkRequestSummary() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
ArclinkRequestSummary& operator=(const ArclinkRequestSummary& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ArclinkRequestSummary& other) const;
|
||||
bool operator!=(const ArclinkRequestSummary& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ArclinkRequestSummary& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setOkLineCount(int okLineCount);
|
||||
int okLineCount() const;
|
||||
|
||||
void setTotalLineCount(int totalLineCount);
|
||||
int totalLineCount() const;
|
||||
|
||||
void setAverageTimeWindow(int averageTimeWindow);
|
||||
int averageTimeWindow() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Attributes
|
||||
int _okLineCount;
|
||||
int _totalLineCount;
|
||||
int _averageTimeWindow;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
172
include/seiscomp/datamodel/arclinkstatusline.h
Normal file
172
include/seiscomp/datamodel/arclinkstatusline.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_DATAMODEL_ARCLINKSTATUSLINE_H
|
||||
#define SEISCOMP_DATAMODEL_ARCLINKSTATUSLINE_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ArclinkStatusLine);
|
||||
|
||||
class ArclinkRequest;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkStatusLineIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ArclinkStatusLineIndex();
|
||||
ArclinkStatusLineIndex(const std::string& volumeID,
|
||||
const std::string& type,
|
||||
const std::string& status);
|
||||
|
||||
//! Copy constructor
|
||||
ArclinkStatusLineIndex(const ArclinkStatusLineIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const ArclinkStatusLineIndex&) const;
|
||||
bool operator!=(const ArclinkStatusLineIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string volumeID;
|
||||
std::string type;
|
||||
std::string status;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkStatusLine : public Object {
|
||||
DECLARE_SC_CLASS(ArclinkStatusLine)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ArclinkStatusLine();
|
||||
|
||||
//! Copy constructor
|
||||
ArclinkStatusLine(const ArclinkStatusLine& other);
|
||||
|
||||
//! Destructor
|
||||
~ArclinkStatusLine() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
ArclinkStatusLine& operator=(const ArclinkStatusLine& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ArclinkStatusLine& other) const;
|
||||
bool operator!=(const ArclinkStatusLine& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ArclinkStatusLine& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setType(const std::string& type);
|
||||
const std::string& type() const;
|
||||
|
||||
void setStatus(const std::string& status);
|
||||
const std::string& status() const;
|
||||
|
||||
void setSize(const OPT(int)& size);
|
||||
int size() const;
|
||||
|
||||
void setMessage(const std::string& message);
|
||||
const std::string& message() const;
|
||||
|
||||
void setVolumeID(const std::string& volumeID);
|
||||
const std::string& volumeID() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const ArclinkStatusLineIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const ArclinkStatusLine* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
ArclinkRequest* arclinkRequest() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
ArclinkStatusLineIndex _index;
|
||||
|
||||
// Attributes
|
||||
OPT(int) _size;
|
||||
std::string _message;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
188
include/seiscomp/datamodel/arclinkuser.h
Normal file
188
include/seiscomp/datamodel/arclinkuser.h
Normal file
@@ -0,0 +1,188 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_ARCLINKUSER_H
|
||||
#define SEISCOMP_DATAMODEL_ARCLINKUSER_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/publicobject.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ArclinkUser);
|
||||
|
||||
class ArclinkLog;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkUserIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ArclinkUserIndex();
|
||||
ArclinkUserIndex(const std::string& name,
|
||||
const std::string& email);
|
||||
|
||||
//! Copy constructor
|
||||
ArclinkUserIndex(const ArclinkUserIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const ArclinkUserIndex&) const;
|
||||
bool operator!=(const ArclinkUserIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string name;
|
||||
std::string email;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkUser : public PublicObject {
|
||||
DECLARE_SC_CLASS(ArclinkUser)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Protected constructor
|
||||
ArclinkUser();
|
||||
|
||||
public:
|
||||
//! Copy constructor
|
||||
ArclinkUser(const ArclinkUser& other);
|
||||
|
||||
//! Constructor with publicID
|
||||
ArclinkUser(const std::string& publicID);
|
||||
|
||||
//! Destructor
|
||||
~ArclinkUser() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Creators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static ArclinkUser* Create();
|
||||
static ArclinkUser* Create(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Lookup
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static ArclinkUser* Find(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
//! No changes regarding child objects are made
|
||||
ArclinkUser& operator=(const ArclinkUser& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ArclinkUser& other) const;
|
||||
bool operator!=(const ArclinkUser& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ArclinkUser& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setName(const std::string& name);
|
||||
const std::string& name() const;
|
||||
|
||||
void setEmail(const std::string& email);
|
||||
const std::string& email() const;
|
||||
|
||||
void setPassword(const std::string& password);
|
||||
const std::string& password() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const ArclinkUserIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const ArclinkUser* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
ArclinkLog* arclinkLog() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
//! Implement PublicObject interface
|
||||
bool updateChild(Object *child) override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
ArclinkUserIndex _index;
|
||||
|
||||
// Attributes
|
||||
std::string _password;
|
||||
|
||||
DECLARE_SC_CLASSFACTORY_FRIEND(ArclinkUser);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
278
include/seiscomp/datamodel/arrival.h
Normal file
278
include/seiscomp/datamodel/arrival.h
Normal file
@@ -0,0 +1,278 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_ARRIVAL_H
|
||||
#define SEISCOMP_DATAMODEL_ARRIVAL_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/phase.h>
|
||||
#include <seiscomp/datamodel/creationinfo.h>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Arrival);
|
||||
|
||||
class Origin;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArrivalIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ArrivalIndex();
|
||||
ArrivalIndex(const std::string& pickID);
|
||||
|
||||
//! Copy constructor
|
||||
ArrivalIndex(const ArrivalIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const ArrivalIndex&) const;
|
||||
bool operator!=(const ArrivalIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string pickID;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Successful association of a pick with an origin qualifies
|
||||
* \brief this pick as
|
||||
* \brief an arrival. An arrival thus connects a pick with an origin
|
||||
* \brief and provides
|
||||
* \brief additional attributes that describe this relationship.
|
||||
* \brief Usually qualification
|
||||
* \brief of a pick as an arrival for a given origin is a hypothesis,
|
||||
* \brief which is
|
||||
* \brief based on assumptions about the type of arrival (phase) as
|
||||
* \brief well as
|
||||
* \brief observed and (on the basis of an earth model) computed
|
||||
* \brief arrival times,
|
||||
* \brief or the residual, respectively. Additional pick attributes
|
||||
* \brief like the
|
||||
* \brief horizontal slowness and backazimuth of the observed
|
||||
* \brief wave-especially if
|
||||
* \brief derived from array data-may further constrain the nature of
|
||||
* \brief the arrival.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API Arrival : public Object {
|
||||
DECLARE_SC_CLASS(Arrival)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
Arrival();
|
||||
|
||||
//! Copy constructor
|
||||
Arrival(const Arrival& other);
|
||||
|
||||
//! Destructor
|
||||
~Arrival() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
Arrival& operator=(const Arrival& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const Arrival& other) const;
|
||||
bool operator!=(const Arrival& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const Arrival& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Refers to a publicID of a Pick.
|
||||
void setPickID(const std::string& pickID);
|
||||
const std::string& pickID() const;
|
||||
|
||||
//! Phase identification. For possible values, please refer to
|
||||
//! the description of the Phase type.
|
||||
void setPhase(const Phase& phase);
|
||||
Phase& phase();
|
||||
const Phase& phase() const;
|
||||
|
||||
//! Time correction value. Usually, a value characteristic for
|
||||
//! the station
|
||||
//! at which the pick was detected, sometimes also
|
||||
//! characteristic for the
|
||||
//! phase type or the slowness in seconds.
|
||||
void setTimeCorrection(const OPT(double)& timeCorrection);
|
||||
double timeCorrection() const;
|
||||
|
||||
//! Azimuth of station as seen from the epicenter in degrees.
|
||||
void setAzimuth(const OPT(double)& azimuth);
|
||||
double azimuth() const;
|
||||
|
||||
//! Epicentral distance in degrees.
|
||||
void setDistance(const OPT(double)& distance);
|
||||
double distance() const;
|
||||
|
||||
//! Angle of emerging ray at the source, measured against the
|
||||
//! downward
|
||||
//! normal direction in degrees.
|
||||
void setTakeOffAngle(const OPT(double)& takeOffAngle);
|
||||
double takeOffAngle() const;
|
||||
|
||||
//! Residual between observed and expected arrival time
|
||||
//! assuming proper
|
||||
//! phase identification and given the earthModelID of the
|
||||
//! Origin,
|
||||
//! taking into account the timeCorrection in seconds.
|
||||
void setTimeResidual(const OPT(double)& timeResidual);
|
||||
double timeResidual() const;
|
||||
|
||||
//! Residual of horizontal slowness and the expected slowness
|
||||
//! given the
|
||||
//! current origin (refers to attribute horizontalSlowness of
|
||||
//! class Pick)
|
||||
//! in s/deg.
|
||||
void setHorizontalSlownessResidual(const OPT(double)& horizontalSlownessResidual);
|
||||
double horizontalSlownessResidual() const;
|
||||
|
||||
//! Residual of backazimuth and the backazimuth computed for
|
||||
//! the current
|
||||
//! origin (refers to attribute backazimuth of class Pick) in
|
||||
//! degrees.
|
||||
void setBackazimuthResidual(const OPT(double)& backazimuthResidual);
|
||||
double backazimuthResidual() const;
|
||||
|
||||
void setTimeUsed(const OPT(bool)& timeUsed);
|
||||
bool timeUsed() const;
|
||||
|
||||
//! Weight of the horizontal slowness for computation of the
|
||||
//! associated Origin.
|
||||
//! Note that the sum of all weights is not required to be
|
||||
//! unity.
|
||||
void setHorizontalSlownessUsed(const OPT(bool)& horizontalSlownessUsed);
|
||||
bool horizontalSlownessUsed() const;
|
||||
|
||||
void setBackazimuthUsed(const OPT(bool)& backazimuthUsed);
|
||||
bool backazimuthUsed() const;
|
||||
|
||||
//! Weight of the arrival time for computation of the
|
||||
//! associated Origin.
|
||||
//! Note that the sum of all weights is not required to be
|
||||
//! unity.
|
||||
void setWeight(const OPT(double)& weight);
|
||||
double weight() const;
|
||||
|
||||
//! Earth model which is used for the association of Arrival to
|
||||
//! Pick and computation of the
|
||||
//! residuals.
|
||||
void setEarthModelID(const std::string& earthModelID);
|
||||
const std::string& earthModelID() const;
|
||||
|
||||
//! Indicates if the arrival is preliminary.
|
||||
void setPreliminary(const OPT(bool)& preliminary);
|
||||
bool preliminary() const;
|
||||
|
||||
//! CreationInfo for the Arrival object.
|
||||
void setCreationInfo(const OPT(CreationInfo)& creationInfo);
|
||||
CreationInfo& creationInfo();
|
||||
const CreationInfo& creationInfo() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const ArrivalIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const Arrival* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Origin* origin() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
ArrivalIndex _index;
|
||||
|
||||
// Attributes
|
||||
Phase _phase;
|
||||
OPT(double) _timeCorrection;
|
||||
OPT(double) _azimuth;
|
||||
OPT(double) _distance;
|
||||
OPT(double) _takeOffAngle;
|
||||
OPT(double) _timeResidual;
|
||||
OPT(double) _horizontalSlownessResidual;
|
||||
OPT(double) _backazimuthResidual;
|
||||
OPT(bool) _timeUsed;
|
||||
OPT(bool) _horizontalSlownessUsed;
|
||||
OPT(bool) _backazimuthUsed;
|
||||
OPT(double) _weight;
|
||||
std::string _earthModelID;
|
||||
OPT(bool) _preliminary;
|
||||
OPT(CreationInfo) _creationInfo;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
249
include/seiscomp/datamodel/auxdevice.h
Normal file
249
include/seiscomp/datamodel/auxdevice.h
Normal file
@@ -0,0 +1,249 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_AUXDEVICE_H
|
||||
#define SEISCOMP_DATAMODEL_AUXDEVICE_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/blob.h>
|
||||
#include <vector>
|
||||
#include <seiscomp/datamodel/auxsource.h>
|
||||
#include <seiscomp/datamodel/notifier.h>
|
||||
#include <seiscomp/datamodel/publicobject.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(AuxDevice);
|
||||
DEFINE_SMARTPOINTER(AuxSource);
|
||||
|
||||
class Inventory;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API AuxDeviceIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
AuxDeviceIndex();
|
||||
AuxDeviceIndex(const std::string& name);
|
||||
|
||||
//! Copy constructor
|
||||
AuxDeviceIndex(const AuxDeviceIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const AuxDeviceIndex&) const;
|
||||
bool operator!=(const AuxDeviceIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief This type describes an auxiliary device
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API AuxDevice : public PublicObject {
|
||||
DECLARE_SC_CLASS(AuxDevice)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Protected constructor
|
||||
AuxDevice();
|
||||
|
||||
public:
|
||||
//! Copy constructor
|
||||
AuxDevice(const AuxDevice& other);
|
||||
|
||||
//! Constructor with publicID
|
||||
AuxDevice(const std::string& publicID);
|
||||
|
||||
//! Destructor
|
||||
~AuxDevice() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Creators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static AuxDevice* Create();
|
||||
static AuxDevice* Create(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Lookup
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static AuxDevice* Find(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
//! No changes regarding child objects are made
|
||||
AuxDevice& operator=(const AuxDevice& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const AuxDevice& other) const;
|
||||
bool operator!=(const AuxDevice& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const AuxDevice& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Unique device name
|
||||
void setName(const std::string& name);
|
||||
const std::string& name() const;
|
||||
|
||||
//! Device description
|
||||
void setDescription(const std::string& description);
|
||||
const std::string& description() const;
|
||||
|
||||
//! Device model
|
||||
void setModel(const std::string& model);
|
||||
const std::string& model() const;
|
||||
|
||||
//! Device manufacturer
|
||||
void setManufacturer(const std::string& manufacturer);
|
||||
const std::string& manufacturer() const;
|
||||
|
||||
void setRemark(const OPT(Blob)& remark);
|
||||
Blob& remark();
|
||||
const Blob& remark() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const AuxDeviceIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const AuxDevice* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Add an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been added
|
||||
* @return false The object has not been added
|
||||
* because it already exists in the list
|
||||
* or it already has another parent
|
||||
*/
|
||||
bool add(AuxSource* obj);
|
||||
|
||||
/**
|
||||
* Removes an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been removed
|
||||
* @return false The object has not been removed
|
||||
* because it does not exist in the list
|
||||
*/
|
||||
bool remove(AuxSource* obj);
|
||||
|
||||
/**
|
||||
* Removes an object of a particular class.
|
||||
* @param i The object index
|
||||
* @return true The object has been removed
|
||||
* @return false The index is out of bounds
|
||||
*/
|
||||
bool removeAuxSource(size_t i);
|
||||
bool removeAuxSource(const AuxSourceIndex& i);
|
||||
|
||||
//! Retrieve the number of objects of a particular class
|
||||
size_t auxSourceCount() const;
|
||||
|
||||
//! Index access
|
||||
//! @return The object at index i
|
||||
AuxSource* auxSource(size_t i) const;
|
||||
AuxSource* auxSource(const AuxSourceIndex& i) const;
|
||||
|
||||
//! Find an object by its unique attribute(s)
|
||||
|
||||
Inventory* inventory() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
//! Implement PublicObject interface
|
||||
bool updateChild(Object *child) override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
AuxDeviceIndex _index;
|
||||
|
||||
// Attributes
|
||||
std::string _description;
|
||||
std::string _model;
|
||||
std::string _manufacturer;
|
||||
OPT(Blob) _remark;
|
||||
|
||||
// Aggregations
|
||||
std::vector<AuxSourcePtr> _auxSources;
|
||||
|
||||
DECLARE_SC_CLASSFACTORY_FRIEND(AuxDevice);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
201
include/seiscomp/datamodel/auxsource.h
Normal file
201
include/seiscomp/datamodel/auxsource.h
Normal file
@@ -0,0 +1,201 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_AUXSOURCE_H
|
||||
#define SEISCOMP_DATAMODEL_AUXSOURCE_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/blob.h>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(AuxSource);
|
||||
|
||||
class AuxDevice;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API AuxSourceIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
AuxSourceIndex();
|
||||
AuxSourceIndex(const std::string& name);
|
||||
|
||||
//! Copy constructor
|
||||
AuxSourceIndex(const AuxSourceIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const AuxSourceIndex&) const;
|
||||
bool operator!=(const AuxSourceIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief This type describes a channel of an auxiliary device
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API AuxSource : public Object {
|
||||
DECLARE_SC_CLASS(AuxSource)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
AuxSource();
|
||||
|
||||
//! Copy constructor
|
||||
AuxSource(const AuxSource& other);
|
||||
|
||||
//! Custom constructor
|
||||
AuxSource(const std::string& name);
|
||||
AuxSource(const std::string& name,
|
||||
const std::string& description,
|
||||
const std::string& unit,
|
||||
const std::string& conversion,
|
||||
const OPT(int)& sampleRateNumerator = Seiscomp::Core::None,
|
||||
const OPT(int)& sampleRateDenominator = Seiscomp::Core::None,
|
||||
const OPT(Blob)& remark = Seiscomp::Core::None);
|
||||
|
||||
//! Destructor
|
||||
~AuxSource() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
AuxSource& operator=(const AuxSource& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const AuxSource& other) const;
|
||||
bool operator!=(const AuxSource& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const AuxSource& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Referred from network/station/auxStream/@source
|
||||
void setName(const std::string& name);
|
||||
const std::string& name() const;
|
||||
|
||||
//! Description
|
||||
void setDescription(const std::string& description);
|
||||
const std::string& description() const;
|
||||
|
||||
//! Unit of mesurement
|
||||
void setUnit(const std::string& unit);
|
||||
const std::string& unit() const;
|
||||
|
||||
//! Conversion formula from counts to unit of measurement
|
||||
void setConversion(const std::string& conversion);
|
||||
const std::string& conversion() const;
|
||||
|
||||
//! Output sample rate (numerator); referred from
|
||||
//! network/station/AuxStream/@sampleRateNumerator
|
||||
void setSampleRateNumerator(const OPT(int)& sampleRateNumerator);
|
||||
int sampleRateNumerator() const;
|
||||
|
||||
//! Output sample rate (denominator); referred from
|
||||
//! network/station/AuxStream/@sampleRateDenominator
|
||||
void setSampleRateDenominator(const OPT(int)& sampleRateDenominator);
|
||||
int sampleRateDenominator() const;
|
||||
|
||||
void setRemark(const OPT(Blob)& remark);
|
||||
Blob& remark();
|
||||
const Blob& remark() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const AuxSourceIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const AuxSource* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
AuxDevice* auxDevice() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
AuxSourceIndex _index;
|
||||
|
||||
// Attributes
|
||||
std::string _description;
|
||||
std::string _unit;
|
||||
std::string _conversion;
|
||||
OPT(int) _sampleRateNumerator;
|
||||
OPT(int) _sampleRateDenominator;
|
||||
OPT(Blob) _remark;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
207
include/seiscomp/datamodel/auxstream.h
Normal file
207
include/seiscomp/datamodel/auxstream.h
Normal file
@@ -0,0 +1,207 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_AUXSTREAM_H
|
||||
#define SEISCOMP_DATAMODEL_AUXSTREAM_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(AuxStream);
|
||||
|
||||
class SensorLocation;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API AuxStreamIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
AuxStreamIndex();
|
||||
AuxStreamIndex(const std::string& code,
|
||||
Seiscomp::Core::Time start);
|
||||
|
||||
//! Copy constructor
|
||||
AuxStreamIndex(const AuxStreamIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const AuxStreamIndex&) const;
|
||||
bool operator!=(const AuxStreamIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string code;
|
||||
Seiscomp::Core::Time start;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief This type describes a stream (channel) without defined
|
||||
* \brief frequency response
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API AuxStream : public Object {
|
||||
DECLARE_SC_CLASS(AuxStream)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
AuxStream();
|
||||
|
||||
//! Copy constructor
|
||||
AuxStream(const AuxStream& other);
|
||||
|
||||
//! Destructor
|
||||
~AuxStream() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
AuxStream& operator=(const AuxStream& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const AuxStream& other) const;
|
||||
bool operator!=(const AuxStream& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const AuxStream& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Stream code (52.04)
|
||||
void setCode(const std::string& code);
|
||||
const std::string& code() const;
|
||||
|
||||
//! Start of epoch in ISO datetime format (52.22)
|
||||
void setStart(Seiscomp::Core::Time start);
|
||||
Seiscomp::Core::Time start() const;
|
||||
|
||||
//! End of epoch (52.23)
|
||||
void setEnd(const OPT(Seiscomp::Core::Time)& end);
|
||||
Seiscomp::Core::Time end() const;
|
||||
|
||||
//! Reference to auxDevice/@publicID
|
||||
void setDevice(const std::string& device);
|
||||
const std::string& device() const;
|
||||
|
||||
//! Serial number of device
|
||||
void setDeviceSerialNumber(const std::string& deviceSerialNumber);
|
||||
const std::string& deviceSerialNumber() const;
|
||||
|
||||
//! Reference to auxSource/@name
|
||||
void setSource(const std::string& source);
|
||||
const std::string& source() const;
|
||||
|
||||
//! Data format, eg.: "steim1", "steim2", "mseedN" (N =
|
||||
//! encoding format in blockette 1000)
|
||||
void setFormat(const std::string& format);
|
||||
const std::string& format() const;
|
||||
|
||||
//! Channel flags (52.21)
|
||||
void setFlags(const std::string& flags);
|
||||
const std::string& flags() const;
|
||||
|
||||
//! Whether the stream is "restricted"
|
||||
void setRestricted(const OPT(bool)& restricted);
|
||||
bool restricted() const;
|
||||
|
||||
//! Whether the metadata is synchronized with other datacenters
|
||||
void setShared(const OPT(bool)& shared);
|
||||
bool shared() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const AuxStreamIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const AuxStream* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SensorLocation* sensorLocation() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
AuxStreamIndex _index;
|
||||
|
||||
// Attributes
|
||||
OPT(Seiscomp::Core::Time) _end;
|
||||
std::string _device;
|
||||
std::string _deviceSerialNumber;
|
||||
std::string _source;
|
||||
std::string _format;
|
||||
std::string _flags;
|
||||
OPT(bool) _restricted;
|
||||
OPT(bool) _shared;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
119
include/seiscomp/datamodel/axis.h
Normal file
119
include/seiscomp/datamodel/axis.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_AXIS_H
|
||||
#define SEISCOMP_DATAMODEL_AXIS_H
|
||||
|
||||
|
||||
#include <seiscomp/datamodel/realquantity.h>
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Axis);
|
||||
|
||||
|
||||
/**
|
||||
* \brief This class describes an eigenvector of a moment tensor
|
||||
* \brief expressed in its
|
||||
* \brief principal-axes system. It uses the angles azimuth, plunge,
|
||||
* \brief and the
|
||||
* \brief eigenvalue length.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API Axis : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(Axis)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
Axis();
|
||||
|
||||
//! Copy constructor
|
||||
Axis(const Axis& other);
|
||||
|
||||
//! Destructor
|
||||
~Axis() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
Axis& operator=(const Axis& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const Axis& other) const;
|
||||
bool operator!=(const Axis& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const Axis& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Azimuth of eigenvector of moment tensor expressed in
|
||||
//! principal-axes system. Measured clockwise
|
||||
//! from South-North direction at epicenter in degrees.
|
||||
void setAzimuth(const RealQuantity& azimuth);
|
||||
RealQuantity& azimuth();
|
||||
const RealQuantity& azimuth() const;
|
||||
|
||||
//! Plunge of eigenvector of moment tensor expressed in
|
||||
//! principal-axes system. Measured against downward
|
||||
//! vertical direction at epicenter in degrees.
|
||||
void setPlunge(const RealQuantity& plunge);
|
||||
RealQuantity& plunge();
|
||||
const RealQuantity& plunge() const;
|
||||
|
||||
//! Eigenvalue of moment tensor expressed in principal-axes
|
||||
//! system in Nm.
|
||||
void setLength(const RealQuantity& length);
|
||||
RealQuantity& length();
|
||||
const RealQuantity& length() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Attributes
|
||||
RealQuantity _azimuth;
|
||||
RealQuantity _plunge;
|
||||
RealQuantity _length;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
93
include/seiscomp/datamodel/blob.h
Normal file
93
include/seiscomp/datamodel/blob.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_BLOB_H
|
||||
#define SEISCOMP_DATAMODEL_BLOB_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Blob);
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Blob : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(Blob)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
Blob();
|
||||
|
||||
//! Copy constructor
|
||||
Blob(const Blob& other);
|
||||
|
||||
//! Destructor
|
||||
~Blob() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
Blob& operator=(const Blob& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const Blob& other) const;
|
||||
bool operator!=(const Blob& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const Blob& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setContent(const std::string& content);
|
||||
const std::string& content() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Attributes
|
||||
std::string _content;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
213
include/seiscomp/datamodel/comment.h
Normal file
213
include/seiscomp/datamodel/comment.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_DATAMODEL_COMMENT_H
|
||||
#define SEISCOMP_DATAMODEL_COMMENT_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/datamodel/creationinfo.h>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Comment);
|
||||
|
||||
class MomentTensor;
|
||||
class FocalMechanism;
|
||||
class Amplitude;
|
||||
class Magnitude;
|
||||
class StationMagnitude;
|
||||
class Pick;
|
||||
class Event;
|
||||
class Origin;
|
||||
class Parameter;
|
||||
class ParameterSet;
|
||||
class Stream;
|
||||
class SensorLocation;
|
||||
class Station;
|
||||
class Network;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API CommentIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
CommentIndex();
|
||||
CommentIndex(const std::string& id);
|
||||
|
||||
//! Copy constructor
|
||||
CommentIndex(const CommentIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const CommentIndex&) const;
|
||||
bool operator!=(const CommentIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string id;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Comment holds information on comments to a resource as well
|
||||
* \brief as author and creation time information.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API Comment : public Object {
|
||||
DECLARE_SC_CLASS(Comment)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
Comment();
|
||||
|
||||
//! Copy constructor
|
||||
Comment(const Comment& other);
|
||||
|
||||
//! Destructor
|
||||
~Comment() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
Comment& operator=(const Comment& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const Comment& other) const;
|
||||
bool operator!=(const Comment& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const Comment& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Text of comment.
|
||||
void setText(const std::string& text);
|
||||
const std::string& text() const;
|
||||
|
||||
//! Identifier of comment, possibly in QuakeML RI format.
|
||||
void setId(const std::string& id);
|
||||
const std::string& id() const;
|
||||
|
||||
//! Start of epoch in ISO datetime format
|
||||
void setStart(const OPT(Seiscomp::Core::Time)& start);
|
||||
Seiscomp::Core::Time start() const;
|
||||
|
||||
//! End of epoch (empty if the comment epoch is open)
|
||||
void setEnd(const OPT(Seiscomp::Core::Time)& end);
|
||||
Seiscomp::Core::Time end() const;
|
||||
|
||||
//! CreationInfo for the Comment object.
|
||||
void setCreationInfo(const OPT(CreationInfo)& creationInfo);
|
||||
CreationInfo& creationInfo();
|
||||
const CreationInfo& creationInfo() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const CommentIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const Comment* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* The following methods return the parent object by type.
|
||||
* Because different parent types are possible, just one
|
||||
* of these methods will return a valid pointer at a time.
|
||||
*/
|
||||
MomentTensor* momentTensor() const;
|
||||
FocalMechanism* focalMechanism() const;
|
||||
Amplitude* amplitude() const;
|
||||
Magnitude* magnitude() const;
|
||||
StationMagnitude* stationMagnitude() const;
|
||||
Pick* pick() const;
|
||||
Event* event() const;
|
||||
Origin* origin() const;
|
||||
Parameter* parameter() const;
|
||||
ParameterSet* parameterSet() const;
|
||||
Stream* stream() const;
|
||||
SensorLocation* sensorLocation() const;
|
||||
Station* station() const;
|
||||
Network* network() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
CommentIndex _index;
|
||||
|
||||
// Attributes
|
||||
std::string _text;
|
||||
OPT(Seiscomp::Core::Time) _start;
|
||||
OPT(Seiscomp::Core::Time) _end;
|
||||
OPT(CreationInfo) _creationInfo;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
95
include/seiscomp/datamodel/complexarray.h
Normal file
95
include/seiscomp/datamodel/complexarray.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_COMPLEXARRAY_H
|
||||
#define SEISCOMP_DATAMODEL_COMPLEXARRAY_H
|
||||
|
||||
|
||||
#include <complex>
|
||||
#include <vector>
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ComplexArray);
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ComplexArray : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(ComplexArray)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ComplexArray();
|
||||
|
||||
//! Copy constructor
|
||||
ComplexArray(const ComplexArray& other);
|
||||
|
||||
//! Destructor
|
||||
~ComplexArray() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
ComplexArray& operator=(const ComplexArray& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ComplexArray& other) const;
|
||||
bool operator!=(const ComplexArray& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ComplexArray& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setContent(const std::vector< std::complex<double> >&);
|
||||
const std::vector< std::complex<double> >& content() const;
|
||||
std::vector< std::complex<double> >& content();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Attributes
|
||||
std::vector< std::complex<double> > _content;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
179
include/seiscomp/datamodel/compositetime.h
Normal file
179
include/seiscomp/datamodel/compositetime.h
Normal file
@@ -0,0 +1,179 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_COMPOSITETIME_H
|
||||
#define SEISCOMP_DATAMODEL_COMPOSITETIME_H
|
||||
|
||||
|
||||
#include <seiscomp/datamodel/integerquantity.h>
|
||||
#include <seiscomp/datamodel/realquantity.h>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(CompositeTime);
|
||||
|
||||
class Origin;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Focal times differ significantly in their precision. While
|
||||
* \brief focal times
|
||||
* \brief of instrumentally located earthquakes are estimated
|
||||
* \brief precisely down to
|
||||
* \brief seconds, historic events have only incomplete time
|
||||
* \brief descriptions. Sometimes,
|
||||
* \brief even contradictory information about the rupture time
|
||||
* \brief exist. The
|
||||
* \brief CompositeTime type allows for such complex descriptions. If
|
||||
* \brief the specification
|
||||
* \brief is given with no greater accuracy than days (i.e., no time
|
||||
* \brief components are
|
||||
* \brief given), the date refers to local time. However, if time
|
||||
* \brief components are
|
||||
* \brief given, they have to refer to UTC. As an example, consider a
|
||||
* \brief historic
|
||||
* \brief earthquake in California, e.g., on 28 February 1730, with
|
||||
* \brief no time information
|
||||
* \brief given. Expressed in UTC, this day extends from
|
||||
* \brief 1730-02-28T08:00:00Z
|
||||
* \brief until 1730-03-01T08:00:00Z. Such a specification would be
|
||||
* \brief against intuition.
|
||||
* \brief Therefore, for date-time specifications without time
|
||||
* \brief components, local
|
||||
* \brief time is used. In the example, the CompositeTime attributes
|
||||
* \brief are simply
|
||||
* \brief year 1730, month 2, and day 28. In the corresponding time
|
||||
* \brief attribute of
|
||||
* \brief the origin, however, UTC has to be used. If the unknown
|
||||
* \brief time components
|
||||
* \brief are assumed to be zero, the value is 1730-02-28T08:00:00Z.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API CompositeTime : public Object {
|
||||
DECLARE_SC_CLASS(CompositeTime)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
CompositeTime();
|
||||
|
||||
//! Copy constructor
|
||||
CompositeTime(const CompositeTime& other);
|
||||
|
||||
//! Destructor
|
||||
~CompositeTime() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
CompositeTime& operator=(const CompositeTime& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const CompositeTime& other) const;
|
||||
bool operator!=(const CompositeTime& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const CompositeTime& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Year or range of years of the event's focal time.
|
||||
void setYear(const OPT(IntegerQuantity)& year);
|
||||
IntegerQuantity& year();
|
||||
const IntegerQuantity& year() const;
|
||||
|
||||
//! Month or range of months of the event's focal time.
|
||||
void setMonth(const OPT(IntegerQuantity)& month);
|
||||
IntegerQuantity& month();
|
||||
const IntegerQuantity& month() const;
|
||||
|
||||
//! Day or range of days of the event's focal time.
|
||||
void setDay(const OPT(IntegerQuantity)& day);
|
||||
IntegerQuantity& day();
|
||||
const IntegerQuantity& day() const;
|
||||
|
||||
//! Hour or range of hours of the event's focal time.
|
||||
void setHour(const OPT(IntegerQuantity)& hour);
|
||||
IntegerQuantity& hour();
|
||||
const IntegerQuantity& hour() const;
|
||||
|
||||
//! Minute or range of minutes of the event's focal time.
|
||||
void setMinute(const OPT(IntegerQuantity)& minute);
|
||||
IntegerQuantity& minute();
|
||||
const IntegerQuantity& minute() const;
|
||||
|
||||
//! Second and fraction of seconds or range of seconds with
|
||||
//! fraction of the event's focal time.
|
||||
void setSecond(const OPT(RealQuantity)& second);
|
||||
RealQuantity& second();
|
||||
const RealQuantity& second() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Origin* origin() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Attributes
|
||||
OPT(IntegerQuantity) _year;
|
||||
OPT(IntegerQuantity) _month;
|
||||
OPT(IntegerQuantity) _day;
|
||||
OPT(IntegerQuantity) _hour;
|
||||
OPT(IntegerQuantity) _minute;
|
||||
OPT(RealQuantity) _second;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
183
include/seiscomp/datamodel/confidenceellipsoid.h
Normal file
183
include/seiscomp/datamodel/confidenceellipsoid.h
Normal file
@@ -0,0 +1,183 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_CONFIDENCEELLIPSOID_H
|
||||
#define SEISCOMP_DATAMODEL_CONFIDENCEELLIPSOID_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ConfidenceEllipsoid);
|
||||
|
||||
|
||||
/**
|
||||
* \brief This class represents a description of the location
|
||||
* \brief uncertainty as a confidence
|
||||
* \brief ellipsoid with arbitrary orientation in space. The
|
||||
* \brief orientation of a rigid
|
||||
* \brief body in three-dimensional Euclidean space can be described
|
||||
* \brief by three
|
||||
* \brief parameters. We use the convention of Euler angles, which
|
||||
* \brief can be interpreted
|
||||
* \brief as a composition of three elemental rotations (i.e.,
|
||||
* \brief rotations around a single axis).
|
||||
* \brief In the special case of Euler angles we use here, the angles
|
||||
* \brief are referred
|
||||
* \brief to as Tait-Bryan (or Cardan) angles. These angles may be
|
||||
* \brief familiar to
|
||||
* \brief the reader from their application in flight dynamics, and
|
||||
* \brief are referred
|
||||
* \brief to as heading (yaw, psi), elevation (attitude, pitch, phi),
|
||||
* \brief and bank (roll, theta).
|
||||
* \brief For a definition of the angles, see Figure 4. Through the
|
||||
* \brief three elemental
|
||||
* \brief rotations, a Cartesian system (x, y, z) centered at the
|
||||
* \brief epicenter, with
|
||||
* \brief the South-North direction x, the West-East direction y, and
|
||||
* \brief the downward
|
||||
* \brief vertical direction z, is transferred into a different
|
||||
* \brief Cartesian system
|
||||
* \brief (X, Y , Z) centered on the confidence ellipsoid. Here, X
|
||||
* \brief denotes the direction
|
||||
* \brief of the major axis, and Y denotes the direction of the minor
|
||||
* \brief axis of the
|
||||
* \brief ellipsoid. Note that Figure 4 can be interpreted as a
|
||||
* \brief hypothetical view
|
||||
* \brief from the interior of the Earth to the inner face of a shell
|
||||
* \brief representing
|
||||
* \brief Earth's surface. The three Tait-Bryan rotations are
|
||||
* \brief performed as follows:
|
||||
* \brief (i) a rotation about the Z axis with angle psi (heading, or
|
||||
* \brief azimuth);
|
||||
* \brief (ii) a rotation about the Y axis with angle phi (elevation,
|
||||
* \brief or plunge);
|
||||
* \brief and (iii) a rotation about the X axis with angle theta
|
||||
* \brief (bank). Note that in
|
||||
* \brief the case of Tait-Bryan angles, the rotations are performed
|
||||
* \brief about the
|
||||
* \brief ellipsoid's axes, not about the axes of the fixed (x, y, z)
|
||||
* \brief Cartesian system.
|
||||
* \brief In the following list the correspondence of the attributes
|
||||
* \brief of class
|
||||
* \brief ConfidenceEllipsoid to the respective Tait-Bryan angles is
|
||||
* \brief listed:
|
||||
* \brief majorAxisPlunge: elevation (pitch, phi), majorAxisAzimuth:
|
||||
* \brief heading (yaw, psi), majorAxisRotation: bank (roll, theta)
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API ConfidenceEllipsoid : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(ConfidenceEllipsoid)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ConfidenceEllipsoid();
|
||||
|
||||
//! Copy constructor
|
||||
ConfidenceEllipsoid(const ConfidenceEllipsoid& other);
|
||||
|
||||
//! Destructor
|
||||
~ConfidenceEllipsoid() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
ConfidenceEllipsoid& operator=(const ConfidenceEllipsoid& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ConfidenceEllipsoid& other) const;
|
||||
bool operator!=(const ConfidenceEllipsoid& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ConfidenceEllipsoid& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Largest uncertainty, corresponding to the semi-major axis
|
||||
//! of the confidence ellipsoid in meter.
|
||||
void setSemiMajorAxisLength(double semiMajorAxisLength);
|
||||
double semiMajorAxisLength() const;
|
||||
|
||||
//! Smallest uncertainty, corresponding to the semi-minor axis
|
||||
//! of the confidence ellipsoid in meter.
|
||||
void setSemiMinorAxisLength(double semiMinorAxisLength);
|
||||
double semiMinorAxisLength() const;
|
||||
|
||||
//! Uncertainty in direction orthogonal to major and minor axes
|
||||
//! of the confidence ellipsoid in meter.
|
||||
void setSemiIntermediateAxisLength(double semiIntermediateAxisLength);
|
||||
double semiIntermediateAxisLength() const;
|
||||
|
||||
//! Plunge angle of major axis of confidence ellipsoid.
|
||||
//! Corresponds to Tait-Bryan angle phi
|
||||
//! in degrees.
|
||||
void setMajorAxisPlunge(double majorAxisPlunge);
|
||||
double majorAxisPlunge() const;
|
||||
|
||||
//! Azimuth angle of major axis of confidence ellipsoid.
|
||||
//! Corresponds to Tait-Bryan angle psi
|
||||
//! in degrees.
|
||||
void setMajorAxisAzimuth(double majorAxisAzimuth);
|
||||
double majorAxisAzimuth() const;
|
||||
|
||||
//! This angle describes a rotation about the confidence
|
||||
//! ellipsoid's major axis which is required
|
||||
//! to define the direction of the ellipsoid's minor axis.
|
||||
//! Corresponds to Tait-Bryan angle theta
|
||||
//! in degrees.
|
||||
void setMajorAxisRotation(double majorAxisRotation);
|
||||
double majorAxisRotation() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Attributes
|
||||
double _semiMajorAxisLength;
|
||||
double _semiMinorAxisLength;
|
||||
double _semiIntermediateAxisLength;
|
||||
double _majorAxisPlunge;
|
||||
double _majorAxisAzimuth;
|
||||
double _majorAxisRotation;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
153
include/seiscomp/datamodel/config.h
Normal file
153
include/seiscomp/datamodel/config.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_CONFIG_H
|
||||
#define SEISCOMP_DATAMODEL_CONFIG_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <seiscomp/datamodel/notifier.h>
|
||||
#include <seiscomp/datamodel/publicobject.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Config);
|
||||
DEFINE_SMARTPOINTER(ParameterSet);
|
||||
DEFINE_SMARTPOINTER(ConfigModule);
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Config : public PublicObject {
|
||||
DECLARE_SC_CLASS(Config)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
Config();
|
||||
|
||||
//! Copy constructor
|
||||
Config(const Config& other);
|
||||
|
||||
//! Destructor
|
||||
~Config() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
//! No changes regarding child objects are made
|
||||
Config& operator=(const Config& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const Config& other) const;
|
||||
bool operator!=(const Config& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const Config& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Add an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been added
|
||||
* @return false The object has not been added
|
||||
* because it already exists in the list
|
||||
* or it already has another parent
|
||||
*/
|
||||
bool add(ParameterSet* obj);
|
||||
bool add(ConfigModule* obj);
|
||||
|
||||
/**
|
||||
* Removes an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been removed
|
||||
* @return false The object has not been removed
|
||||
* because it does not exist in the list
|
||||
*/
|
||||
bool remove(ParameterSet* obj);
|
||||
bool remove(ConfigModule* obj);
|
||||
|
||||
/**
|
||||
* Removes an object of a particular class.
|
||||
* @param i The object index
|
||||
* @return true The object has been removed
|
||||
* @return false The index is out of bounds
|
||||
*/
|
||||
bool removeParameterSet(size_t i);
|
||||
bool removeConfigModule(size_t i);
|
||||
|
||||
//! Retrieve the number of objects of a particular class
|
||||
size_t parameterSetCount() const;
|
||||
size_t configModuleCount() const;
|
||||
|
||||
//! Index access
|
||||
//! @return The object at index i
|
||||
ParameterSet* parameterSet(size_t i) const;
|
||||
ConfigModule* configModule(size_t i) const;
|
||||
|
||||
//! Find an object by its unique attribute(s)
|
||||
ParameterSet* findParameterSet(const std::string& publicID) const;
|
||||
ConfigModule* findConfigModule(const std::string& publicID) const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
//! Implement PublicObject interface
|
||||
bool updateChild(Object *child) override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Aggregations
|
||||
std::vector<ParameterSetPtr> _parameterSets;
|
||||
std::vector<ConfigModulePtr> _configModules;
|
||||
|
||||
DECLARE_SC_CLASSFACTORY_FRIEND(Config);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
33
include/seiscomp/datamodel/config_package.h
Normal file
33
include/seiscomp/datamodel/config_package.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_CONFIG_PACKAGE_H__
|
||||
#define SEISCOMP_DATAMODEL_CONFIG_PACKAGE_H__
|
||||
|
||||
|
||||
#include <seiscomp/datamodel/parameter.h>
|
||||
#include <seiscomp/datamodel/parameterset.h>
|
||||
#include <seiscomp/datamodel/setup.h>
|
||||
#include <seiscomp/datamodel/configstation.h>
|
||||
#include <seiscomp/datamodel/configmodule.h>
|
||||
#include <seiscomp/datamodel/config.h>
|
||||
|
||||
|
||||
#endif
|
||||
191
include/seiscomp/datamodel/configmodule.h
Normal file
191
include/seiscomp/datamodel/configmodule.h
Normal file
@@ -0,0 +1,191 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_CONFIGMODULE_H
|
||||
#define SEISCOMP_DATAMODEL_CONFIGMODULE_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <seiscomp/datamodel/configstation.h>
|
||||
#include <seiscomp/datamodel/notifier.h>
|
||||
#include <seiscomp/datamodel/publicobject.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ConfigModule);
|
||||
DEFINE_SMARTPOINTER(ConfigStation);
|
||||
|
||||
class Config;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ConfigModule : public PublicObject {
|
||||
DECLARE_SC_CLASS(ConfigModule)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Protected constructor
|
||||
ConfigModule();
|
||||
|
||||
public:
|
||||
//! Copy constructor
|
||||
ConfigModule(const ConfigModule& other);
|
||||
|
||||
//! Constructor with publicID
|
||||
ConfigModule(const std::string& publicID);
|
||||
|
||||
//! Destructor
|
||||
~ConfigModule() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Creators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static ConfigModule* Create();
|
||||
static ConfigModule* Create(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Lookup
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static ConfigModule* Find(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
//! No changes regarding child objects are made
|
||||
ConfigModule& operator=(const ConfigModule& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ConfigModule& other) const;
|
||||
bool operator!=(const ConfigModule& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ConfigModule& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setName(const std::string& name);
|
||||
const std::string& name() const;
|
||||
|
||||
void setParameterSetID(const std::string& parameterSetID);
|
||||
const std::string& parameterSetID() const;
|
||||
|
||||
void setEnabled(bool enabled);
|
||||
bool enabled() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Add an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been added
|
||||
* @return false The object has not been added
|
||||
* because it already exists in the list
|
||||
* or it already has another parent
|
||||
*/
|
||||
bool add(ConfigStation* obj);
|
||||
|
||||
/**
|
||||
* Removes an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been removed
|
||||
* @return false The object has not been removed
|
||||
* because it does not exist in the list
|
||||
*/
|
||||
bool remove(ConfigStation* obj);
|
||||
|
||||
/**
|
||||
* Removes an object of a particular class.
|
||||
* @param i The object index
|
||||
* @return true The object has been removed
|
||||
* @return false The index is out of bounds
|
||||
*/
|
||||
bool removeConfigStation(size_t i);
|
||||
bool removeConfigStation(const ConfigStationIndex& i);
|
||||
|
||||
//! Retrieve the number of objects of a particular class
|
||||
size_t configStationCount() const;
|
||||
|
||||
//! Index access
|
||||
//! @return The object at index i
|
||||
ConfigStation* configStation(size_t i) const;
|
||||
ConfigStation* configStation(const ConfigStationIndex& i) const;
|
||||
|
||||
//! Find an object by its unique attribute(s)
|
||||
ConfigStation* findConfigStation(const std::string& publicID) const;
|
||||
|
||||
Config* config() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
//! Implement PublicObject interface
|
||||
bool updateChild(Object *child) override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Attributes
|
||||
std::string _name;
|
||||
std::string _parameterSetID;
|
||||
bool _enabled;
|
||||
|
||||
// Aggregations
|
||||
std::vector<ConfigStationPtr> _configStations;
|
||||
|
||||
DECLARE_SC_CLASSFACTORY_FRIEND(ConfigModule);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
240
include/seiscomp/datamodel/configstation.h
Normal file
240
include/seiscomp/datamodel/configstation.h
Normal file
@@ -0,0 +1,240 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_CONFIGSTATION_H
|
||||
#define SEISCOMP_DATAMODEL_CONFIGSTATION_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/creationinfo.h>
|
||||
#include <vector>
|
||||
#include <seiscomp/datamodel/setup.h>
|
||||
#include <seiscomp/datamodel/notifier.h>
|
||||
#include <seiscomp/datamodel/publicobject.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ConfigStation);
|
||||
DEFINE_SMARTPOINTER(Setup);
|
||||
|
||||
class ConfigModule;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ConfigStationIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
ConfigStationIndex();
|
||||
ConfigStationIndex(const std::string& networkCode,
|
||||
const std::string& stationCode);
|
||||
|
||||
//! Copy constructor
|
||||
ConfigStationIndex(const ConfigStationIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const ConfigStationIndex&) const;
|
||||
bool operator!=(const ConfigStationIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string networkCode;
|
||||
std::string stationCode;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ConfigStation : public PublicObject {
|
||||
DECLARE_SC_CLASS(ConfigStation)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Protected constructor
|
||||
ConfigStation();
|
||||
|
||||
public:
|
||||
//! Copy constructor
|
||||
ConfigStation(const ConfigStation& other);
|
||||
|
||||
//! Constructor with publicID
|
||||
ConfigStation(const std::string& publicID);
|
||||
|
||||
//! Destructor
|
||||
~ConfigStation() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Creators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static ConfigStation* Create();
|
||||
static ConfigStation* Create(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Lookup
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static ConfigStation* Find(const std::string& publicID);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
//! No changes regarding child objects are made
|
||||
ConfigStation& operator=(const ConfigStation& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const ConfigStation& other) const;
|
||||
bool operator!=(const ConfigStation& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const ConfigStation& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void setNetworkCode(const std::string& networkCode);
|
||||
const std::string& networkCode() const;
|
||||
|
||||
void setStationCode(const std::string& stationCode);
|
||||
const std::string& stationCode() const;
|
||||
|
||||
void setEnabled(bool enabled);
|
||||
bool enabled() const;
|
||||
|
||||
//! CreationInfo for the ConfigStation object.
|
||||
void setCreationInfo(const OPT(CreationInfo)& creationInfo);
|
||||
CreationInfo& creationInfo();
|
||||
const CreationInfo& creationInfo() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const ConfigStationIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const ConfigStation* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Add an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been added
|
||||
* @return false The object has not been added
|
||||
* because it already exists in the list
|
||||
* or it already has another parent
|
||||
*/
|
||||
bool add(Setup* obj);
|
||||
|
||||
/**
|
||||
* Removes an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been removed
|
||||
* @return false The object has not been removed
|
||||
* because it does not exist in the list
|
||||
*/
|
||||
bool remove(Setup* obj);
|
||||
|
||||
/**
|
||||
* Removes an object of a particular class.
|
||||
* @param i The object index
|
||||
* @return true The object has been removed
|
||||
* @return false The index is out of bounds
|
||||
*/
|
||||
bool removeSetup(size_t i);
|
||||
bool removeSetup(const SetupIndex& i);
|
||||
|
||||
//! Retrieve the number of objects of a particular class
|
||||
size_t setupCount() const;
|
||||
|
||||
//! Index access
|
||||
//! @return The object at index i
|
||||
Setup* setup(size_t i) const;
|
||||
Setup* setup(const SetupIndex& i) const;
|
||||
|
||||
//! Find an object by its unique attribute(s)
|
||||
|
||||
ConfigModule* configModule() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
//! Implement PublicObject interface
|
||||
bool updateChild(Object *child) override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
ConfigStationIndex _index;
|
||||
|
||||
// Attributes
|
||||
bool _enabled;
|
||||
OPT(CreationInfo) _creationInfo;
|
||||
|
||||
// Aggregations
|
||||
std::vector<SetupPtr> _setups;
|
||||
|
||||
DECLARE_SC_CLASSFACTORY_FRIEND(ConfigStation);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
133
include/seiscomp/datamodel/creationinfo.h
Normal file
133
include/seiscomp/datamodel/creationinfo.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_CREATIONINFO_H
|
||||
#define SEISCOMP_DATAMODEL_CREATIONINFO_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(CreationInfo);
|
||||
|
||||
|
||||
/**
|
||||
* \brief CreationInfo is used to describe creation metadata (author,
|
||||
* \brief version, and creation time) of a resource.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API CreationInfo : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(CreationInfo)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
CreationInfo();
|
||||
|
||||
//! Copy constructor
|
||||
CreationInfo(const CreationInfo& other);
|
||||
|
||||
//! Destructor
|
||||
~CreationInfo() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
CreationInfo& operator=(const CreationInfo& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const CreationInfo& other) const;
|
||||
bool operator!=(const CreationInfo& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const CreationInfo& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Designation of agency that published a resource. The string
|
||||
//! has a maximum length of 64 characters.
|
||||
void setAgencyID(const std::string& agencyID);
|
||||
const std::string& agencyID() const;
|
||||
|
||||
//! RI of the agency that published a resource.
|
||||
void setAgencyURI(const std::string& agencyURI);
|
||||
const std::string& agencyURI() const;
|
||||
|
||||
//! Name describing the author of a resource. The string has a
|
||||
//! maximum length of 128 characters.
|
||||
void setAuthor(const std::string& author);
|
||||
const std::string& author() const;
|
||||
|
||||
//! RI of the author of a resource.
|
||||
void setAuthorURI(const std::string& authorURI);
|
||||
const std::string& authorURI() const;
|
||||
|
||||
//! Time of creation of a resource, in ISO 8601 format. It has
|
||||
//! to be given in UTC.
|
||||
void setCreationTime(const OPT(Seiscomp::Core::Time)& creationTime);
|
||||
Seiscomp::Core::Time creationTime() const;
|
||||
|
||||
//! Time of last modification of a resource, in ISO 8601
|
||||
//! format. It has to be given in UTC.
|
||||
void setModificationTime(const OPT(Seiscomp::Core::Time)& modificationTime);
|
||||
Seiscomp::Core::Time modificationTime() const;
|
||||
|
||||
//! Version string of a resource.
|
||||
void setVersion(const std::string& version);
|
||||
const std::string& version() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Attributes
|
||||
std::string _agencyID;
|
||||
std::string _agencyURI;
|
||||
std::string _author;
|
||||
std::string _authorURI;
|
||||
OPT(Seiscomp::Core::Time) _creationTime;
|
||||
OPT(Seiscomp::Core::Time) _modificationTime;
|
||||
std::string _version;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
184
include/seiscomp/datamodel/dataattributeextent.h
Normal file
184
include/seiscomp/datamodel/dataattributeextent.h
Normal file
@@ -0,0 +1,184 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_DATAATTRIBUTEEXTENT_H
|
||||
#define SEISCOMP_DATAMODEL_DATAATTRIBUTEEXTENT_H
|
||||
|
||||
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <string>
|
||||
#include <seiscomp/datamodel/object.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(DataAttributeExtent);
|
||||
|
||||
class DataExtent;
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API DataAttributeExtentIndex {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
DataAttributeExtentIndex();
|
||||
DataAttributeExtentIndex(double sampleRate,
|
||||
const std::string& quality);
|
||||
|
||||
//! Copy constructor
|
||||
DataAttributeExtentIndex(const DataAttributeExtentIndex&);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool operator==(const DataAttributeExtentIndex&) const;
|
||||
bool operator!=(const DataAttributeExtentIndex&) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
double sampleRate;
|
||||
std::string quality;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API DataAttributeExtent : public Object {
|
||||
DECLARE_SC_CLASS(DataAttributeExtent)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
DataAttributeExtent();
|
||||
|
||||
//! Copy constructor
|
||||
DataAttributeExtent(const DataAttributeExtent& other);
|
||||
|
||||
//! Destructor
|
||||
~DataAttributeExtent() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
DataAttributeExtent& operator=(const DataAttributeExtent& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const DataAttributeExtent& other) const;
|
||||
bool operator!=(const DataAttributeExtent& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const DataAttributeExtent& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Time of first sample of data attribute extent.
|
||||
void setStart(Seiscomp::Core::Time start);
|
||||
Seiscomp::Core::Time start() const;
|
||||
|
||||
//! Time after last sample of data attribute extent.
|
||||
void setEnd(Seiscomp::Core::Time end);
|
||||
Seiscomp::Core::Time end() const;
|
||||
|
||||
//! Sample rate of the current data attribute extent.
|
||||
void setSampleRate(double sampleRate);
|
||||
double sampleRate() const;
|
||||
|
||||
//! Quality indicator of current data attribute extent.
|
||||
void setQuality(const std::string& quality);
|
||||
const std::string& quality() const;
|
||||
|
||||
//! The time of the last update or creation of this data
|
||||
//! attribute extent.
|
||||
void setUpdated(Seiscomp::Core::Time updated);
|
||||
Seiscomp::Core::Time updated() const;
|
||||
|
||||
//! Number of data segments covered by this data attribute
|
||||
//! extent.
|
||||
void setSegmentCount(int segmentCount);
|
||||
int segmentCount() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Index management
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the object's index
|
||||
const DataAttributeExtentIndex& index() const;
|
||||
|
||||
//! Checks two objects for equality regarding their index
|
||||
bool equalIndex(const DataAttributeExtent* lhs) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
DataExtent* dataExtent() const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Index
|
||||
DataAttributeExtentIndex _index;
|
||||
|
||||
// Attributes
|
||||
Seiscomp::Core::Time _start;
|
||||
Seiscomp::Core::Time _end;
|
||||
Seiscomp::Core::Time _updated;
|
||||
int _segmentCount;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
152
include/seiscomp/datamodel/dataavailability.h
Normal file
152
include/seiscomp/datamodel/dataavailability.h
Normal file
@@ -0,0 +1,152 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_DATAAVAILABILITY_H
|
||||
#define SEISCOMP_DATAMODEL_DATAAVAILABILITY_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <seiscomp/datamodel/dataextent.h>
|
||||
#include <seiscomp/datamodel/notifier.h>
|
||||
#include <seiscomp/datamodel/publicobject.h>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace DataModel {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(DataAvailability);
|
||||
DEFINE_SMARTPOINTER(DataExtent);
|
||||
|
||||
|
||||
/**
|
||||
* \brief This type can hold data availability related objects
|
||||
* \brief (extent and segment).
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API DataAvailability : public PublicObject {
|
||||
DECLARE_SC_CLASS(DataAvailability)
|
||||
DECLARE_SERIALIZATION;
|
||||
DECLARE_METAOBJECT;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
DataAvailability();
|
||||
|
||||
//! Copy constructor
|
||||
DataAvailability(const DataAvailability& other);
|
||||
|
||||
//! Destructor
|
||||
~DataAvailability() override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Copies the metadata of other to this
|
||||
//! No changes regarding child objects are made
|
||||
DataAvailability& operator=(const DataAvailability& other);
|
||||
//! Checks for equality of two objects. Child objects
|
||||
//! are not part of the check.
|
||||
bool operator==(const DataAvailability& other) const;
|
||||
bool operator!=(const DataAvailability& other) const;
|
||||
|
||||
//! Wrapper that calls operator==
|
||||
bool equal(const DataAvailability& other) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Add an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been added
|
||||
* @return false The object has not been added
|
||||
* because it already exists in the list
|
||||
* or it already has another parent
|
||||
*/
|
||||
bool add(DataExtent* obj);
|
||||
|
||||
/**
|
||||
* Removes an object.
|
||||
* @param obj The object pointer
|
||||
* @return true The object has been removed
|
||||
* @return false The object has not been removed
|
||||
* because it does not exist in the list
|
||||
*/
|
||||
bool remove(DataExtent* obj);
|
||||
|
||||
/**
|
||||
* Removes an object of a particular class.
|
||||
* @param i The object index
|
||||
* @return true The object has been removed
|
||||
* @return false The index is out of bounds
|
||||
*/
|
||||
bool removeDataExtent(size_t i);
|
||||
bool removeDataExtent(const DataExtentIndex& i);
|
||||
|
||||
//! Retrieve the number of objects of a particular class
|
||||
size_t dataExtentCount() const;
|
||||
|
||||
//! Index access
|
||||
//! @return The object at index i
|
||||
DataExtent* dataExtent(size_t i) const;
|
||||
DataExtent* dataExtent(const DataExtentIndex& i) const;
|
||||
|
||||
//! Find an object by its unique attribute(s)
|
||||
DataExtent* findDataExtent(const std::string& publicID) const;
|
||||
|
||||
//! Implement Object interface
|
||||
bool assign(Object *other) override;
|
||||
bool attachTo(PublicObject *parent) override;
|
||||
bool detachFrom(PublicObject *parent) override;
|
||||
bool detach() override;
|
||||
|
||||
//! Creates a clone
|
||||
Object *clone() const override;
|
||||
|
||||
//! Implement PublicObject interface
|
||||
bool updateChild(Object *child) override;
|
||||
|
||||
void accept(Visitor *visitor) override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
// Aggregations
|
||||
std::vector<DataExtentPtr> _dataExtents;
|
||||
|
||||
DECLARE_SC_CLASSFACTORY_FRIEND(DataAvailability);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
31
include/seiscomp/datamodel/dataavailability_package.h
Normal file
31
include/seiscomp/datamodel/dataavailability_package.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/***************************************************************************
|
||||
* 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_DATAMODEL_DATAAVAILABILITY_PACKAGE_H__
|
||||
#define SEISCOMP_DATAMODEL_DATAAVAILABILITY_PACKAGE_H__
|
||||
|
||||
|
||||
#include <seiscomp/datamodel/datasegment.h>
|
||||
#include <seiscomp/datamodel/dataattributeextent.h>
|
||||
#include <seiscomp/datamodel/dataextent.h>
|
||||
#include <seiscomp/datamodel/dataavailability.h>
|
||||
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user