Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
type_io.h
Go to the documentation of this file.
1#ifndef joedb_type_io_declared
2#define joedb_type_io_declared
3
4#include "joedb/index_types.h"
5#include "joedb/Blob.h"
6
7#include <iostream>
8#include <cstdint>
9
10namespace joedb
11{
12 /// @addtogroup ui
13 /// @{
14
15 std::string read_string(std::istream &in);
16 void write_string(std::ostream &out, const std::string &s, bool json = false);
17 void write_sql_string(std::ostream &out, const std::string &s);
18
19 size_t utf8_display_size(const std::string &s);
20 uint32_t read_utf8_char(size_t &i, const std::string &s);
22 (
23 std::ostream &out,
24 const std::string &s,
25 size_t width,
26 bool flush_left = true
27 );
28
29 char get_hex_char_from_digit(uint8_t n);
30 uint8_t get_hex_digit_from_char(char c);
31 void write_hexa_character(std::ostream &out, uint8_t c);
32 void write_octal_character(std::ostream &out, uint8_t c);
33
34 int8_t read_int8(std::istream &in);
35 void write_int8(std::ostream &out, int8_t value);
36
37 bool read_boolean(std::istream &in);
38 void write_boolean(std::ostream &out, bool value);
39
40 void write_blob(std::ostream &out, const Blob blob);
41 Blob read_blob(std::istream &in);
42
43 inline std::ostream &operator<<(std::ostream &out, Table_Id table_id)
44 {
45 return out << to_underlying(table_id);
46 }
47 inline std::ostream &operator<<(std::ostream &out, Field_Id field_id)
48 {
49 return out << to_underlying(field_id);
50 }
51 inline std::ostream &operator<<(std::ostream &out, Record_Id record_id)
52 {
53 return out << to_underlying(record_id);
54 }
55
56 inline std::istream &operator>>(std::istream &in, Table_Id &table_id)
57 {
58 return in >> *(std::underlying_type<Table_Id>::type *)(&table_id);
59 }
60 inline std::istream &operator>>(std::istream &in, Field_Id &field_id)
61 {
62 return in >> *(std::underlying_type<Field_Id>::type *)(&field_id);
63 }
64 inline std::istream &operator>>(std::istream &in, Record_Id &record_id)
65 {
66 return in >> *(std::underlying_type<Record_Id>::type *)(&record_id);
67 }
68
69 #define PRIMITIVE_IO(type, type_id)\
70 inline type read_##type_id(std::istream &in)\
71 {type value = type(); in >> value; return value;}\
72 inline void write_##type_id(std::ostream &out, type value)\
73 {out << value;}
74
75 PRIMITIVE_IO(int32_t, int32)
76 PRIMITIVE_IO(int64_t, int64)
78 PRIMITIVE_IO(float, float32)
79 PRIMITIVE_IO(double, float64)
80 PRIMITIVE_IO(int16_t, int16)
81
82 #undef PRIMITIVE_IO
83
84 /// @}
85}
86
87#endif
void write_octal_character(std::ostream &out, uint8_t c)
std::istream & operator>>(std::istream &in, Table_Id &table_id)
Definition type_io.h:56
uint8_t get_hex_digit_from_char(char c)
Definition type_io.cpp:68
void write_boolean(std::ostream &out, bool value)
Definition type_io.cpp:233
void write_string(std::ostream &out, const std::string &s, bool json)
void write_sql_string(std::ostream &out, const std::string &s)
Definition type_io.cpp:90
uint32_t read_utf8_char(size_t &i, const std::string &s)
Definition type_io.cpp:121
void write_justified(std::ostream &out, const std::string &s, size_t width, bool flush_left)
Definition type_io.cpp:161
void write_hexa_character(std::ostream &out, uint8_t c)
Definition type_io.cpp:80
bool read_boolean(std::istream &in)
Definition type_io.cpp:215
size_t utf8_display_size(const std::string &s)
Definition type_io.cpp:104
int8_t read_int8(std::istream &in)
Definition type_io.cpp:206
void write_int8(std::ostream &out, int8_t value)
std::ostream & operator<<(std::ostream &out, Table_Id table_id)
Definition type_io.h:43
void write_blob(std::ostream &out, Blob blob)
Definition type_io.cpp:243
#define PRIMITIVE_IO(type, type_id)
Definition type_io.h:69
char get_hex_char_from_digit(uint8_t n)
std::string read_string(std::istream &in)
Definition type_io.cpp:12
Blob read_blob(std::istream &in)
Definition type_io.cpp:250
Definition Blob.h:7
constexpr std::underlying_type< Table_Id >::type to_underlying(Table_Id id)
Definition index_types.h:21