Beatmup
Beatmup::Listing Class Reference

Parser of simple YAML-like listings. More...

#include <listing.h>

Classes

class  Block
 Set of key-value pairs. More...
 
class  Parser
 

Public Member Functions

 Listing ()
 
 Listing (InputStream &stream)
 
 Listing (std::istream &stream)
 
void printOut (std::ostream &stream)
 Prints out the listing to an output stream. More...
 
bool has (const std::string &key) const
 Returns true if a specific chapter is present in the listing. More...
 
const std::vector< Block > & operator[] (const std::string &key) const
 Retrieves a chapter in the listing by its name. More...
 
void emplace (const std::string &key, Block &&block)
 Adds a block to a chapter. More...
 

Private Attributes

std::map< std::string, std::vector< Block > > chapters
 

Detailed Description

Parser of simple YAML-like listings.

Listing consists of chapters. Chapters are ordered sequences of blocks of key-value pairs: chapter1:

  • key: value arg: another value
  • key: stuff # comments are like this param: number chapter2:
  • stuff: stuff

Definition at line 40 of file listing.h.

Constructor & Destructor Documentation

◆ Listing() [1/3]

Beatmup::Listing::Listing ( )
inline

Definition at line 117 of file listing.h.

117 {}

◆ Listing() [2/3]

Listing::Listing ( InputStream stream)

Definition at line 174 of file listing.cpp.

174  {
175  Parser parser(stream, chapters);
176 }
std::map< std::string, std::vector< Block > > chapters
Definition: listing.h:114

◆ Listing() [3/3]

Listing::Listing ( std::istream &  stream)

Definition at line 179 of file listing.cpp.

179  {
180  Parser parser(stream, chapters);
181 }

Member Function Documentation

◆ printOut()

void Listing::printOut ( std::ostream &  stream)

Prints out the listing to an output stream.

Respects its own format when printing, i.e., the printed output may be reparsed into a listing.

Parameters
[in,out]streamThe output stream

Definition at line 184 of file listing.cpp.

184  {
185  for (auto& it : chapters) {
186  str << it.first << ":" << std::endl;
187  for (auto& i : it.second)
188  i.printOut(str);
189  }
190 }
JNIEnv jobject jstring str

◆ has()

bool Beatmup::Listing::has ( const std::string &  key) const
inline

Returns true if a specific chapter is present in the listing.

Parameters
[in]keyThe chapter name

Definition at line 132 of file listing.h.

132 { return chapters.find(key) != chapters.cend(); }

◆ operator[]()

const std::vector< Listing::Block > & Listing::operator[] ( const std::string &  key) const

Retrieves a chapter in the listing by its name.

If not found, an exception is thrown.

Parameters
[in]keyThe chapter name

Definition at line 192 of file listing.cpp.

192  {
193  auto it = chapters.find(key);
194  if (it == chapters.cend())
195  throw new InvalidArgument("Key not found: " + key);
196  return it->second;
197 }

◆ emplace()

void Listing::emplace ( const std::string &  key,
Block &&  block 
)

Adds a block to a chapter.

Parameters
[in]keyThe chapter name
[in]blockThe block

Definition at line 200 of file listing.cpp.

200  {
201  if (!has(key))
202  chapters.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple());
203  chapters[key].emplace_back(block);
204 }
bool has(const std::string &key) const
Returns true if a specific chapter is present in the listing.
Definition: listing.h:132

Member Data Documentation

◆ chapters

std::map<std::string, std::vector<Block> > Beatmup::Listing::chapters
private

Definition at line 114 of file listing.h.


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