0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd::json: Split path related from util header.

This commit is contained in:
Jason Volk 2019-01-12 11:51:15 -08:00
parent 6a0b384d8f
commit f6e1311e21
3 changed files with 36 additions and 25 deletions

View file

@ -50,6 +50,7 @@ namespace ircd::json
} }
#include "util.h" #include "util.h"
#include "path.h"
#include "array.h" #include "array.h"
#include "object.h" #include "object.h"
#include "vector.h" #include "vector.h"

35
include/ircd/json/path.h Normal file
View file

@ -0,0 +1,35 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_JSON_PATH_H
namespace ircd::json
{
/// Higher order type beyond a string to cleanly delimit multiple keys.
using path = std::initializer_list<string_view>;
std::ostream &operator<<(std::ostream &, const path &);
}
inline std::ostream &
ircd::json::operator<<(std::ostream &s, const path &p)
{
auto it(std::begin(p));
if(it != std::end(p))
{
s << *it;
++it;
}
for(; it != std::end(p); ++it)
s << '.' << *it;
return s;
}

View file

@ -17,10 +17,6 @@ namespace ircd::json
constexpr name_hash_t name_hash(const string_view name); constexpr name_hash_t name_hash(const string_view name);
constexpr name_hash_t operator ""_(const char *const name, const size_t len); constexpr name_hash_t operator ""_(const char *const name, const size_t len);
/// Higher order type beyond a string to cleanly delimit multiple keys.
using path = std::initializer_list<string_view>;
std::ostream &operator<<(std::ostream &, const path &);
extern const string_view literal_null; extern const string_view literal_null;
extern const string_view literal_true; extern const string_view literal_true;
extern const string_view literal_false; extern const string_view literal_false;
@ -43,27 +39,6 @@ namespace ircd::json
void valid_output(const string_view &, const size_t &expected); void valid_output(const string_view &, const size_t &expected);
} }
namespace ircd
{
using json::operator<<;
}
inline std::ostream &
ircd::json::operator<<(std::ostream &s, const path &p)
{
auto it(std::begin(p));
if(it != std::end(p))
{
s << *it;
++it;
}
for(; it != std::end(p); ++it)
s << '.' << *it;
return s;
}
constexpr ircd::json::name_hash_t constexpr ircd::json::name_hash_t
ircd::json::operator ""_(const char *const text, const size_t len) ircd::json::operator ""_(const char *const text, const size_t len)
{ {