[seiscomp, scanloc] Install, add .gitignore
This commit is contained in:
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
|
Reference in New Issue
Block a user