OOFEM 3.0
Loading...
Searching...
No Matches
paramkey.h
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#ifndef paramkey_h
36#define paramkey_h
37
38
39#include <string>
40#include <unordered_map>
41#include <mutex>
42#include <shared_mutex>
43#include <atomic>
44#include <iostream>
45
46namespace oofem {
51class ParamKey {
52public:
53 using IndexType = size_t;
54
55 explicit ParamKey(std::string name)
56 : name_(std::move(name)), index_(generateUniqueIndex()) {
58 }
59
60 IndexType getIndex() const { return index_; }
61 const std::string& getName() const { return name_; }
62 const char* getNameCStr() const { return name_.c_str(); }
63
64 static std::string getDebugName(IndexType index) {
65 std::shared_lock lock(debugMutex_);
66 auto it = debugNames_.find(index);
67 return it != debugNames_.end() ? it->second : "<unknown>";
68 }
69
70 friend std::ostream& operator<<(std::ostream& os, const ParamKey& key) {
71 return os << "ParamKey{name=\"" << key.name_ << "\", index=" << key.index_ << "}";
72 }
73
74private:
75 std::string name_;
77
79 static std::atomic<IndexType> counter{0};
80 return counter.fetch_add(1, std::memory_order_relaxed);
81 }
82
83 static void registerDebugName(IndexType index, const std::string& name) {
84 std::unique_lock lock(debugMutex_);
85 debugNames_[index] = name;
86 }
87
88 static inline std::unordered_map<IndexType, std::string> debugNames_;
89 static inline std::shared_mutex debugMutex_;
90};
91
92} // end namespace oofem
93
94#endif // paramkey_h
IndexType getIndex() const
Definition paramkey.h:60
static IndexType generateUniqueIndex()
Definition paramkey.h:78
ParamKey(std::string name)
Definition paramkey.h:55
static void registerDebugName(IndexType index, const std::string &name)
Definition paramkey.h:83
static std::string getDebugName(IndexType index)
Definition paramkey.h:64
IndexType index_
Definition paramkey.h:76
const char * getNameCStr() const
Definition paramkey.h:62
const std::string & getName() const
Definition paramkey.h:61
friend std::ostream & operator<<(std::ostream &os, const ParamKey &key)
Definition paramkey.h:70
size_t IndexType
Definition paramkey.h:53
static std::unordered_map< IndexType, std::string > debugNames_
Definition paramkey.h:88
static std::shared_mutex debugMutex_
Definition paramkey.h:89
std::string name_
Definition paramkey.h:75

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011