NeoN
A framework for CFD software
Loading...
Searching...
No Matches
document.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <string>
8#include <functional>
9#include <atomic>
10
12
13namespace NeoN
14{
15
31using DocumentValidator = std::function<bool(Dictionary)>;
32
41bool hasId(Dictionary doc);
42
43
51class Document : public Dictionary
52{
53public:
54
59
66 Document(const Dictionary& dict, DocumentValidator validator = hasId);
67
76 bool validate() const;
77
83 std::string id() const { return get<std::string>("id"); }
84
85private:
86
92 static std::string generateID()
93 {
94 static std::atomic<int> counter {0};
95 return "doc_" + std::to_string(counter++);
96 }
97 std::string id_;
98 DocumentValidator validator_;
99};
100
110const std::string& name(const NeoN::Document& doc);
111
121std::string& name(NeoN::Document& doc);
122
123} // namespace NeoN
A class representing a dictionary that stores key-value pairs.
A class representing a document in a database.
Definition document.hpp:52
Document()
Constructs a Document with a unique ID.
bool validate() const
Validates the Document.
std::string id() const
Retrieves the ID of the Document.
Definition document.hpp:83
Document(const Dictionary &dict, DocumentValidator validator=hasId)
Constructs a Document with the given Dictionary and validator.
Definition array.hpp:20
bool hasId(Dictionary doc)
Checks if a Dictionary object has an "id" key.
std::function< bool(Dictionary)> DocumentValidator
A type alias for a function that validates a Dictionary object.
Definition document.hpp:31
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.