NEML2 2.0.0
Loading...
Searching...
No Matches
CrossRef.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 <sstream>
28
29namespace neml2
30{
31// Forward decl
32template <typename T>
33class CrossRef;
34
36template <typename T>
37std::stringstream & operator>>(std::stringstream &, CrossRef<T> &);
38
52template <typename T>
54{
55public:
56 CrossRef() = default;
57
58 CrossRef(std::string raw)
59 : _raw_str(std::move(raw))
60 {
61 }
62
68 CrossRef<T> & operator=(const std::string & other);
69
76 operator T() const;
77
79 bool operator==(const CrossRef<T> & other) const { return _raw_str == other.raw(); }
80
86 const std::string & raw() const { return _raw_str; }
87
88 friend std::stringstream & operator>> <>(std::stringstream & in, CrossRef<T> &);
89
90private:
92 std::string _raw_str;
93};
94} // namespace neml2
95
97// Implementations
99
100namespace neml2
101{
102template <typename T>
103CrossRef<T> &
104CrossRef<T>::operator=(const std::string & other)
105{
106 _raw_str = other;
107 return *this;
108}
109
110template <typename T>
111std::ostream &
112operator<<(std::ostream & os, const CrossRef<T> & cr)
113{
114 os << cr.raw();
115 return os;
116}
117
118template <typename T>
119std::stringstream &
120operator>>(std::stringstream & ss, CrossRef<T> & cr)
121{
122 ss >> cr._raw_str;
123 return ss;
124}
125} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:54
CrossRef< T > & operator=(const std::string &other)
Assignment operator.
Definition CrossRef.h:104
bool operator==(const CrossRef< T > &other) const
Test equality.
Definition CrossRef.h:79
CrossRef(std::string raw)
Definition CrossRef.h:58
const std::string & raw() const
Get the raw string literal.
Definition CrossRef.h:86
CrossRef()=default
Definition CrossRef.cxx:31
std::ostream & operator<<(std::ostream &os, const EnumSelection &es)
Definition EnumSelection.cxx:31
std::stringstream & operator>>(std::stringstream &ss, EnumSelection &es)
Definition EnumSelection.cxx:38