| 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 |
|
| 24 |
namespace Ioss { |
| 25 |
#if defined USE_ROBIN_MAP |
| 26 |
using FieldMapType = tsl::robin_pg_map<std::string, Field>; |
| 27 |
#else |
| 28 |
using FieldMapType = std::unordered_map<std::string, Field>; |
| 29 |
#endif |
| 30 |
using FieldValuePair = FieldMapType::value_type; |
| 31 |
|
| 32 |
/** \brief A collection of Ioss::Field objects. |
| 33 |
*/ |
| 34 |
class IOSS_EXPORT FieldManager |
| 35 |
{ |
| 36 |
public: |
| 37 |
FieldManager() = default; |
| 38 |
FieldManager(const FieldManager &other) |
| 39 |
: fields(other.fields) |
| 40 |
{ /* Do not make this `=default` since that breaks the thread-safe build */ } |
| 41 |
|
| 42 |
FieldManager &operator=(const FieldManager &) = delete; |
| 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; |
| 62 |
IOSS_NODISCARD NameList describe() const; |
| 63 |
|
| 64 |
// Returns the names of all fields with the specified 'RoleType' |
| 65 |
int describe(Field::RoleType role, NameList *names) const; |
| 66 |
IOSS_NODISCARD NameList describe(Field::RoleType role) const; |
| 67 |
|
| 68 |
IOSS_NODISCARD size_t count() const; |
| 69 |
|
| 70 |
private: |
| 71 |
FieldMapType fields; |
| 72 |
#if defined(IOSS_THREADSAFE) |
| 73 |
mutable std::mutex m_; |
| 74 |
#endif |
| 75 |
}; |
| 76 |
} // namespace Ioss |