Source
stdlib/parsers/json/fwd.hpp
1
// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).2
// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.3
#pragma once5
// cheatah::parsers::json — forward declarations for the whole value model (NOT a second Node;6
// the Node class lives only in node.hpp). These forwards must precede array.hpp / object.hpp so7
// that each token header can stand on its own (and so IntelliSense can compile them in isolation)8
// without pulling in the recursive Node class definition.9
//10
// Node is a forward-declarable class, which is what lets Array AND Object be templated on their11
// storage TYPE with real concepts (ArrayStorage / ObjectStorage), each with an owning backing12
// (std::vector, self-contained) and a viewing backing (std::span, into a Parser's pool).14
#include <span>15
#include <type_traits>16
#include <vector>18
namespace cheatah::parsers::json {20
class Node; // the value type; defined in node.hpp22
// ---- arrays ------------------------------------------------------------------24
// Backing storage for an Array: owning std::vector<Node> or non-owning std::span<const Node>.25
template <typename S>26
concept ArrayStorage =27
std::is_same_v<S, std::vector<Node>> || std::is_same_v<S, std::span<const Node>>;29
template <ArrayStorage S>30
class Array; // defined in array.hpp32
using OwnedArray = Array<std::vector<Node>>; // owns its elements (self-contained)33
using ArrayView = Array<std::span<const Node>>; // views elements in a pool (zero-copy)35
// ---- objects -----------------------------------------------------------------37
// One object member: a key (a string Node) and its value. A forward-declared STRUCT (not a38
// std::pair alias) so it can be named here while Node is incomplete and defined in node.hpp after39
// Node — std::span<const Member> would otherwise eagerly instantiate pair<Node,Node> (via span's40
// iterator concepts) while Node is still incomplete. (Node itself is forward-declarable, so41
// span<const Node> for ArrayView does not have this problem.)42
struct Member;44
// Backing storage for an Object, mirroring ArrayStorage: owning vector or non-owning span.45
template <typename S>46
concept ObjectStorage =47
std::is_same_v<S, std::vector<Member>> || std::is_same_v<S, std::span<const Member>>;49
template <ObjectStorage S>50
class Object; // defined in object.hpp52
using OwnedObject = Object<std::vector<Member>>; // owns its members (self-contained)53
using ObjectView = Object<std::span<const Member>>; // views members in a pool (zero-copy)55
} // namespace cheatah::parsers::json