algorithm.hxx
Go to the documentation of this file.
1 /*===========================================================================================================
2  *
3  * SHA-L - Simple Hybesis Algorithm Logger
4  *
5  * Copyright (c) Michael Jeulin-Lagarrigue
6  *
7  * Licensed under the MIT License, you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * https://github.com/michael-jeulinl/Simple-Hybesis-Algorithms-Logger/blob/master/LICENSE
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License is
13  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and limitations under the License.
15  *
16  * The above copyright notice and this permission notice shall be included in all copies or
17  * substantial portions of the Software.
18  *
19  *=========================================================================================================*/
20 #ifndef MODULE_LOGGER_ALGORITHM_HXX
21 #define MODULE_LOGGER_ALGORITHM_HXX
22 
23 #include <Logger/options.hxx>
24 #include <Logger/typedef.hxx>
25 
26 namespace SHA_Logger
27 {
30  template <typename Algo>
32  {
33  public:
39  static Ostream& Build(Ostream& os, Options opts)
40  {
41  std::unique_ptr<Algo_Traits> algo = std::unique_ptr<Algo_Traits>(new Algo_Traits(os));
42  algo->Write(opts);
43 
44  return os;
45  }
46 
51  static Writer& Build(Writer& writer, Options opts)
52  {
53  Write(writer, opts);
54 
55  return writer;
56  }
57 
58  private:
59  Algo_Traits(Ostream& os) : stream(std::unique_ptr<Stream>(new Stream(os))),
60  writer(std::unique_ptr<Writer>(new Writer(*this->stream))) {}
61  Algo_Traits operator=(Algo_Traits&) {} // Not Implemented
62 
63  bool Write(Options opts) { return Write(*this->writer, opts); }
64 
65  static bool Write(Writer& writer, Options opts)
66  {
67  writer.Key("type");
68  writer.String(GetType());
69  if (opts & OpGetName || opts & OpIsSub)
70  {
71  writer.Key("name");
72  writer.String(Algo::GetName());
73  }
74  if (opts & OpGetDoc)
75  Algo::WriteDoc(writer);
76  if (opts & OpGetInfo)
77  Algo::WriteInfo(writer);
78  if (opts & OpGetSrc)
79  Algo::WriteSrc(writer);
80 
81  return true;
82  }
83 
84  static const String GetType() { return "algorithm"; }
85 
86  std::unique_ptr<Stream> stream; // Stream wrapper
87  std::unique_ptr<Writer> writer; // Writer used to fill the stream
88  };
89 }
90 
91 #endif // MODULE_LOGGER_ALGORITHM_HXX
static const String GetType()
Definition: algorithm.hxx:84
Algo_Traits(Ostream &os)
Definition: algorithm.hxx:59
const std::string String
Definition: typedef.hxx:36
static Ostream & Build(Ostream &os, Options opts)
Definition: algorithm.hxx:39
std::unique_ptr< Stream > stream
Definition: algorithm.hxx:86
rapidjson::OStreamWrapper Stream
Definition: typedef.hxx:32
static Writer & Build(Writer &writer, Options opts)
Definition: algorithm.hxx:51
Algo_Traits operator=(Algo_Traits &)
Definition: algorithm.hxx:61
static bool Write(Writer &writer, Options opts)
Definition: algorithm.hxx:65
bool Write(Options opts)
Definition: algorithm.hxx:63
std::ostream Ostream
Definition: typedef.hxx:37
std::unique_ptr< Writer > writer
Definition: algorithm.hxx:87
rapidjson::PrettyWriter< Stream > Writer
Definition: typedef.hxx:33