IOSS 2.0
Loading...
Searching...
No Matches
Ioss_FieldManager.h
Go to the documentation of this file.
1// Copyright(C) 1999-2024 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// See packages/seacas/LICENSE for details
6
7#pragma once
8
9#include "Ioss_CodeTypes.h"
10#include "Ioss_Field.h" // for Field, Field::RoleType
11#include <cstddef> // for size_t
12#include <string> // for string
13#include <vector> // for vector
14
15#include "ioss_export.h"
16
17#define USE_ROBIN_MAP
18#if defined USE_ROBIN_MAP
19#include <robin_map.h>
20#else
21#include <unordered_map>
22#endif
23
24namespace Ioss {
25#if defined USE_ROBIN_MAP
27#else
28 using FieldMapType = std::unordered_map<std::string, Field>;
29#endif
31
32 /** \brief A collection of Ioss::Field objects.
33 */
34 class IOSS_EXPORT FieldManager
35 {
36 public:
37 FieldManager() = default;
39 : fields(other.fields)
40 { /* Do not make this `=default` since that breaks the thread-safe build */ }
41
43
44 // If a field with the same 'name' exists, an exception will be thrown.
45 // Add the specified field to the list.
46 void add(const Field &new_field);
47
48 // Remove all fields of type `role`
49 void erase(Field::RoleType role);
50
51 // Assumes: Field 'name' must exist.
52 void erase(const std::string &field_name);
53
54 // Checks if a field with 'field_name' exists in the database.
55 IOSS_NODISCARD bool exists(const std::string &field_name) const;
56
57 IOSS_NODISCARD Field get(const std::string &field_name) const;
58 IOSS_NODISCARD const Field &getref(const std::string &field_name) const;
59
60 // Returns the names of all fields
61 int describe(NameList *names) const;
63
64 // Returns the names of all fields with the specified 'RoleType'
65 int describe(Field::RoleType role, NameList *names) const;
67
68 IOSS_NODISCARD size_t count() const;
69
70 private:
72#if defined(IOSS_THREADSAFE)
73 mutable std::mutex m_;
74#endif
75 };
76} // namespace Ioss
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:55
void add(const Field &new_field)
Add a field to the field manager.
Definition Ioss_FieldManager.C:25
IOSS_NODISCARD const Field & getref(const std::string &field_name) const
Get a reference to a field from the field manager.
Definition Ioss_FieldManager.C:68
IOSS_NODISCARD 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:40
FieldManager()=default
FieldManager(const FieldManager &other)
Definition Ioss_FieldManager.h:38
void erase(Field::RoleType role)
Remove all fields of type role from the field manager.
Definition Ioss_FieldManager.C:98
IOSS_NODISCARD size_t count() const
Get the number of fields in the field manager.
Definition Ioss_FieldManager.C:184
FieldManager & operator=(const FieldManager &)=delete
int describe(NameList *names) const
Get the names of all fields in the field manager.
Definition Ioss_FieldManager.C:130
FieldMapType fields
Definition Ioss_FieldManager.h:71
IOSS_NODISCARD Field get(const std::string &field_name) const
Get a field from the field manager.
Definition Ioss_FieldManager.C:53
Holds metadata for bulk data associated with a GroupingEntity.
Definition Ioss_Field.h:25
RoleType
Definition Ioss_Field.h:69
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
FieldMapType::value_type FieldValuePair
Definition Ioss_FieldManager.h:30
Ioss::NameList NameList
Definition Ioss_ChangeSetFactory.h:25
tsl::robin_pg_map< std::string, Field > FieldMapType
Definition Ioss_FieldManager.h:26
robin_map< Key, T, Hash, KeyEqual, Allocator, StoreHash, tsl::rh::prime_growth_policy > robin_pg_map
Definition robin_map.h:786