#include <bubble_log.hxx>

Public Member Functions

 ~BubbleLog ()
 

Static Public Member Functions

static const String GetName ()
 eg https://cs.chromium.org/chromium/src/gpu/config/software_rendering_list_json.cc More...
 
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)
 
static WriterBuild (Writer &writer, Options opts, const IT &begin, const IT &end)
 

Private Member Functions

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

Static Private Member Functions

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

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::BubbleLog< IT, Compare >

Definition at line 39 of file bubble_log.hxx.

Constructor & Destructor Documentation

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

Definition at line 58 of file bubble_log.hxx.

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

Definition at line 85 of file bubble_log.hxx.

85  : stream(std::unique_ptr<Stream>(new Stream(os))),
86  writer(std::unique_ptr<Writer>(new Writer(*this->stream))) {}
std::unique_ptr< Stream > stream
Definition: bubble_log.hxx:188
rapidjson::OStreamWrapper Stream
Definition: typedef.hxx:32
std::unique_ptr< Writer > writer
Definition: bubble_log.hxx:189
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 Ostream& SHA_Logger::BubbleLog< IT, Compare >::Build ( Ostream os,
Options  opts,
const IT &  begin,
const IT &  end 
)
inlinestatic

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

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

Definition at line 65 of file bubble_log.hxx.

66  {
67  std::unique_ptr<BubbleLog> builder = std::unique_ptr<BubbleLog>(new BubbleLog(os));
68  builder->Write(opts, begin, end);
69 
70  return os;
71  }
BubbleLog(Ostream &os)
Definition: bubble_log.hxx:85
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static Writer& SHA_Logger::BubbleLog< IT, Compare >::Build ( Writer writer,
Options  opts,
const IT &  begin,
const IT &  end 
)
inlinestatic

Use json writer passed as parameter to write iterator information.

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

Definition at line 77 of file bubble_log.hxx.

78  {
79  Write(writer, opts, begin, end);
80 
81  return writer;
82  }
bool Write(Options opts, const IT &begin, const IT &end)
Definition: bubble_log.hxx:89
std::unique_ptr< Writer > writer
Definition: bubble_log.hxx:189
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static const String SHA_Logger::BubbleLog< IT, Compare >::GetName ( )
inlinestatic

eg https://cs.chromium.org/chromium/src/gpu/config/software_rendering_list_json.cc

Definition at line 43 of file bubble_log.hxx.

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

Definition at line 87 of file bubble_log.hxx.

87 {} // Not Implemented
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
bool SHA_Logger::BubbleLog< IT, Compare >::Write ( Options  opts,
const IT &  begin,
const IT &  end 
)
inlineprivate

Definition at line 89 of file bubble_log.hxx.

90  { return Write(*this->writer, opts, begin, end); }
bool Write(Options opts, const IT &begin, const IT &end)
Definition: bubble_log.hxx:89
std::unique_ptr< Writer > writer
Definition: bubble_log.hxx:189
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static bool SHA_Logger::BubbleLog< IT, Compare >::Write ( Writer writer,
Options  opts,
const IT &  begin,
const IT &  end 
)
inlinestaticprivate

Definition at line 92 of file bubble_log.hxx.

93  {
94  // Do not write sequence if no data to be processed
95  const int _seqSize = static_cast<int>(std::distance(begin, end));
96  if (_seqSize < 2)
97  {
98  Comment::Build(writer, "Sequence size too small to be processed.", 0);
99  Operation::Return<bool>(writer, true);
100  return true;
101  }
102 
103  writer.StartObject();
104 
105  // Write description
107 
108  // Write parameters
109  WriteParameters(writer, opts, begin, end);
110 
111  // Write computation
112  WriteComputation(writer, begin, end);
113 
114  writer.EndObject();
115 
116  return true;
117  }
static bool WriteComputation(Writer &writer, const IT &begin, const IT &end)
Definition: bubble_log.hxx:140
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
std::unique_ptr< Writer > writer
Definition: bubble_log.hxx:189
static bool WriteParameters(Writer &writer, Options opts, const IT &begin, const IT &end)
Definition: bubble_log.hxx:120
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static bool SHA_Logger::BubbleLog< IT, Compare >::WriteComputation ( Writer writer,
const IT &  begin,
const IT &  end 
)
inlinestaticprivate

Definition at line 140 of file bubble_log.hxx.

141  {
142  int _itIdx = 0;
143  int endIdx = -1;
144  bool hasSwapped;
145 
146  // Local logged variables
147  writer.Key("locals");
148  writer.StartArray();
149  auto curIt = Iterator::BuildIt<IT>(writer, kSeqName, "it", 0, begin);
150  auto pivot = Iterator::BuildIt<IT>(writer, kSeqName, "pivot", 1, begin + 1);
151  writer.EndArray();
152 
153  // Proceed sort
154  writer.Key("logs");
155  writer.StartArray();
156  // for each element - bubble it up until the end.
157  for (auto it = begin; it < end - 1; ++it, --endIdx)
158  {
159  hasSwapped = false;
160  _itIdx = 0;
161  for (; curIt < end + endIdx; ++curIt)
162  {
163  if (Compare()(*(curIt + 1), *curIt))
164  {
165  Operation::Swap(writer, "it", "pivot");
166  std::swap(*curIt, *(curIt + 1));
167  hasSwapped = true;
168  }
169 
170  Operation::Set<int>(writer, "it", ++_itIdx);
171  Operation::Set<int>(writer, "pivot", _itIdx + 1);
172  }
173 
174  if (!hasSwapped)
175  break;
176 
177  Operation::Set<int>(writer, "it", 0);
178  Operation::Set<int>(writer, "pivot", 1);
179  curIt = begin;
180  }
181 
182  Operation::Return<bool>(writer, true);
183  writer.EndArray();
184 
185  return true;
186  }
static const std::string kSeqName
Definition: typedef.hxx:41
std::unique_ptr< Writer > writer
Definition: bubble_log.hxx:189
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::BubbleLog< IT, Compare >::WriteDoc ( Writer writer)
inlinestatic

Write algorithm decription

Todo:
Use string litteral for JSON description within c++ code

Definition at line 51 of file bubble_log.hxx.

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

Write algorithm information

Todo:
Use string litteral for JSON description within c++ code

Definition at line 47 of file bubble_log.hxx.

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

Definition at line 120 of file bubble_log.hxx.

121  {
122  writer.Key("parameters");
123  writer.StartArray();
124  if (opts & OpIsSub)
125  {
126  const int _seqSize = static_cast<int>(std::distance(begin, end));
127  Iterator::Build(writer, kSeqName, "begin", 0);
128  Iterator::Build(writer, kSeqName, "end", _seqSize);
129  }
130  else
131  {
132  Array<IT>::Build(writer, kSeqName, "begin", begin, "end", end);
133  }
134  writer.EndArray();
135 
136  return true;
137  }
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
Definition: bubble_log.hxx:189
template<typename IT , typename Compare = std::less_equal<typename std::iterator_traits<IT>::value_type>>
static bool SHA_Logger::BubbleLog< IT, Compare >::WriteSrc ( Writer writer)
inlinestatic

Write algorithm sources

Todo:
Use string litteral for JSON description within c++ code

Definition at line 55 of file bubble_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::BubbleLog< IT, Compare >::stream
private

Definition at line 188 of file bubble_log.hxx.

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

Definition at line 189 of file bubble_log.hxx.


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