NEML2 2.1.0
Loading...
Searching...
No Matches
Option.h
1// Copyright 2024, UChicago Argonne, LLC
2// All Rights Reserved
3// Software Name: NEML2 -- the New Engineering material Model Library, version 2
4// By: Argonne National Laboratory
5// OPEN SOURCE LICENSE (MIT)
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23// THE SOFTWARE.
24
25#pragma once
26
27#include <vector>
28
29#include "neml2/base/OptionBase.h"
30
31namespace neml2
32{
33namespace details
34{
46template <typename P>
47void _print_helper(std::ostream & os, const P *);
48template <typename P>
49void _print_helper(std::ostream & os, const std::vector<P> *);
50template <typename P>
51void _print_helper(std::ostream & os, const std::vector<std::vector<P>> *);
53template <>
54void _print_helper(std::ostream & os, const std::vector<bool> *);
56template <>
57void _print_helper(std::ostream & os, const char *);
59template <>
60void _print_helper(std::ostream & os, const unsigned char *);
62}
63
68template <typename T>
69class Option : public OptionBase
70{
71public:
72 Option(const std::string & name);
73
74 bool operator==(const OptionBase & other) const override;
75
76 bool operator!=(const OptionBase & other) const override;
77
79 const T & get() const { return _value; }
80
82 T & set() { return _value; }
83
84 void print(std::ostream &) const override;
85
86 std::unique_ptr<OptionBase> clone() const override;
87
88private:
90 T _value;
91};
92
93namespace details
94{
95// LCOV_EXCL_START
96template <typename P>
97void
98_print_helper(std::ostream & os, const P * option)
99{
100 os << *option;
101}
102
103template <typename P>
104void
105_print_helper(std::ostream & os, const std::vector<P> * option)
106{
107 for (const auto & p : *option)
108 os << p << " ";
109}
110
111template <typename P>
112void
113_print_helper(std::ostream & os, const std::vector<std::vector<P>> * option)
114{
115 for (const auto & pv : *option)
116 _print_helper(os, &pv);
117}
118} // namespace details
119// LCOV_EXCL_STOP
120} // namespace neml2
const std::string & name() const
A readonly reference to the option's name.
Definition OptionBase.h:61
OptionBase()=default
void print(std::ostream &) const override
T & set()
Definition Option.h:82
bool operator==(const OptionBase &other) const override
Test for option equality.
bool operator!=(const OptionBase &other) const override
Test for option inequality.
Option(const std::string &name)
std::unique_ptr< OptionBase > clone() const override
const T & get() const
Definition Option.h:79
Definition DiagnosticsInterface.h:31