Commit fdabca98 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Configuration: allow default array/update to upstream

parent 7530648d
/**
* @file
* @brief Collection of all configuration exceptions
*
* @copyright Copyright (c) 2017 CERN and the Allpix Squared authors.
* This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
* In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*/
#ifndef CORRYVRECKAN_CLIPBOARD_EXCEPTIONS_H
#define CORRYVRECKAN_CLIPOARD_EXCEPTIONS_H
#include <string>
#include "core/utils/exceptions.h"
#include "core/utils/type.h"
namespace corryvreckan {
/**
* @ingroup Exceptions
* @brief Base class for all clipboard exceptions in the framework.
*/
class ClipboardError : public Exception {};
/**
* @ingroup Exceptions
* @brief Informs of missing data that has been requested
*/
class MissingDataError : public ClipboardError {
public:
/**
* @brief Construct an error for a missing key
* @param key Name of the missing key
* @param section Section where the key should have been defined
*/
MissingDataError(const std::string& name) {
error_message_ = "No data with key '" + name + "' exists on the clipboard";
}
};
} // namespace corryvreckan
#endif /* CORRYVRECKAN_CONFIG_EXCEPTIONS_H */
......@@ -84,6 +84,17 @@ namespace corryvreckan {
*/
// TODO [doc] Provide second template parameter to specify the vector type to return it in
template <typename T> std::vector<T> getArray(const std::string& key) const;
/**
* @brief Get values for a key containing an array or default array if it does not exists
* @param key Key to get values of
* @param def Default value array to use if key is not defined
* @return List of values in the array in the requested template parameter
* or the default array if the key does not exist
*/
// TODO [doc] Provide second template parameter to specify the vector type to return it in
template <typename T> std::vector<T> getArray(const std::string& key, const std::vector<T> def) const;
/**
* @brief Get values for a key containing a 2D matrix
* @param key Key to get values of
......
......@@ -67,6 +67,16 @@ namespace corryvreckan {
throw InvalidKeyError(key, getName(), config_.at(key), typeid(T), e.what());
}
}
/**
* @throws InvalidKeyError If the conversion to the requested type did not succeed
* @throws InvalidKeyError If an overflow happened while converting the key
*/
template <typename T> std::vector<T> Configuration::getArray(const std::string& key, const std::vector<T> def) const {
if(has(key)) {
return getArray<T>(key);
}
return def;
}
/**
* @throws MissingKeyError If the requested key is not defined
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment