Skip to content

Commit

Permalink
Cleanup (remove headers, preprocessor, clang-format)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Maciel committed Nov 22, 2023
1 parent a44e26b commit 70ff604
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 59 deletions.
12 changes: 3 additions & 9 deletions src/eckit/option/FactoryOption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@

#include <iostream>

#include "eckit/config/Configuration.h"
#include "eckit/config/Configured.h"

#include "eckit/exception/Exceptions.h"
#include "eckit/option/FactoryOption.h"
#include "eckit/utils/Translator.h"

namespace eckit {
namespace option {
namespace eckit::option {


template <class T>
Expand Down Expand Up @@ -62,11 +58,9 @@ void FactoryOption<T>::copy(const Configuration& from, Configured& to) const {

template <class T>
void FactoryOption<T>::print(std::ostream& out) const {
out << " --" << name_ << "=name"
<< " (" << description_ << ")";
out << " --" << name_ << "=name" << " (" << description_ << ")";
out << std::endl << " Values are: ";
T::list(out);
}

} // namespace option
} // namespace eckit
} // namespace eckit::option
6 changes: 1 addition & 5 deletions src/eckit/option/FactoryOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
/// @author Tiago Quintino
/// @date Apr 2015


#ifndef eckit_option_FactoryOption_H
#define eckit_option_FactoryOption_H
#pragma once

#include <iosfwd>

Expand Down Expand Up @@ -52,5 +50,3 @@ class FactoryOption : public BaseOption<std::string> {
} // namespace eckit::option

#include "eckit/option/FactoryOption.cc"

#endif
9 changes: 3 additions & 6 deletions src/eckit/option/MultiValueOption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#include <algorithm>
#include <iostream>

#include "eckit/config/Configuration.h"
#include "eckit/config/Configured.h"

#include "eckit/exception/Exceptions.h"

namespace eckit::option {
Expand All @@ -39,16 +37,15 @@ MultiValueOption::MultiValueOption(const std::string& name, const std::string& d
size_t n_optional_values, std::optional<values_t> default_values) :
base_t(name, description, std::move(default_values)),
n_mandatory_values_{n_mandatory_values},
n_optional_values_{n_optional_values},
values_{} {
n_optional_values_{n_optional_values} {
ASSERT_MSG(n_mandatory_values >= 1, "At least 1 mandatory value is expected.");
}

size_t MultiValueOption::set(Configured& parametrisation, [[maybe_unused]] size_t values, args_t::const_iterator begin,
args_t::const_iterator end) const {
if (std::distance(begin, end) < n_mandatory_values_) {
throw UserError("Not enough option values found for MultiValueOption, where at least " +
std::to_string(n_mandatory_values_) + " were expected");
throw UserError("Not enough option values found for MultiValueOption, where at least "
+ std::to_string(n_mandatory_values_) + " were expected");
}

// Collect n_mandatory_values_ mandatory values from the range [begin, end)
Expand Down
17 changes: 9 additions & 8 deletions src/eckit/option/MultiValueOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* does it submit to any jurisdiction.
*/

#ifndef eckit_option_MultiValueOption_H
#define eckit_option_MultiValueOption_H
#pragma once

#include <iosfwd>

Expand All @@ -23,17 +22,21 @@ class MultiValueOption : public BaseOption<std::vector<std::string>> {
using values_t = std::vector<std::string>;

MultiValueOption(const std::string& name, const std::string& description, size_t n_mandatory_values);
MultiValueOption(const std::string& name, const std::string& description, size_t n_mandatory_values, size_t n_optional_values);
MultiValueOption(const std::string& name, const std::string& description, size_t n_mandatory_values, const values_t& default_values);
MultiValueOption(const std::string& name, const std::string& description, size_t n_mandatory_values, size_t n_optional_values, const values_t& default_values);
MultiValueOption(const std::string& name, const std::string& description, size_t n_mandatory_values,
size_t n_optional_values);
MultiValueOption(const std::string& name, const std::string& description, size_t n_mandatory_values,
const values_t& default_values);
MultiValueOption(const std::string& name, const std::string& description, size_t n_mandatory_values,
size_t n_optional_values, const values_t& default_values);
~MultiValueOption() override = default;

size_t set(Configured&, size_t values, args_t::const_iterator begin, args_t::const_iterator end) const override;

void print(std::ostream&) const override;

private:
MultiValueOption(const std::string& name, const std::string& description, size_t n_mandatory_values, size_t n_maximum_values, std::optional<values_t> default_values);
MultiValueOption(const std::string& name, const std::string& description, size_t n_mandatory_values,
size_t n_maximum_values, std::optional<values_t> default_values);

void set_value(const values_t& values, Configured&) const override;

Expand All @@ -47,5 +50,3 @@ class MultiValueOption : public BaseOption<std::vector<std::string>> {
};

} // namespace eckit::option

#endif
5 changes: 2 additions & 3 deletions src/eckit/option/SimpleOption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "eckit/config/Configuration.h"
#include "eckit/config/Configured.h"

#include "eckit/exception/Exceptions.h"
#include "eckit/filesystem/PathName.h"
#include "eckit/option/SimpleOption.h"
Expand Down Expand Up @@ -68,12 +67,12 @@ void SimpleOption<T>::set_value(const T& value, Configured& parametrisation) con

template <class T>
T SimpleOption<T>::translate(const std::string& value) const {
T v = eckit::Translator<std::string, T>()(value);
T v = Translator<std::string, T>()(value);
return v;
}

template <>
inline void SimpleOption<eckit::PathName>::copy(const Configuration& from, Configured& to) const {
inline void SimpleOption<PathName>::copy(const Configuration& from, Configured& to) const {
std::string v;
if (from.get(name_, v)) {
to.set(name_, v);
Expand Down
7 changes: 1 addition & 6 deletions src/eckit/option/SimpleOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
/// @author Tiago Quintino
/// @date Apr 2015


#ifndef eckit_option_SimpleOption_H
#define eckit_option_SimpleOption_H
#pragma once

#include <iosfwd>

Expand All @@ -39,7 +37,6 @@ class SimpleOption : public BaseOption<T> {
void print(std::ostream&) const override;

private:

void set_value(const T& value, Configured&) const override;

[[nodiscard]] T translate(const std::string& value) const override;
Expand All @@ -50,5 +47,3 @@ class SimpleOption : public BaseOption<T> {
} // namespace eckit::option

#include "eckit/option/SimpleOption.cc"

#endif
21 changes: 4 additions & 17 deletions src/eckit/option/VectorOption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@
#include "eckit/utils/Tokenizer.h"
#include "eckit/utils/Translator.h"


namespace eckit {

namespace option {

//----------------------------------------------------------------------------------------------------------------------

namespace eckit::option {

template <class T>
VectorOption<T>::VectorOption(const std::string& name, const std::string& description, size_t size,
Expand Down Expand Up @@ -61,9 +55,9 @@ void VectorOption<T>::set_value(const std::vector<T>& value, Configured& paramet

template <class T>
std::vector<T> VectorOption<T>::translate(const std::string& value) const {
eckit::Translator<std::string, T> t;
Translator<std::string, T> t;

eckit::Tokenizer parse(separator_);
Tokenizer parse(separator_);
std::vector<std::string> tokens;
parse(value, tokens);

Expand Down Expand Up @@ -97,16 +91,9 @@ void VectorOption<T>::print(std::ostream& out) const {
out << " (" << this->description() << ")";
}


template <class T>
void VectorOption<T>::copy(const Configuration& from, Configured& to) const {
Option::copy<std::vector<T>>(this->name(), from, to);
}


//----------------------------------------------------------------------------------------------------------------------


} // namespace option

} // namespace eckit
} // namespace eckit::option
8 changes: 3 additions & 5 deletions src/eckit/option/VectorOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
/// @date Apr 2015


#ifndef VectorOption_H
#define VectorOption_H
#pragma once

#include <iosfwd>

Expand All @@ -33,7 +32,8 @@ class VectorOption : public BaseOption<std::vector<T>> {
// -- Contructors

VectorOption(const std::string& name, const std::string& description, size_t size, const char* separator = "/");
VectorOption(const std::string& name, const std::string& description, size_t size, const std::vector<T>& default_value, const char* separator = "/");
VectorOption(const std::string& name, const std::string& description, size_t size,
const std::vector<T>& default_value, const char* separator = "/");

// -- Destructor

Expand Down Expand Up @@ -106,5 +106,3 @@ class VectorOption : public BaseOption<std::vector<T>> {
} // namespace eckit::option

#include "eckit/option/VectorOption.cc"

#endif

0 comments on commit 70ff604

Please sign in to comment.