IOSS 2.0

Ioss_FieldManager.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2017 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of NTESS nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 #ifndef IOSS_Ioss_FieldManager_h
34 #define IOSS_Ioss_FieldManager_h
35
36 #include <Ioss_CodeTypes.h>
37 #include <Ioss_Field.h> // for Field, Field::RoleType
38 #include <Ioss_Utils.h> // for Utils
39 #include <cstddef> // for size_t
40 #include <functional> // for binary_function
41 #include <string> // for string
42 #include <unordered_map>
43 #include <vector> // for vector
44
45 namespace Ioss {
46 using FieldMapType = std::unordered_map<std::string, Field>;
47 using FieldValuePair = FieldMapType::value_type;
48
49 /** \brief A collection of Ioss::Field objects.
50 */
51 class FieldManager
52 {
53 public:
54 FieldManager() = default;
55 FieldManager(const FieldManager &) = delete;
56 FieldManager &operator=(const FieldManager &) = delete;
57 ~FieldManager() = default;
58
59 // Assumes: Field with the same 'name' does not exist.
60 // Add the specified field to the list.
61 void add(const Field &new_field);
62
63 // Assumes: Field 'name' must exist.
64 void erase(const std::string &field_name);
65
66 // Checks if a field with 'field_name' exists in the database.
67 bool exists(const std::string &field_name) const;
68
69 Field get(const std::string &field_name) const;
70 const Field &getref(const std::string &field_name) const;
71
72 // Returns the names of all fields
73 int describe(NameList *names) const;
74
75 // Returns the names of all fields with the specified 'RoleType'
76 int describe(Field::RoleType role, NameList *names) const;
77
78 size_t count() const;
79
80 private:
81 // Disallow copying; don't implement...
82 FieldMapType fields;
83 #if defined(IOSS_THREADSAFE)
84 mutable std::mutex m_;
85 #endif
86 };
87 } // namespace Ioss
88 #endif
Ioss::NameList
std::vector< std::string > NameList
Definition: Ioss_CodeTypes.h:44
Ioss_CodeTypes.h
Ioss::FieldManager::erase
void erase(const std::string &field_name)
Remove a field from the field manager.
Definition: Ioss_FieldManager.C:106
Ioss
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Ioss::Field::RoleType
RoleType
Definition: Ioss_Field.h:75
Ioss::FieldManager::fields
FieldMapType fields
Definition: Ioss_FieldManager.h:82
Ioss::FieldManager::getref
const Field & getref(const std::string &field_name) const
Get a reference to a field from the field manager.
Definition: Ioss_FieldManager.C:91
Ioss::FieldManager::describe
int describe(NameList *names) const
Get the names of all fields in the field manager.
Definition: Ioss_FieldManager.C:123
Ioss::FieldManager::count
size_t count() const
Get the number of fields in the field manager.
Definition: Ioss_FieldManager.C:164
Ioss::FieldManager::FieldManager
FieldManager()=default
Ioss_Utils.h
Ioss::FieldManager::exists
bool exists(const std::string &field_name) const
Checks if a field with a given name exists in the field manager.
Definition: Ioss_FieldManager.C:63
Ioss::FieldManager::~FieldManager
~FieldManager()=default
Ioss::FieldManager::add
void add(const Field &new_field)
Add a field to the field manager.
Definition: Ioss_FieldManager.C:48
Ioss_Field.h
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Ioss::FieldMapType
std::unordered_map< std::string, Field > FieldMapType
Definition: Ioss_FieldManager.h:46
Ioss::FieldManager::operator=
FieldManager & operator=(const FieldManager &)=delete
Ioss::FieldValuePair
FieldMapType::value_type FieldValuePair
Definition: Ioss_FieldManager.h:47
Ioss::FieldManager
A collection of Ioss::Field objects.
Definition: Ioss_FieldManager.h:51