C++ API¶
-
class
bakery_t
¶ Can load or save bakery data files.
Before loading data, options in the bakery can be configured. Directories to be included for recipe files can be added.
After loading data using the bakery, extra compilation information can be retrieved in the state.
Public Functions
-
bakery_t
()¶ Default constructor.
-
void
include
(const std::string &dir)¶ Includes a directory which may contain recipe files.
- Parameters
dir
: The directory.
-
void
include
(const std::list<std::string> &dirs)¶ Add a list of include directories.
- Parameters
dirs
: List of include directories.
-
const std::list<std::string> &
get_include_directories
() const¶ - Return
List of directories which may contain recipe files.
-
void
set_force_rebuild
(bool value)¶ Set or unset force_rebuild switch.
- Parameters
value
: New value.
-
bool
get_force_rebuild
() const¶ - Return
force_rebuild setting.
-
void
set_verbose
(bool value)¶ Enable or disable verbosity. When enabled, bakery directly prints to stdout information when loading data, and error messages. Verbose option is disabled by default.
- Parameters
value
: True to enable verbosity, false to disable.
-
bool
get_verbose
() const¶ - Return
true if verbosity is enabled, false otherwise.
-
void
set_abort_on_error
(bool value)¶ Enable or disable abort on error mode. When enabled, any error encountered during data loading will call std::abort to terminate the program in the most possible brutal way. This option is for thoose who don’t want to deal with errors themselves.
- Parameters
value
: True to abort on error, false to continue execution.
-
bool
get_abort_on_error
() const¶ - Return
true if bakery aborts on errors, false otherwise.
-
input_t
load_input
(const std::string &path, log_t &log)¶ Load a bakery data file. Rebuilds the binary cache if necessary, or if the force_build option is enabled. If options for loading data has to be set, use the bakery_t class instead.
- Return
input_t for deserialization.
- Parameters
path
: Path to the datafile.log
: Where error messages are written in case of problem.
-
template<typename ...
T
>
log_tload
(const std::string &path, T&... dest)¶ Load a bakery data file and deserialize it in destination variables.
- Return
Log object containing potential error messages.
- Parameters
path
: Path to the data file.dest
: Reference to destination variable.
-
template<typename ...
T
>
log_tsave
(const std::string &dat_path, const std::string &rec_path, const T&... src)¶ Save a bakery data in binary using serialization, and then decompiles it to regenerate a text data file.
- Return
false in case of error (if abort_on_error is disabled), true if the binary and data files have been written.
- Parameters
dat_path
: Path to the data file.rec_path
: Path to the recipe file to be used for decompilation.
-
-
class
input_t
¶ Deserialization class. Non-copyable. Movable.
Public Functions
-
input_t
()¶ Default constructor. Set stream to null. The input cannot be deserialized after default construction.
-
~input_t
()¶ Destructor. Closes the stream.
-
operator bool
() const¶ - Return
True if Bakery successfully opened the file.
-
bool
good
() const¶ - Return
True if Bakery successfully opened the file.
-
void
set_stream
(std::istream *stream)¶ Sets the stream used for deserialization.
- Parameters
stream
: Stream pointer. This class takes ownership of the pointer.
-
template<typename
T
>
input_t &operator>>
(T &t)¶ Reads input into t using bakery deserialization.
- Return
this
- Parameters
t
: Destination data.
-
-
class
log_t
¶ Log filled during the compilation or decompilation process.
Public Functions
-
log_t
()¶ Constructor
-
size_t
get_error_count
() const¶ - Return
Count of error messages.
-
void
print
() const¶ Print to std::cout all the messages.
-
std::string
to_string
() const¶ - Return
A string representing the status. It contains all messages.
-
void
add_message
(const log_message_t &message)¶ Adds a message.
- Parameters
message
: The message.
-
void
add_message
(log_message_type_t type, const std::string &text)¶ Adds a message.
- Parameters
type
: type of message.text
: Text of the message.
-
void
error
(const std::string &text)¶ Adds an error message.
- Parameters
text
: Text of the message.
-
void
warning
(const std::string &text)¶ Adds a warning message.
- Parameters
text
: Text of the message.
-
const std::list<log_message_t> &
get_messages
() const¶ - Return
List of compilation messages.
-
void
clear
()¶ Deletes all the messages from the log.
-
size_t
size
() const¶ - Return
Number of messages in the log. To get the number of error messages, use get_error_count.
-
void
set_rebuilt
(bool value)¶ Set the rebuilt flag value. Called by bakery when loading a data file.
-
bool
has_rebuilt
() const¶ - Return
True if the binary has been rebuilt. False if it has been loaded from cache.
-
operator bool
() const¶ - Return
True if log has no error messages.
-
bool
good
() const¶ - Return
True if log has no error messages.
-
-
class
log_message_t
¶ Holds a message resulting from a compilation (error message, warning message…).
Public Functions
-
log_message_t
()¶ Default constructor.
-
log_message_t
(log_message_type_t type_, const std::string &text_)¶ Constructor.
- Parameters
type_
: Type of the message.text_
: Text of the message.
-
std::string
to_string
() const¶ - Return
A string representing the message.
-
bool
operator==
(const log_message_t &other) const¶ - Return
true if this has the same text and message type as other.
-
bool
operator!=
(const log_message_t &other) const¶ - Return
true if this has a different text or message type as other.
-