icinga2/lib/base/dictionary.hpp

97 lines
2.3 KiB
C++
Raw Permalink Normal View History

Replace all existing copyright headers with `SPDX` headers I've used the following command to replace the original copyright header lines in a C-style comment block: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` For files that use shell-style comments (#) like CMakeLists.txt, I've used this command: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` And for SQL files: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ```
2026-01-27 09:06:40 -05:00
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-2.0-or-later
2012-04-18 09:22:25 -04:00
#ifndef DICTIONARY_H
#define DICTIONARY_H
2014-05-25 10:23:35 -04:00
#include "base/i2-base.hpp"
#include "base/atomic.hpp"
2014-05-25 10:23:35 -04:00
#include "base/object.hpp"
#include "base/objectlock.hpp"
2014-05-25 10:23:35 -04:00
#include "base/value.hpp"
2014-08-25 09:12:39 -04:00
#include <boost/range/iterator.hpp>
2013-03-16 16:18:53 -04:00
#include <map>
#include <shared_mutex>
#include <vector>
2013-03-16 16:18:53 -04:00
2012-04-18 09:22:25 -04:00
namespace icinga
{
typedef std::vector<std::pair<String, Value> > DictionaryData;
/**
* A container that holds key-value pairs.
2012-05-18 16:21:28 -04:00
*
* @ingroup base
*/
2018-01-04 00:11:04 -05:00
class Dictionary final : public Object
2012-04-18 09:22:25 -04:00
{
public:
2014-11-02 18:44:04 -05:00
DECLARE_OBJECT(Dictionary);
2012-04-18 09:22:25 -04:00
2012-09-19 06:32:39 -04:00
/**
* An iterator that can be used to iterate over dictionary elements.
*/
2013-03-16 16:18:53 -04:00
typedef std::map<String, Value>::iterator Iterator;
2014-05-11 00:00:34 -04:00
typedef std::map<String, Value>::size_type SizeType;
typedef std::map<String, Value>::value_type Pair;
Dictionary() = default;
Dictionary(const DictionaryData& other);
Dictionary(DictionaryData&& other);
Dictionary(std::initializer_list<Pair> init);
Value Get(const String& key) const;
bool Get(const String& key, Value *result) const;
2023-08-30 10:34:36 -04:00
const Value * GetRef(const String& key) const;
void Set(const String& key, Value value);
bool Contains(const String& key) const;
2013-03-01 06:07:52 -05:00
Iterator Begin();
Iterator End();
2012-04-20 07:49:04 -04:00
size_t GetLength() const;
void Remove(const String& key);
Iterator Remove(Iterator it);
2012-07-09 04:09:53 -04:00
void Clear();
void CopyTo(const Dictionary::Ptr& dest) const;
Dictionary::Ptr ShallowClone() const;
std::vector<String> GetKeys() const;
static Object::Ptr GetPrototype();
2017-12-13 06:54:14 -05:00
Object::Ptr Clone() const override;
String ToString() const override;
void Freeze();
bool Frozen() const;
ObjectLock LockIfRequired();
Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
void SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo) override;
bool HasOwnField(const String& field) const override;
bool GetOwnField(const String& field, Value *result) const override;
private:
2013-03-16 16:18:53 -04:00
std::map<String, Value> m_Data; /**< The data for the dictionary. */
mutable std::shared_timed_mutex m_DataMutex;
Atomic<bool> m_Frozen{false};
2012-04-18 09:22:25 -04:00
};
Dictionary::Iterator begin(const Dictionary::Ptr& x);
Dictionary::Iterator end(const Dictionary::Ptr& x);
2012-07-16 16:00:50 -04:00
}
extern template class std::map<icinga::String, icinga::Value>;
2012-07-16 16:00:50 -04:00
2012-04-18 09:22:25 -04:00
#endif /* DICTIONARY_H */