souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions | Protected Attributes
souffle::WriteStream Class Referenceabstract

#include <WriteStream.h>

Inheritance diagram for souffle::WriteStream:
Inheritance graph
Collaboration diagram for souffle::WriteStream:
Collaboration graph

Public Member Functions

template<typename T >
void writeAll (const T &relation)
 
template<>
void writeNext (const RamDomain *tuple)
 
template<typename T >
void writeSize (const T &relation)
 
 WriteStream (const std::map< std::string, std::string > &rwOperation, const SymbolTable &symbolTable, const RecordTable &recordTable)
 
- Public Member Functions inherited from souffle::SerialisationStream< true >
virtual ~SerialisationStream ()=default
 

Protected Member Functions

void outputADT (std::ostream &destination, const RamDomain value, const std::string &name)
 
void outputRecord (std::ostream &destination, const RamDomain value, const std::string &name)
 
template<typename Tuple >
void writeNext (const Tuple tuple)
 
virtual void writeNextTuple (const RamDomain *tuple)=0
 
virtual void writeNullary ()=0
 
virtual void writeSize (std::size_t)
 
- Protected Member Functions inherited from souffle::SerialisationStream< true >
 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)
 

Protected Attributes

const bool summary
 
- Protected Attributes inherited from souffle::SerialisationStream< true >
size_t arity
 
size_t auxiliaryArity
 
RO< RecordTable > & recordTable
 
RO< SymbolTable > & symbolTable
 
std::vector< std::string > typeAttributes
 
Json types
 

Additional Inherited Members

- Protected Types inherited from souffle::SerialisationStream< true >
using RO = std::conditional_t< readOnlyTables, const A, A >
 

Detailed Description

Definition at line 38 of file WriteStream.h.

Constructor & Destructor Documentation

◆ WriteStream()

souffle::WriteStream::WriteStream ( const std::map< std::string, std::string > &  rwOperation,
const SymbolTable symbolTable,
const RecordTable recordTable 
)
inline

Definition at line 40 of file WriteStream.h.

42  {
43  if (summary) {

References relation, summary, and writeSize().

Referenced by souffle::WriteCoutCSV::writeNextTuple().

Here is the call graph for this function:

Member Function Documentation

◆ outputADT()

void souffle::WriteStream::outputADT ( std::ostream &  destination,
const RamDomain  value,
const std::string &  name 
)
inlineprotected

Definition at line 124 of file WriteStream.h.

139  {
140  const RamDomain* tuplePtr = recordTable.unpack(value, 2);
141 
142  branchId = tuplePtr[0];
143  branchInfo = adtInfo["branches"][branchId];
144  branchTypes = branchInfo["types"].array_items();
145 
146  // Prepare branch's arguments for output.
147  branchArgs = [&]() -> const RamDomain* {
148  if (branchTypes.size() > 1) {
149  return recordTable.unpack(tuplePtr[1], branchTypes.size());
150  } else {
151  return &tuplePtr[1];
152  }
153  }();
154  } else {
155  branchInfo = adtInfo["branches"][branchId];
156  branchTypes = branchInfo["types"].array_items();
157  }
158 
159  destination << "$" << branchInfo["name"].string_value();
160 
161  if (branchTypes.size() > 0) {
162  destination << "(";
163  }
164 
165  // Print arguments
166  for (size_t i = 0; i < branchTypes.size(); ++i) {
167  if (i > 0) {
168  destination << ", ";
169  }
170 
171  auto argType = branchTypes[i].string_value();
172  switch (argType[0]) {
173  case 'i': destination << branchArgs[i]; break;
174  case 'f': destination << ramBitCast<RamFloat>(branchArgs[i]); break;
175  case 'u': destination << ramBitCast<RamUnsigned>(branchArgs[i]); break;
176  case 's': destination << symbolTable.unsafeResolve(branchArgs[i]); break;
177  case 'r': outputRecord(destination, branchArgs[i], argType); break;
178  case '+': outputADT(destination, branchArgs[i], argType); break;
179  default: fatal("Unsupported type attribute: `%c`", argType[0]);
180  }
181  }
182 
183  if (branchTypes.size() > 0) {
184  destination << ")";
185  }
186  }
187 };
188 
189 class WriteStreamFactory {
190 public:

◆ outputRecord()

void souffle::WriteStream::outputRecord ( std::ostream &  destination,
const RamDomain  value,
const std::string &  name 
)
inlineprotected

Definition at line 83 of file WriteStream.h.

86  {
87  destination << "nil";
88  return;
89  }
90 
91  auto&& recordTypes = recordInfo["types"];
92  const size_t recordArity = recordInfo["arity"].long_value();
93 
94  const RamDomain* tuplePtr = recordTable.unpack(value, recordArity);
95 
96  destination << "[";
97 
98  // print record's elements
99  for (size_t i = 0; i < recordArity; ++i) {
100  if (i > 0) {
101  destination << ", ";
102  }
103 
104  const std::string& recordType = recordTypes[i].string_value();
105  const RamDomain recordValue = tuplePtr[i];
106 
107  switch (recordType[0]) {
108  case 'i': destination << recordValue; break;
109  case 'f': destination << ramBitCast<RamFloat>(recordValue); break;
110  case 'u': destination << ramBitCast<RamUnsigned>(recordValue); break;
111  case 's': destination << symbolTable.unsafeResolve(recordValue); break;
112  case 'r': outputRecord(destination, recordValue, recordType); break;
113  case '+': outputADT(destination, recordValue, recordType); break;
114  default: fatal("Unsupported type attribute: `%c`", recordType[0]);
115  }
116  }
117  destination << "]";
118  }
119 
120  void outputADT(std::ostream& destination, const RamDomain value, const std::string& name) {
121  auto&& adtInfo = types["ADTs"][name];
122 

◆ writeAll()

template<typename T >
void souffle::WriteStream::writeAll ( const T &  relation)
inline

Definition at line 46 of file WriteStream.h.

48  {
49  if (relation.begin() != relation.end()) {
50  writeNullary();
51  }
52  return;
53  }
54  for (const auto& current : relation) {
55  writeNext(current);
56  }
57  }
58 
59  template <typename T>
60  void writeSize(const T& relation) {
61  writeSize(relation.size());

References relation, and writeNullary().

Here is the call graph for this function:

◆ writeNext() [1/2]

template<>
void souffle::WriteStream::writeNext ( const RamDomain tuple)
inline

Definition at line 203 of file WriteStream.h.

◆ writeNext() [2/2]

template<typename Tuple >
void souffle::WriteStream::writeNext ( const Tuple  tuple)
inlineprotected

Definition at line 78 of file WriteStream.h.

79  {
80  auto&& recordInfo = types["records"][name];
81 

References souffle::SerialisationStream< true >::types.

◆ writeNextTuple()

virtual void souffle::WriteStream::writeNextTuple ( const RamDomain tuple)
protectedpure virtual

◆ writeNullary()

virtual void souffle::WriteStream::writeNullary ( )
protectedpure virtual

◆ writeSize() [1/2]

template<typename T >
void souffle::WriteStream::writeSize ( const T &  relation)
inline

Definition at line 64 of file WriteStream.h.

64  :
65  const bool summary;
66 

Referenced by WriteStream().

◆ writeSize() [2/2]

virtual void souffle::WriteStream::writeSize ( std::size_t  )
inlineprotectedvirtual

Reimplemented in souffle::WriteCoutPrintSize.

Definition at line 73 of file WriteStream.h.

74  {
75  using tcb::make_span;

References TCB_SPAN_NAMESPACE_NAME::detail::data(), TCB_SPAN_NAMESPACE_NAME::make_span(), and writeNextTuple().

Here is the call graph for this function:

Field Documentation

◆ summary

const bool souffle::WriteStream::summary
protected

Definition at line 69 of file WriteStream.h.

Referenced by WriteStream().


The documentation for this class was generated from the following file:
souffle::SerialisationStream< true >::recordTable
RO< RecordTable > & recordTable
Definition: SerialisationStream.h:72
souffle::RamDomain
int32_t RamDomain
Definition: RamTypes.h:56
relation
Relation & relation
Definition: Reader.h:130
souffle::WriteStream::outputADT
void outputADT(std::ostream &destination, const RamDomain value, const std::string &name)
Definition: WriteStream.h:124
souffle::WriteStream::summary
const bool summary
Definition: WriteStream.h:69
souffle::SerialisationStream< true >::symbolTable
RO< SymbolTable > & symbolTable
Definition: SerialisationStream.h:71
souffle::WriteStream::writeNext
void writeNext(const Tuple tuple)
Definition: WriteStream.h:78
souffle::SerialisationStream< true >::types
Json types
Definition: SerialisationStream.h:73
souffle::WriteStream::outputRecord
void outputRecord(std::ostream &destination, const RamDomain value, const std::string &name)
Definition: WriteStream.h:83
i
size_t i
Definition: json11.h:663
souffle::WriteStream::writeNullary
virtual void writeNullary()=0
souffle::fatal
void fatal(const char *format, const Args &... args)
Definition: MiscUtil.h:198
TCB_SPAN_NAMESPACE_NAME::make_span
constexpr span< ElementType, Extent > make_span(span< ElementType, Extent > s) noexcept
Definition: span.h:543
souffle::WriteStream::writeSize
void writeSize(const T &relation)
Definition: WriteStream.h:64