#include <binary_log.hxx>

Public Member Functions

 ~BinaryLog ()
 

Static Public Member Functions

static const String GetName ()
 
static bool WriteInfo (Writer &writer)
 
static bool WriteDoc (Writer &writer)
 
static bool WriteSrc (Writer &writer)
 
static OstreamBuild (Ostream &os, Options opts, const IT &begin, const IT &end, const T &key)
 
static WriterBuild (Writer &writer, Options opts, const IT &begin, const IT &end, const T &key)
 

Private Member Functions

 BinaryLog (Ostream &os)
 
BinaryLog operator= (BinaryLog &)
 
bool Write (Options opts, const IT &begin, const IT &end, const T &key)
 

Static Private Member Functions

static bool Write (Writer &writer, Options opts, const IT &begin, const IT &end, const T &key)
 
static bool WriteParameters (Writer &writer, const IT &begin, const IT &end, const T &key)
 
static bool WriteComputation (Writer &writer, const IT &begin, const IT &end, const T &key)
 

Private Attributes

std::unique_ptr< Streamstream
 
std::unique_ptr< Writerwriter
 

Detailed Description

template<typename IT, typename T, typename IsEqualT>
class SHA_Logger::BinaryLog< IT, T, IsEqualT >

Definition at line 35 of file binary_log.hxx.

Constructor & Destructor Documentation

template<typename IT , typename T , typename IsEqualT >
SHA_Logger::BinaryLog< IT, T, IsEqualT >::~BinaryLog ( )
inline

Definition at line 55 of file binary_log.hxx.

55 { assert(this->writer->IsComplete()); }
std::unique_ptr< Writer > writer
Definition: binary_log.hxx:183
template<typename IT , typename T , typename IsEqualT >
SHA_Logger::BinaryLog< IT, T, IsEqualT >::BinaryLog ( Ostream os)
inlineprivate

Definition at line 82 of file binary_log.hxx.

82  : stream(std::unique_ptr<Stream>(new Stream(os))),
83  writer(std::unique_ptr<Writer>(new Writer(*this->stream))) {}
std::unique_ptr< Writer > writer
Definition: binary_log.hxx:183
rapidjson::OStreamWrapper Stream
Definition: typedef.hxx:32
std::unique_ptr< Stream > stream
Definition: binary_log.hxx:182
rapidjson::PrettyWriter< Stream > Writer
Definition: typedef.hxx:33

Member Function Documentation

template<typename IT , typename T , typename IsEqualT >
static Ostream& SHA_Logger::BinaryLog< IT, T, IsEqualT >::Build ( Ostream os,
Options  opts,
const IT &  begin,
const IT &  end,
const T &  key 
)
inlinestatic

Instantiate a new json writer using the stream passed as argument, run and write algorithm computation information.

Returns
stream reference filled up with BinaryLog object information, error object information in case of failure.

Definition at line 62 of file binary_log.hxx.

63  {
64  std::unique_ptr<BinaryLog> builder = std::unique_ptr<BinaryLog>(new BinaryLog(os));
65  builder->Write(opts, begin, end, key);
66 
67  return os;
68  }
BinaryLog(Ostream &os)
Definition: binary_log.hxx:82
template<typename IT , typename T , typename IsEqualT >
static Writer& SHA_Logger::BinaryLog< IT, T, IsEqualT >::Build ( Writer writer,
Options  opts,
const IT &  begin,
const IT &  end,
const T &  key 
)
inlinestatic

Use json writer passed as parameter to write iterator information.

Returns
stream reference filled up with BinaryLog object information, error information in case of failure.

Definition at line 74 of file binary_log.hxx.

75  {
76  Write(writer, opts, begin, end, key);
77 
78  return writer;
79  }
std::unique_ptr< Writer > writer
Definition: binary_log.hxx:183
bool Write(Options opts, const IT &begin, const IT &end, const T &key)
Definition: binary_log.hxx:86
template<typename IT , typename T , typename IsEqualT >
static const String SHA_Logger::BinaryLog< IT, T, IsEqualT >::GetName ( )
inlinestatic
Todo:
Use string litteral for JSON description within c++ code eg https://cs.chromium.org/chromium/src/gpu/config/software_rendering_list_json.cc

Definition at line 40 of file binary_log.hxx.

40 { return "Binary_Sort"; }
template<typename IT , typename T , typename IsEqualT >
BinaryLog SHA_Logger::BinaryLog< IT, T, IsEqualT >::operator= ( BinaryLog< IT, T, IsEqualT > &  )
inlineprivate

Definition at line 84 of file binary_log.hxx.

84 {} // Not Implemented
template<typename IT , typename T , typename IsEqualT >
bool SHA_Logger::BinaryLog< IT, T, IsEqualT >::Write ( Options  opts,
const IT &  begin,
const IT &  end,
const T &  key 
)
inlineprivate

Definition at line 86 of file binary_log.hxx.

87  { return Write(*this->writer, opts, begin, end, key); }
std::unique_ptr< Writer > writer
Definition: binary_log.hxx:183
bool Write(Options opts, const IT &begin, const IT &end, const T &key)
Definition: binary_log.hxx:86
template<typename IT , typename T , typename IsEqualT >
static bool SHA_Logger::BinaryLog< IT, T, IsEqualT >::Write ( Writer writer,
Options  opts,
const IT &  begin,
const IT &  end,
const T &  key 
)
inlinestaticprivate

Definition at line 89 of file binary_log.hxx.

90  {
91  writer.StartObject();
92 
93  // Write description
95 
96  // Write parameters
97  WriteParameters(writer, begin, end, key);
98 
99  // Write computation
100  WriteComputation(writer, begin, end, key);
101 
102  writer.EndObject();
103 
104  return true;
105  }
std::unique_ptr< Writer > writer
Definition: binary_log.hxx:183
static Ostream & Build(Ostream &os, Options opts)
Definition: algorithm.hxx:39
static bool WriteComputation(Writer &writer, const IT &begin, const IT &end, const T &key)
Definition: binary_log.hxx:120
static bool WriteParameters(Writer &writer, const IT &begin, const IT &end, const T &key)
Definition: binary_log.hxx:108
template<typename IT , typename T , typename IsEqualT >
static bool SHA_Logger::BinaryLog< IT, T, IsEqualT >::WriteComputation ( Writer writer,
const IT &  begin,
const IT &  end,
const T &  key 
)
inlinestaticprivate

Definition at line 120 of file binary_log.hxx.

121  {
122  // Not part of the logs
123  int _lowIdx = 0;
124 
125  // Local logged variables
126  writer.Key("locals");
127  writer.StartArray();
128  auto index = Value<int>::BuildValue(writer, "index", -1);
129  auto seqSize = Value<int>::BuildValue(writer, "seqSize", static_cast<int>(std::distance(begin, end)));
130  auto lowIt = Iterator::BuildIt<IT>(writer, kSeqName, "lowIt", 0, begin);
131  auto highIt = Iterator::BuildIt<IT>(writer, kSeqName, "highIt", seqSize + 1, end);
132  auto middleIt = Iterator::BuildIt<IT>(writer, kSeqName, "middleIt", seqSize / 2,
133  lowIt + seqSize / 2, "Initiate index on the middle element of the sequence");
134  writer.EndArray();
135 
136  // Log algorithm operations
137  writer.Key("logs");
138  writer.StartArray();
139  Comment::Build(writer, "Start Binary Search", 0);
140  while (lowIt < highIt && index < 0)
141  {
142  if (IsEqualT()(key, *middleIt))
143  {
144  index = static_cast<int>(std::distance(begin, middleIt));
145 
146  Comment::Build(writer, "Found!", 1);
147  Operation::Set<int>(writer, "index", index);
148  break;
149  }
150  else if (key > *middleIt)
151  {
152  lowIt = middleIt + 1;
153  _lowIdx += seqSize / 2 + 1;
154  seqSize -= seqSize / 2 + 1;
155 
156  Comment::Build(writer, "(key > current): search upper sequence.", 1);
157  Operation::Set<int>(writer, "lowIt", _lowIdx);
158  }
159  else
160  {
161  highIt = middleIt;
162 
163  Comment::Build(writer, "(key < current): search lower sequence.", 1);
164  Operation::Set<int>(writer, "highIt", seqSize / 2);
165  seqSize -= seqSize / 2;
166  }
167 
168  middleIt = lowIt + seqSize / 2;
169  Comment::Build(writer, "Select the middle element of the remaining sequence.", 1);
170  Operation::Set<int>(writer, "middleIt", _lowIdx + seqSize / 2);
171  }
172 
173  // Logs failure
174  if (index < 0)
175  Comment::Build(writer, "Key not found.", 0);
176 
177  Operation::Return<int>(writer, index);
178  writer.EndArray();
179  return true;
180  }
std::unique_ptr< Writer > writer
Definition: binary_log.hxx:183
static Ostream & Build(Ostream &os, const String &message, int level=0, const String extent="normal")
Definition: comment.hxx:43
static const T & BuildValue(Writer &writer, const String &name, const T &value, const String &comment="")
Definition: value.hxx:57
static const std::string kSeqName
Definition: typedef.hxx:41
template<typename IT , typename T , typename IsEqualT >
static bool SHA_Logger::BinaryLog< IT, T, IsEqualT >::WriteDoc ( Writer writer)
inlinestatic

Write algorithm decription

Todo:
Use string litteral for JSON description within c++ code –> binary_desc.json.hxx

Definition at line 48 of file binary_log.hxx.

48 { return true; }
template<typename IT , typename T , typename IsEqualT >
static bool SHA_Logger::BinaryLog< IT, T, IsEqualT >::WriteInfo ( Writer writer)
inlinestatic

Write algorithm information

Todo:
Use string litteral for JSON description within c++ code –> binary_desc.json.hxx

Definition at line 44 of file binary_log.hxx.

44 { return true; }
template<typename IT , typename T , typename IsEqualT >
static bool SHA_Logger::BinaryLog< IT, T, IsEqualT >::WriteParameters ( Writer writer,
const IT &  begin,
const IT &  end,
const T &  key 
)
inlinestaticprivate

Definition at line 108 of file binary_log.hxx.

109  {
110  writer.Key("parameters");
111  writer.StartArray();
112  Array<IT>::Build(writer, kSeqName, "begin", begin, "end", end);
113  Value<T>::Build(writer, "key", key);
114  writer.EndArray();
115 
116  return true;
117  }
std::unique_ptr< Writer > writer
Definition: binary_log.hxx:183
static Ostream & Build(Ostream &os, const String &name, const T &value, const String &comment="")
Definition: value.hxx:44
static Ostream & Build(Ostream &os, const String &name, const String &beginName, const IT &begin, const String &endName, const IT &end)
Definition: array.hxx:42
static const std::string kSeqName
Definition: typedef.hxx:41
template<typename IT , typename T , typename IsEqualT >
static bool SHA_Logger::BinaryLog< IT, T, IsEqualT >::WriteSrc ( Writer writer)
inlinestatic

Write algorithm sources

Todo:
Use string litteral for JSON description within c++ code –> binary_desc.json.hxx

Definition at line 52 of file binary_log.hxx.

52 { return true; }

Member Data Documentation

template<typename IT , typename T , typename IsEqualT >
std::unique_ptr<Stream> SHA_Logger::BinaryLog< IT, T, IsEqualT >::stream
private

Definition at line 182 of file binary_log.hxx.

template<typename IT , typename T , typename IsEqualT >
std::unique_ptr<Writer> SHA_Logger::BinaryLog< IT, T, IsEqualT >::writer
private

Definition at line 183 of file binary_log.hxx.


The documentation for this class was generated from the following file: