#include <partition_log.hxx>

Public Member Functions

 ~PartitionLog ()
 

Static Public Member Functions

static const String GetName ()
 
static bool WriteInfo (Writer &writer)
 
static bool WriteDoc (Writer &writer)
 
static bool WriteSrc (Writer &writer)
 
static IT Build (Ostream &os, Options opts, const IT &begin, const IT &pivot, const IT &end, const int offSet=0)
 
static IT Build (Writer &writer, Options opts, const IT &begin, const IT &pivot, const IT &end, const int offSet=0)
 

Private Member Functions

 PartitionLog (Ostream &os)
 
PartitionLog operator= (PartitionLog &)
 
IT Write (Options opts, const IT &begin, const IT &pivot, const IT &end, const int offset)
 

Static Private Member Functions

static IT Write (Writer &writer, Options opts, const IT &begin, const IT &pivot, const IT &end, const int offset)
 
static bool WriteParameters (Writer &writer, Options opts, const IT &begin, const IT &pivot, const IT &end, const int offset)
 
static IT WriteComputation (Writer &writer, const IT &begin, const IT &pivot, const IT &end, const int offset)
 

Private Attributes

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

Detailed Description

template<typename IT, typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
class SHA_Logger::PartitionLog< IT, Compare >

Definition at line 38 of file partition_log.hxx.

Constructor & Destructor Documentation

template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
SHA_Logger::PartitionLog< IT, Compare >::~PartitionLog ( )
inline

Definition at line 58 of file partition_log.hxx.

58 { assert(this->writer->IsComplete()); }
std::unique_ptr< Writer > writer
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
SHA_Logger::PartitionLog< IT, Compare >::PartitionLog ( Ostream os)
inlineprivate

Definition at line 83 of file partition_log.hxx.

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

Member Function Documentation

template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static IT SHA_Logger::PartitionLog< IT, Compare >::Build ( Ostream os,
Options  opts,
const IT &  begin,
const IT &  pivot,
const IT &  end,
const int  offSet = 0 
)
inlinestatic

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

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

Definition at line 65 of file partition_log.hxx.

67  {
68  std::unique_ptr<PartitionLog> builder = std::unique_ptr<PartitionLog>(new PartitionLog(os));
69  return builder->Write(opts, begin, pivot, end, offSet);
70  }
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static IT SHA_Logger::PartitionLog< IT, Compare >::Build ( Writer writer,
Options  opts,
const IT &  begin,
const IT &  pivot,
const IT &  end,
const int  offSet = 0 
)
inlinestatic

Use json writer passed as parameter to write iterator information.

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

Definition at line 76 of file partition_log.hxx.

78  {
79  return Write(writer, opts, begin, pivot, end, offSet);
80  }
IT Write(Options opts, const IT &begin, const IT &pivot, const IT &end, const int offset)
std::unique_ptr< Writer > writer
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static const String SHA_Logger::PartitionLog< IT, Compare >::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 43 of file partition_log.hxx.

43 { return "Partition"; }
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
PartitionLog SHA_Logger::PartitionLog< IT, Compare >::operator= ( PartitionLog< IT, Compare > &  )
inlineprivate

Definition at line 85 of file partition_log.hxx.

85 {} // Not Implemented
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
IT SHA_Logger::PartitionLog< IT, Compare >::Write ( Options  opts,
const IT &  begin,
const IT &  pivot,
const IT &  end,
const int  offset 
)
inlineprivate

Definition at line 87 of file partition_log.hxx.

88  { return Write(*this->writer, opts, begin, pivot, end, offset); }
IT Write(Options opts, const IT &begin, const IT &pivot, const IT &end, const int offset)
std::unique_ptr< Writer > writer
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static IT SHA_Logger::PartitionLog< IT, Compare >::Write ( Writer writer,
Options  opts,
const IT &  begin,
const IT &  pivot,
const IT &  end,
const int  offset 
)
inlinestaticprivate

Definition at line 90 of file partition_log.hxx.

92  {
93  writer.StartObject();
94 
95  // Do not write sequence if no data to be processed
96  const int _seqSize = static_cast<int>(std::distance(begin, end));
97  if (_seqSize < 2 || pivot == end)
98  {
99  Comment::Build(writer, "Sequence size too small to be processed.", 0);
100  // @todo return pivot
101  Operation::Return<bool>(writer, true);
102  return pivot;
103  }
104 
105  // Write description
107 
108  // Write parameters
109  WriteParameters(writer, opts, begin, pivot, end, offset);
110 
111  // Write computation
112  auto newPivot = WriteComputation(writer, begin, pivot, end, offset);
113 
114  writer.EndObject();
115 
116  return newPivot;
117  }
static Ostream & Build(Ostream &os, const String &message, int level=0, const String extent="normal")
Definition: comment.hxx:43
static Ostream & Build(Ostream &os, Options opts)
Definition: algorithm.hxx:39
static bool WriteParameters(Writer &writer, Options opts, const IT &begin, const IT &pivot, const IT &end, const int offset)
std::unique_ptr< Writer > writer
static IT WriteComputation(Writer &writer, const IT &begin, const IT &pivot, const IT &end, const int offset)
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static IT SHA_Logger::PartitionLog< IT, Compare >::WriteComputation ( Writer writer,
const IT &  begin,
const IT &  pivot,
const IT &  end,
const int  offset 
)
inlinestaticprivate

Definition at line 145 of file partition_log.hxx.

146  {
147  // Not part of the logs
148  auto _seqSize = static_cast<int>(std::distance(begin, end));
149  int _itIdx = offset;
150  int _storeIdx = offset;
151 
152  // Local logged variables
153  writer.Key("locals");
154  writer.StartArray();
155  auto it = Iterator::BuildIt<IT>(writer, kSeqName, "it", offset, begin, "Cur IT");
156  Iterator::BuildIt<IT>(writer, kSeqName, "last", offset + _seqSize - 1, end - 1, "Lst IT");
157  auto pivotValue = Value<typename std::iterator_traits<IT>::value_type>::
158  BuildValue(writer, "pivotValue", *pivot, "Keet pivot val.");
159  auto store = Iterator::BuildIt<IT>(writer, kSeqName, "store", offset, begin, "Store IT");
160  writer.EndArray();
161 
162  writer.Key("logs");
163  writer.StartArray();
164  Comment::Build(writer, "Start Partitinning", 0);
165 
166  Comment::Build(writer, "Put the pivot at the end for convenience", 0);
167  Operation::Swap(writer, "pivot", "last");
168  std::swap(*pivot, *(end - 1));
169 
170  Comment::Build(writer, "Swap each element with ", 0);
171  for (it = begin; it != end - 1; ++it, Operation::Set<int>(writer, "it", ++_itIdx))
172  {
173  if (Compare()(*it, pivotValue))
174  {
175  Comment::Build(writer, "it <= pivot: swap(it, store).", 1);
176  Operation::Swap(writer, "store", "it");
177  Operation::Set<int>(writer, "store", ++_storeIdx);
178  std::swap(*store, *it);
179  ++store;
180  } else
181  Comment::Build(writer, "pivot > it : Ignore element.", 1);
182  }
183 
184  Comment::Build(writer, "Replace the pivot at its good position and replace its value.", 0);
185  Operation::Set<int>(writer, "pivot", _storeIdx);
186  Operation::Swap(writer, "store", "last");
187  std::swap(*(end - 1), *store);
188 
189  // @todo Return Iterator
190  Operation::Return<bool>(writer, true);
191  writer.EndArray();
192  return store;
193  }
static Ostream & Build(Ostream &os, const String &message, int level=0, const String extent="normal")
Definition: comment.hxx:43
static const std::string kSeqName
Definition: typedef.hxx:41
std::unique_ptr< Writer > writer
static Ostream & Swap(Ostream &os, const String &aName, const String &bName)
Definition: operation.hxx:79
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static bool SHA_Logger::PartitionLog< IT, Compare >::WriteDoc ( Writer writer)
inlinestatic

Write algorithm decription

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

Definition at line 51 of file partition_log.hxx.

51 { return true; }
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static bool SHA_Logger::PartitionLog< IT, Compare >::WriteInfo ( Writer writer)
inlinestatic

Write algorithm information

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

Definition at line 47 of file partition_log.hxx.

47 { return true; }
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static bool SHA_Logger::PartitionLog< IT, Compare >::WriteParameters ( Writer writer,
Options  opts,
const IT &  begin,
const IT &  pivot,
const IT &  end,
const int  offset 
)
inlinestaticprivate

Definition at line 120 of file partition_log.hxx.

122  {
123  const int _pivIdx = static_cast<int>(std::distance(begin,pivot));
124  writer.Key("parameters");
125  writer.StartArray();
126  if (opts & OpIsSub)
127  {
128  const int _seqSize = static_cast<int>(std::distance(begin, end));
129  Iterator::Build(writer, kSeqName, "begin", offset);
130  Iterator::Build(writer, kSeqName, "pivot", offset + _pivIdx);
131  Iterator::Build(writer, kSeqName, "end", offset + _seqSize);
132  }
133  else
134  {
135  Array<IT>::Build(writer, kSeqName, "begin", begin, "end", end);
136  Iterator::Build(writer, kSeqName, "pivot", _pivIdx);
137  }
138  writer.EndArray();
139 
140  return true;
141  }
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 Ostream & Build(Ostream &os, const String &parentId, const String &name, int index, const String &comment="")
Definition: iterator.hxx:43
static const std::string kSeqName
Definition: typedef.hxx:41
std::unique_ptr< Writer > writer
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static bool SHA_Logger::PartitionLog< IT, Compare >::WriteSrc ( Writer writer)
inlinestatic

Write algorithm sources

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

Definition at line 55 of file partition_log.hxx.

55 { return true; }

Member Data Documentation

template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
std::unique_ptr<Stream> SHA_Logger::PartitionLog< IT, Compare >::stream
private

Definition at line 195 of file partition_log.hxx.

template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
std::unique_ptr<Writer> SHA_Logger::PartitionLog< IT, Compare >::writer
private

Definition at line 196 of file partition_log.hxx.


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