-
Notifications
You must be signed in to change notification settings - Fork 543
CXX-3082 Add Comprehensive Examples (bsoncxx) #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Additional remarks:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comment changes but otherwise LGTM
src/bsoncxx/include/bsoncxx/doc.hpp
Outdated
|
||
/// | ||
/// @page topic-mongocxx-examples Using the mongocxx Library | ||
/// @brief Examples of how to use the bsoncxx library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// @brief Examples of how to use the bsoncxx library. | |
/// @brief Examples of how to use the mongocxx library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
ASSERT(!bsoncxx::validate(bytes, length, options, &offset)); | ||
|
||
// Offset of `"a.b": 1` relative to start of the sub-document. (CDRIVER-5710) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Offset of `"a.b": 1` relative to start of the sub-document. (CDRIVER-5710) | |
// Offset of `"$numberInt": "123"` relative to start of the sub-document. (CDRIVER-5710) |
// [0,123,-1] | ||
ASSERT((d128{0x303e000000000000, 0x000000000000007b}) == d128{"12.3"}); | ||
|
||
// [0,123,-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// [0,123,-1] | |
// [1,123,-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting. The new examples seem comprehensive, tested, and easy to follow. Left minor suggestions, but otherwise LGTM.
examples/api/bsoncxx/examples/bson_documents/create_doc/builder_sub_document.cpp
Outdated
Show resolved
Hide resolved
runner.set_jobs(0); | ||
} | ||
|
||
return runner.run(); | ||
return runner.run(); // Return directly from forked processes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaked an upcoming change. Disregard the presence of this comment for now.
Summary
Resolves CXX-3082 for bsoncxx. Comprehensive examples for mongocxx will be included in a followup PR.
Build and run of examples are verified by this patch. To review the displayed examples in API doc pages, the API docs must be built locally.
This PR is a smaller-sized demonstration of the design of API doc examples (bsoncxx only). The various patterns used in this PR will be extended to mongocxx library comprehensive examples.
Topic Pages
This PR adds the first set of "Topic" pages following their preparation by #1183.
The "Using" pages implement the "How-To Guides" quadrant of the Diataxis compass, as clearly indicated by the page descriptions ("How to ..."). The "About" pages implement the "Explanation" quadrant of the Diataxis map. The focus of CXX-3082 is on implementing "How-To Guides", so the About pages are left empty besides their description. They are still included in this PR to record their intended purpose.
The Topic pages directly correspond to the
\page
Doxygen commands used indoc.hpp
. Each\page
defines the name, title, and contents of a single Topic page. The page name (e.g.topic-bsoncxx-examples-bson-documents
) is very important: this determines the corresponding page URL (e.g./topic-bsoncxx-examples-bson-documents.html
). Therefore, for link stability purposes, they must be defined and used with care. The page title (e.g. "BSON Documents") is cosmetic and does not require such stability.Important
The
<name>
in@page <name> <title>
must be stable! (This may not be as necessary if we revise how/api/current
links are handled.)The page hierarchy is determined by use of the
\subpage
command. I expect (and recommend) only a single level of nesting to ever be necessary. This will be elaborated on further below.Markdown Files
To avoid extreme bloating of the
doc.hpp
file, as well as to facilitate easier authoring of topic pages, the contents of each page are written as Markdown files underdocs/api/
. Their layout approximately reflect the page name and hierarchy (e.g.docs/bsoncxx/examples/bson_documents/
fortopic-bsoncxx-examples-bson-documents
page content). This design also permits standalone formatting and preview of the Markdown files, isolated from Doxygen-specific content.Markdown file content is imported into Doxygen pages via
\include{doc}
. The{doc}
indicates the contents of the included file are documentation, not code. This structure permits flexibility of content layout and organization on a per-page level, e.g. splitting page content across multiple files as done for the "BSON Documents" page:Important
The layout and organization of contents of a page are flexible.
Section IDs are generated using GitHub style ("An Example Section" ->
an-example-section
) per theMARKDOWN_ID_STYLE = GITHUB
as set by #1185. This permits linking directly to individual examples from regular API doc pages (this not yet utilized by this PR). I do not think going out of our way to preserve the stability of section IDs will be necessary, but it is something to keep in mind regardless.Example Code
Examples are embedded in pages via the
\snippet
Doxygen command. Each example is implemented as an individual, standalone component underexamples/api/
. Their layout approximately reflect the layout of the page content that embeds them, e.g. for the Decimal128 page:Note
For forward compatibility, current examples are grouped under the
examples/api/bsoncxx/examples/
subdirectory to distinguish them from examples which may be embedded in regular API doc pages. e.g. ifbsoncxx/v_noabi/bsoncxx/types.hpp
were to include a snippet as part of its API documentation, the code being included would be placed inexamples/api/bsoncxx/v_noabi/bsoncxx/types/n_snippet.cpp
. This is not yet utilized by this PR.Every example code block is deliberately included in a dedicated (sub)section that describes the goal of the example being described (e.g. "How To > Query an Element > In a Document > For a Single Type"). Every example code block corresponds to a single C++ source file containing an
[Example]
block ID. This ensures a one-to-one correspondance between example code blocks in a topic page and source files underexamples/api/bsoncxx/examples/
.Various patterns for how to include example code in pages were considered and experimented with. In the end, keeping the Markdown files as simple as possible (sections +
\snippet <file> Example
) was determined to be the most straightforward and flexible. Thedoc.hpp
defines pages and their hierarchy, the Markdown files define the page contents, and examples sources individually provide the contents of a single example. This keeps every individual file and component minimal in their complexity and dependencies.API Examples Runner
Unfortunately during development of this PR, the length and depth of examples being compiled were too much for some Windows distros to handle:
Therefore, rather than fighting against Windows
MAX_PATH
, the API examples were refactored to use a singleapi-runner
executable instead of every component generating its own (lengthy) executable target. The runner behaves as a simplified, rudimentary job scheduler that registers and executes each API example component in its own thread. This is deliberately implemented a manner that is similar to Catch2 test case registration.Note
Using Catch2 in API examples was considered but rejected to avoid imposing C++14 build requirements on API examples.
Miscellaneous
Other notes regarding changes in this PR:
--order rand
flag, but alas.) The benefits of this implementation will be better realized when mongocxx examples that run server commands are introduced..compare() == 0
style of string comparison. We may be able to avoid this if we start compiling on CI withENABLE_BSONCXX_POLY_USE_IMPLS=ON
by default (as is recommended by the CMake configuration warning) or dropped entirely as part of CXX-2797.