NEML2 2.1.0
Loading...
Searching...
No Matches
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; }
69 FType & ftype() { return _metadata.ftype; }
70
72 const std::string & doc() const { return _metadata.doc; }
74 std::string & doc() { return _metadata.doc; }
75
77 bool required() const { return _metadata.required; }
79 bool & required() { return _metadata.required; }
80
82 bool suppressed() const { return _metadata.suppressed; }
84 bool & suppressed() { return _metadata.suppressed; }
85
87 bool user_specified() const { return _metadata.user_specified; }
89 bool & user_specified() { return _metadata.user_specified; }
90
92 bool defined() const { return _metadata.defined; }
94 bool & defined() { return _metadata.defined; }
95
100 virtual void print(std::ostream &) const = 0;
101
106 virtual std::unique_ptr<OptionBase> clone() const = 0;
107
108protected:
112 struct Metadata
113 {
126 std::string name = "";
136 std::string type = "";
157 std::string doc = "";
166 bool required = false;
176 bool suppressed = false;
185 bool user_specified = false;
192 bool defined = false;
193
194 bool operator==(const Metadata & other) const
195 {
196 return name == other.name && type == other.type && ftype == other.ftype && doc == other.doc &&
197 required == other.required && suppressed == other.suppressed &&
198 user_specified == other.user_specified && defined == other.defined;
199 }
200
201 bool operator!=(const Metadata & other) const { return !(*this == other); }
202
204};
205} // 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:69
bool & user_specified()
A writable reference to the option's user_specified status.
Definition OptionBase.h:89
bool & required()
A writable reference to the option's required status.
Definition OptionBase.h:79
OptionBase(OptionBase &&)=delete
const std::string & type() const
A readonly reference to the option's type.
Definition OptionBase.h:64
virtual ~OptionBase()=default
bool defined() const
Whether this option is defined.
Definition OptionBase.h:92
virtual bool operator==(const OptionBase &other) const =0
Test for option equality.
bool user_specified() const
Whether this option is user-specified.
Definition OptionBase.h:87
const std::string & doc() const
A readonly reference to the option's docstring.
Definition OptionBase.h:72
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:74
OptionBase & operator=(OptionBase &&)=delete
bool & suppressed()
A writable reference to the option's suppression status.
Definition OptionBase.h:84
bool required() const
Whether this option is required.
Definition OptionBase.h:77
bool suppressed() const
Whether this option is suppressed.
Definition OptionBase.h:82
bool & defined()
A writable reference to the option's defined status.
Definition OptionBase.h:94
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.h:31
std::ostream & operator<<(std::ostream &, const EnumSelection &)
FType
Role in a function definition.
Definition types.h:90
@ NONE
Definition types.h:91
Definition OptionBase.h:113
bool operator!=(const Metadata &other) const
Definition OptionBase.h:201
bool suppressed
Whether this option is suppressed.
Definition OptionBase.h:176
bool defined
Whether this option is defined.
Definition OptionBase.h:192
std::string type
Type of the option.
Definition OptionBase.h:136
bool required
Whether this option is required.
Definition OptionBase.h:166
FType ftype
Option's role in defining the function.
Definition OptionBase.h:146
std::string name
Name of the option.
Definition OptionBase.h:126
std::string doc
Option's doc string.
Definition OptionBase.h:157
bool operator==(const Metadata &other) const
Definition OptionBase.h:194
bool user_specified
Whether this option has been specified by the user from the input file.
Definition OptionBase.h:185