parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
filesystem.h
Go to the documentation of this file.
1#pragma once
2
12#include <parcel/cell.h>
13#include <parcel/defaults.h>
14#include <parcel/descriptor.h>
15#include <parcel/json.h>
16
17#include <filesystem>
18#include <memory>
19#include <string>
20#include <string_view>
21
22namespace parcel {
23
27class PathCell : public BaseCell<PathCell, std::filesystem::path> {
29
30public:
31 using base_t::base_t;
32 using base_t::operator=;
33
34 static constexpr std::string_view kind_id = "fs:path";
35
36 [[nodiscard]] std::string to_string() const override {
37 return this->value.generic_string();
38 }
39
40 [[nodiscard]] json_t to_json() const override {
41 json_t j{
42 {ICell::KEY_KIND, kind_id},
43 {ICell::KEY_VALUE, this->value.generic_string()},
44 };
45 this->inject_display_info(j);
46 return j;
47 }
48
49 static cell_t from_json(json_t const& j, ParcelRegistry const&) {
50 const auto s = base_t::cell_from_json<std::string>(j, kind_id);
51 auto cell = std::make_shared<PathCell>(std::filesystem::path{s});
53 return cell;
54 }
55
56 static cell_type_descriptor_t descriptor() {
57 static const auto d = std::make_shared<SimpleCellTypeDescriptor<PathCell>>(
58 DisplayInfo{.name = "Path", .description = "Filesystem path (UTF-8 generic form)"});
59 return d;
60 }
61};
62
63} // namespace parcel
64
Core ICell interface, cell_t handle, BaseCell CRTP base, and CellLike concept.
std::shared_ptr< ICellTypeDescriptor > cell_type_descriptor_t
Shared handle to a runtime cell-type descriptor.
Definition cell.h:63
std::shared_ptr< ICell > cell_t
Shared handle to any ICell-derived value — the canonical cell pointer.
Definition cell.h:68
Runtime catalog of cell-type descriptors, keyed by wire kind id.
Definition registry.h:115
Cell wrapping std::filesystem::path as a portable UTF-8 string.
Definition filesystem.h:27
json_t to_json() const override
Default JSON serialization for cells with JSON-convertible storage.
Definition filesystem.h:40
std::string to_string() const override
Render the cell's value as a compact human-readable string.
Definition filesystem.h:36
comms::DisplayInfo DisplayInfo
Display info attached to a cell or descriptor — re-exported from comms::DisplayInfo.
Definition common.h:75
The default_cell_for<T> trait that drives FieldsBuilder field-type inference.
#define PARCEL_DEFAULT_CELL(CellT)
Register a cell type as the default wrapper for its payload type.
Definition defaults.h:269
auto cell(T &&v)
Wrap a raw value into its default cell, returning a shared_ptr to the cell.
Definition defaults.h:192
Runtime cell-type descriptors and the schema-graph mix-ins (IHasFields, ISubTypes).
nlohmann::json typedef shared across cell types.
nlohmann::json json_t
Project-wide alias for nlohmann::json.
Definition json.h:19
CRTP base providing default to_json / clone / kind plumbing on top of a storage type.
Definition cell.h:343
static void absorb_display_info(json_t const &j, Out &out)
Read "d" (if present) from a JSON object and assign it onto a cell.
Definition cell.h:499
std::filesystem::path value
Held value of the cell.
Definition cell.h:348
void inject_display_info(json_t &j) const
Copy this cell's display info (if any) into the JSON object under "d".
Definition cell.h:486
static constexpr std::string_view KEY_VALUE
JSON key for the value payload ("v").
Definition cell.h:88
static constexpr std::string_view KEY_KIND
JSON key for the kind id ("k").
Definition cell.h:86