-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: lazy object mapping traits
fix #696
- Loading branch information
1 parent
9daf71f
commit 9d30ea1
Showing
20 changed files
with
1,148 additions
and
681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// Copyright (c) 2023 Vinnie Falco ([email protected]) | ||
// Copyright (c) 2024 Alan de Freitas ([email protected]) | ||
// | ||
// Official repository: https://github.com/cppalliance/mrdocs | ||
// | ||
|
@@ -268,7 +269,7 @@ class MRDOCS_DECL | |
template <class F> | ||
requires | ||
std::invocable<F, String, Value> && | ||
detail::isExpected<std::invoke_result_t<F, String, Value>> | ||
mrdocs::detail::isExpected<std::invoke_result_t<F, String, Value>> | ||
Expected<void, typename std::invoke_result_t<F, String, Value>::error_type> | ||
visit(F&& fn) const; | ||
|
||
|
@@ -414,77 +415,6 @@ class MRDOCS_DECL | |
storage_type entries_; | ||
}; | ||
|
||
//------------------------------------------------ | ||
// | ||
// LazyObjectImpl | ||
// | ||
//------------------------------------------------ | ||
|
||
/** Abstract lazy object interface. | ||
This interface is used to define objects | ||
that are constructed on demand. | ||
The subclass must override the `construct` | ||
function to return the constructed object. | ||
It will typically also store whatever | ||
data is necessary to construct this object. | ||
When any of the object properties are accessed | ||
for the first time, the object is constructed. | ||
This can happen via any of the public functions, | ||
such as `get`, `set`, `size`, `exists`, or `visit`. | ||
The underlying object storage is only | ||
initialized when the first property is | ||
set or accessed. In practice, it means | ||
the object is never initialized if it's | ||
not used in a template. | ||
When the object is initialized, the | ||
*/ | ||
class MRDOCS_DECL | ||
LazyObjectImpl : public ObjectImpl | ||
{ | ||
#ifdef __cpp_lib_atomic_shared_ptr | ||
std::atomic<std::shared_ptr<ObjectImpl>> mutable sp_; | ||
#else | ||
std::shared_ptr<ObjectImpl> mutable sp_; | ||
#endif | ||
|
||
using impl_type = Object::impl_type; | ||
|
||
/* Return the constructed object. | ||
This function is invoked by all public | ||
functions that access the object properties. | ||
When invoked for the first time, the object | ||
is constructed and stored in the shared | ||
pointer. | ||
Further invocations return a reference | ||
to the existing value in the shared pointer. | ||
*/ | ||
ObjectImpl& obj() const; | ||
|
||
protected: | ||
/** Return the constructed object. | ||
Subclasses override this. | ||
The function is invoked just in time. | ||
*/ | ||
virtual Object construct() const = 0; | ||
|
||
public: | ||
std::size_t size() const override; | ||
Value get(std::string_view key) const override; | ||
void set(String key, Value value) override; | ||
bool visit(std::function<bool(String, Value)>) const override; | ||
bool exists(std::string_view key) const override; | ||
}; | ||
|
||
} // dom | ||
} // mrdocs | ||
} // clang | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,13 @@ | |
// | ||
// Copyright (c) 2023 Vinnie Falco ([email protected]) | ||
// Copyright (c) 2023 Krystian Stasiowski ([email protected]) | ||
// Copyright (c) 2024 Alan de Freitas ([email protected]) | ||
// | ||
// Official repository: https://github.com/cppalliance/mrdocs | ||
// | ||
|
||
#ifndef MRDOCS_API_DOM_DOMMETADATA_HPP | ||
#define MRDOCS_API_DOM_DOMMETADATA_HPP | ||
#ifndef MRDOCS_API_DOM_DOMCORPUS_HPP | ||
#define MRDOCS_API_DOM_DOMCORPUS_HPP | ||
|
||
#include <mrdocs/Platform.hpp> | ||
#include <mrdocs/Corpus.hpp> | ||
|
@@ -24,9 +25,14 @@ namespace mrdocs { | |
|
||
/** Front-end factory for producing Dom nodes. | ||
A @ref Generator subclasses this object and | ||
then uses it to create the Dom nodes used for | ||
rendering in template engines. | ||
This class keeps a reference to the @ref Corpus | ||
of extracted metadata, and provides a mechanism | ||
for constructing DOM nodes representing the metadata. | ||
A @ref Generator subclasses this object | ||
(e.g. @ref AdocCorpus and @ref HTMLCorpus), | ||
then uses it to create the Dom nodes used | ||
as input for rendering template engines. | ||
*/ | ||
class MRDOCS_DECL | ||
DomCorpus | ||
|
@@ -62,7 +68,7 @@ class MRDOCS_DECL | |
*/ | ||
Corpus const* operator->() const; | ||
|
||
/** Construct a Dom object representing the given symbol. | ||
/** Construct a lazy Dom object representing the specified symbol. | ||
This function is called internally when a `dom::Object` | ||
representing a symbol needs to be constructed because | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.