souffle
2.0.2-371-g6315b36
|
#include <ReadStream.h>
|
void | consumeChar (const std::string &str, char c, size_t &pos) |
| Read past given character, consuming any preceding whitespace. More...
|
|
void | consumeWhiteSpace (const std::string &str, size_t &pos) |
| Advance position in the string until first non-whitespace character. More...
|
|
RamDomain | readADT (const std::string &source, const std::string &adtName, size_t pos=0, size_t *charactersRead=nullptr) |
|
std::string | readAlphanumeric (const std::string &source, size_t &pos) |
| Read the next alphanumeric sequence (corresponding to IDENT). More...
|
|
virtual Own< RamDomain[]> | readNextTuple ()=0 |
|
RamDomain | readRecord (const std::string &source, const std::string &recordTypeName, size_t pos=0, size_t *charactersRead=nullptr) |
| Read a record from a string. More...
|
|
| ReadStream (const std::map< std::string, std::string > &rwOperation, SymbolTable &symTab, RecordTable &recTab) |
|
std::string | readUntil (const std::string &source, const std::string stopChars, const size_t pos, size_t *charactersRead) |
|
| SerialisationStream (RO< SymbolTable > &symTab, RO< RecordTable > &recTab, const std::map< std::string, std::string > &rwOperation) |
|
| SerialisationStream (RO< SymbolTable > &symTab, RO< RecordTable > &recTab, Json types) |
|
| SerialisationStream (RO< SymbolTable > &symTab, RO< RecordTable > &recTab, Json types, std::vector< std::string > relTypes, size_t auxArity=0) |
|
Definition at line 40 of file ReadStream.h.
◆ ReadStream()
souffle::ReadStream::ReadStream |
( |
const std::map< std::string, std::string > & |
rwOperation, |
|
|
SymbolTable & |
symTab, |
|
|
RecordTable & |
recTab |
|
) |
| |
|
inlineprotected |
◆ consumeChar()
void souffle::ReadStream::consumeChar |
( |
const std::string & |
str, |
|
|
char |
c, |
|
|
size_t & |
pos |
|
) |
| |
|
inlineprotected |
Read past given character, consuming any preceding whitespace.
Definition at line 290 of file ReadStream.h.
299 while (pos <
str.length() && std::isspace(
static_cast<unsigned char>(
str[pos]))) {
◆ consumeWhiteSpace()
void souffle::ReadStream::consumeWhiteSpace |
( |
const std::string & |
str, |
|
|
size_t & |
pos |
|
) |
| |
|
inlineprotected |
Advance position in the string until first non-whitespace character.
Definition at line 306 of file ReadStream.h.
309 virtual Own<ReadStream> getReader(
310 const std::map<std::string, std::string>&, SymbolTable&, RecordTable&) = 0;
References souffle::ReadStreamFactory::getReader().
◆ readADT()
RamDomain souffle::ReadStream::readADT |
( |
const std::string & |
source, |
|
|
const std::string & |
adtName, |
|
|
size_t |
pos = 0 , |
|
|
size_t * |
charactersRead = nullptr |
|
) |
| |
|
inlineprotected |
Definition at line 143 of file ReadStream.h.
149 throw std::invalid_argument(
"Missing ADT information: " + adtName);
157 for (
auto branch : branches.array_items()) {
159 if (branch[
"name"].string_value() == constructor) {
164 throw std::invalid_argument(
"Missing branch information: " + constructor);
167 assert(branchInfo[
"types"].is_array());
168 auto branchTypes = branchInfo[
"types"].
array_items();
171 if (branchTypes.empty()) {
172 if (charactersRead !=
nullptr) {
173 *charactersRead = pos - initial_position;
176 if (adtInfo[
"enum"].bool_value()) {
181 return recordTable.pack(toVector<RamDomain>(branchIdx, emptyArgs).
data(), 2);
186 std::vector<RamDomain> branchArgs(branchTypes.size());
188 for (
size_t i = 0;
i < branchTypes.size(); ++
i) {
189 auto argType = branchTypes[
i].string_value();
190 assert(!argType.empty());
199 switch (argType[0]) {
217 branchArgs[
i] =
readRecord(source, argType, pos, &consumed);
221 branchArgs[
i] =
readADT(source, argType, pos, &consumed);
224 default:
fatal(
"Invalid type attribute");
231 if (charactersRead !=
nullptr) {
232 *charactersRead = pos - initial_position;
237 if (branchArgs.size() != 1) {
238 return recordTable.pack(branchArgs.data(), branchArgs.size());
240 return branchArgs[0];
244 return recordTable.pack(toVector<RamDomain>(branchIdx, branchValue).data(), 2);
◆ readAll()
template<typename T >
void souffle::ReadStream::readAll |
( |
T & |
relation | ) |
|
|
inline |
◆ readAlphanumeric()
std::string souffle::ReadStream::readAlphanumeric |
( |
const std::string & |
source, |
|
|
size_t & |
pos |
|
) |
| |
|
inlineprotected |
Read the next alphanumeric sequence (corresponding to IDENT).
Consume preceding whitespace. TODO (darth_tytus): use std::string_view?
Definition at line 260 of file ReadStream.h.
268 size_t endOfSymbol = source.find_first_of(stopChars, pos);
270 if (endOfSymbol == std::string::npos) {
271 throw std::invalid_argument(
"Unexpected end of input");
◆ readNextTuple()
virtual Own<RamDomain[]> souffle::ReadStream::readNextTuple |
( |
| ) |
|
|
protectedpure virtual |
◆ readRecord()
RamDomain souffle::ReadStream::readRecord |
( |
const std::string & |
source, |
|
|
const std::string & |
recordTypeName, |
|
|
size_t |
pos = 0 , |
|
|
size_t * |
charactersRead = nullptr |
|
) |
| |
|
inlineprotected |
Read a record from a string.
- Parameters
-
source | - string containing a record |
recordTypeName | - record type. @parem pos - start parsing from this position. |
consumed | - if not nullptr: number of characters read. |
Definition at line 71 of file ReadStream.h.
76 if (charactersRead !=
nullptr) {
82 auto&& recordTypes = recordInfo[
"types"];
83 const size_t recordArity = recordInfo[
"arity"].long_value();
85 std::vector<RamDomain> recordValues(recordArity);
89 for (
size_t i = 0;
i < recordArity; ++
i) {
90 const std::string& recordType = recordTypes[
i].string_value();
97 switch (recordType[0]) {
115 recordValues[
i] =
readRecord(source, recordType, pos, &consumed);
119 recordValues[
i] =
readADT(source, recordType, pos, &consumed);
122 default:
fatal(
"Invalid type attribute");
128 if (charactersRead !=
nullptr) {
129 *charactersRead = pos - initial_position;
132 return recordTable.pack(recordValues.data(), recordValues.size());
135 RamDomain readADT(
const std::string& source,
const std::string& adtName,
size_t pos = 0,
136 size_t* charactersRead =
nullptr) {
137 const size_t initial_position = pos;
◆ readUntil()
std::string souffle::ReadStream::readUntil |
( |
const std::string & |
source, |
|
|
const std::string |
stopChars, |
|
|
const size_t |
pos, |
|
|
size_t * |
charactersRead |
|
) |
| |
|
inlineprotected |
Definition at line 274 of file ReadStream.h.
284 if (pos >=
str.length()) {
285 throw std::invalid_argument(
"Unexpected end of input");
The documentation for this class was generated from the following file:
RamSigned RamSignedFromString(const std::string &str, std::size_t *position=nullptr, const int base=10)
Converts a string to a RamSigned.
RO< RecordTable > & recordTable
RO< SymbolTable > & symbolTable
const array & array_items() const
void consumeWhiteSpace(const std::string &str, size_t &pos)
Advance position in the string until first non-whitespace character.
std::string readUntil(const std::string &source, const std::string stopChars, const size_t pos, size_t *charactersRead)
std::string readAlphanumeric(const std::string &source, size_t &pos)
Read the next alphanumeric sequence (corresponding to IDENT).
void fatal(const char *format, const Args &... args)
RamUnsigned RamUnsignedFromString(const std::string &str, std::size_t *position=nullptr, const int base=10)
Converts a string to a RamUnsigned.
constexpr auto data(C &c) -> decltype(c.data())
To ramBitCast(From source)
In C++20 there will be a new way to cast between types by reinterpreting bits (std::bit_cast),...
RamFloat RamFloatFromString(const std::string &str, std::size_t *position=nullptr)
Converts a string to a RamFloat.
RamDomain readADT(const std::string &source, const std::string &adtName, size_t pos=0, size_t *charactersRead=nullptr)
RamDomain readRecord(const std::string &source, const std::string &recordTypeName, size_t pos=0, size_t *charactersRead=nullptr)
Read a record from a string.
void consumeChar(const std::string &str, char c, size_t &pos)
Read past given character, consuming any preceding whitespace.