NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
OptionBase.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 <string>
28#include <memory>
29#include <iosfwd>
30
31#include "neml2/misc/types.h"
32
33namespace neml2
34{
35class OptionBase;
36
37// Streaming operators
38std::ostream & operator<<(std::ostream &, const OptionBase &);
39
44{
45public:
46 OptionBase() = default;
47
48 OptionBase(OptionBase &&) = delete;
49 OptionBase(const OptionBase &) = delete;
50 OptionBase & operator=(const OptionBase &) = delete;
52 virtual ~OptionBase() = default;
53
55 virtual bool operator==(const OptionBase & other) const = 0;
56
58 virtual bool operator!=(const OptionBase & other) const = 0;
59
61 const std::string & name() const { return _metadata.name; }
62
64 const std::string & type() const { return _metadata.type; }
65
67 const FType & ftype() const { return _metadata.ftype; }
68
70 FType & ftype() { return _metadata.ftype; }
71
73 const std::string & doc() const { return _metadata.doc; }
74
76 std::string & doc() { return _metadata.doc; }
77
79 const bool & suppressed() const { return _metadata.suppressed; }
80
82 bool & suppressed() { return _metadata.suppressed; }
83
85 const bool & user_specified() const { return _metadata.user_specified; }
86
88 bool & user_specified() { return _metadata.user_specified; }
89
94 virtual void print(std::ostream &) const = 0;
95
100 virtual std::unique_ptr<OptionBase> clone() const = 0;
101
102protected:
106 struct Metadata
107 {
120 std::string name = "";
130 std::string type = "";
151 std::string doc = "";
161 bool suppressed = false;
170 bool user_specified = false;
171
172 bool operator==(const Metadata & other) const
173 {
174 return name == other.name && type == other.type && ftype == other.ftype && doc == other.doc &&
176 }
177
178 bool operator!=(const Metadata & other) const { return !(*this == other); }
179
181};
182} // namespace neml2
Definition OptionBase.h:44
OptionBase & operator=(const OptionBase &)=delete
virtual void print(std::ostream &) const =0
const std::string & name() const
A readonly reference to the option's name.
Definition OptionBase.h:61
FType & ftype()
A writable reference to the option's ftype.
Definition OptionBase.h:70
bool & user_specified()
A writable reference to the option's user_specified status.
Definition OptionBase.h:88
OptionBase(OptionBase &&)=delete
const std::string & type() const
A readonly reference to the option's type.
Definition OptionBase.h:64
virtual ~OptionBase()=default
const bool & user_specified() const
A readonly reference to the option's user_specified status.
Definition OptionBase.h:85
const bool & suppressed() const
A readonly reference to the option's suppression status.
Definition OptionBase.h:79
virtual bool operator==(const OptionBase &other) const =0
Test for option equality.
const std::string & doc() const
A readonly reference to the option's docstring.
Definition OptionBase.h:73
virtual std::unique_ptr< OptionBase > clone() const =0
OptionBase(const OptionBase &)=delete
std::string & doc()
A writable reference to the option's docstring.
Definition OptionBase.h:76
OptionBase & operator=(OptionBase &&)=delete
bool & suppressed()
A writable reference to the option's suppression status.
Definition OptionBase.h:82
struct neml2::OptionBase::Metadata _metadata
OptionBase()=default
virtual bool operator!=(const OptionBase &other) const =0
Test for option inequality.
const FType & ftype() const
A readonly reference to the option's ftype.
Definition OptionBase.h:67
Definition DiagnosticsInterface.cxx:30
FType
Role in a function definition.
Definition types.h:91
@ NONE
Definition types.h:92
std::ostream & operator<<(std::ostream &os, const EnumSelection &es)
Definition EnumSelection.cxx:32
Definition OptionBase.h:107
bool operator!=(const Metadata &other) const
Definition OptionBase.h:178
bool suppressed
Whether this option is suppressed.
Definition OptionBase.h:161
std::string type
Type of the option.
Definition OptionBase.h:130
FType ftype
Option's role in defining the function.
Definition OptionBase.h:140
std::string name
Name of the option.
Definition OptionBase.h:120
std::string doc
Option's doc string.
Definition OptionBase.h:151
bool operator==(const Metadata &other) const
Definition OptionBase.h:172
bool user_specified
Whether this option has been specified by the user from the input file.
Definition OptionBase.h:170