NEML2 1.4.0
Loading...
Searching...
No Matches
LabeledAxisAccessor.h
1// Copyright 2023, 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#include <iostream>
29
30namespace neml2
31{
44{
45public:
47
48 template <typename... S>
49 LabeledAxisAccessor(const char * name, S &&... names)
50 {
51 validate_item_name(name);
52 _item_names.push_back(name);
53
54 (validate_item_name(names), ...);
55 (_item_names.push_back(names), ...);
56 }
57
58 template <typename... S>
59 LabeledAxisAccessor(const std::string & name, S &&... names)
60 {
61 validate_item_name(name);
62 _item_names.push_back(name);
63
64 (validate_item_name(names), ...);
65 (_item_names.push_back(names), ...);
66 }
67
68 LabeledAxisAccessor(const std::vector<std::string> & names);
69
71
74
75 operator std::vector<std::string>() const;
76
77 const std::vector<std::string> & vec() const { return _item_names; }
78
79 bool empty() const;
80
81 size_t size() const;
82
84 LabeledAxisAccessor with_suffix(const std::string & suffix) const;
85
88
90 LabeledAxisAccessor on(const LabeledAxisAccessor & axis) const;
91
93 LabeledAxisAccessor slice(size_t n) const;
94
96 LabeledAxisAccessor slice(size_t n1, size_t n2) const;
97
99 bool start_with(const LabeledAxisAccessor & axis) const;
100
101private:
103 void validate_item_name(const std::string &) const;
104
105 std::vector<std::string> _item_names;
106};
107
109bool operator==(const LabeledAxisAccessor & a, const LabeledAxisAccessor & b);
110
112bool operator!=(const LabeledAxisAccessor & a, const LabeledAxisAccessor & b);
113
118bool operator<(const LabeledAxisAccessor & a, const LabeledAxisAccessor & b);
119
124std::ostream & operator<<(std::ostream & os, const LabeledAxisAccessor & accessor);
125} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:44
LabeledAxisAccessor(const std::string &name, S &&... names)
Definition LabeledAxisAccessor.h:59
size_t size() const
Definition LabeledAxisAccessor.cxx:58
LabeledAxisAccessor append(const LabeledAxisAccessor &axis) const
Add a new item.
Definition LabeledAxisAccessor.cxx:72
LabeledAxisAccessor(const char *name, S &&... names)
Definition LabeledAxisAccessor.h:49
bool empty() const
Definition LabeledAxisAccessor.cxx:52
bool start_with(const LabeledAxisAccessor &axis) const
Check if this accessor begins with another accessor.
Definition LabeledAxisAccessor.cxx:103
LabeledAxisAccessor with_suffix(const std::string &suffix) const
Append a suffix to the item name.
Definition LabeledAxisAccessor.cxx:64
LabeledAxisAccessor slice(size_t n) const
Remove the leading n items from the labels.
Definition LabeledAxisAccessor.cxx:86
LabeledAxisAccessor & operator=(const LabeledAxisAccessor &other)
Assignment operator.
Definition LabeledAxisAccessor.cxx:43
LabeledAxisAccessor on(const LabeledAxisAccessor &axis) const
Re-mount the LabeledAxisAccessor on an axis by the axis accessor.
Definition LabeledAxisAccessor.cxx:78
const std::vector< std::string > & vec() const
Definition LabeledAxisAccessor.h:77
Definition CrossRef.cxx:32
std::ostream & operator<<(std::ostream &os, const OptionCollection &p)
Definition OptionCollection.cxx:37
bool operator==(const LabeledAxis &a, const LabeledAxis &b)
Definition LabeledAxis.cxx:461
bool operator!=(const LabeledAxis &a, const LabeledAxis &b)
Definition LabeledAxis.cxx:467
bool operator<(const LabeledAxisAccessor &a, const LabeledAxisAccessor &b)
The (strict) smaller than operator is created so as to use LabeledAxisAccessor in sorted data structu...
Definition LabeledAxisAccessor.cxx:131