Class to implement reading, writing, adding, deleting, and formatting messages from the SMK .json file.
More...
#include <smk.hpp>

Public Member Functions | |
| SMK (void) | |
| Constructor. More... | |
| ~SMK (void) | |
| Destructor. More... | |
| json | load (void) |
| Load the json from filename. More... | |
| SMK & | save (json &j) |
| Save the json to filename. More... | |
| SMK & | show_usage (const std::string &arg0) |
| Show a block of text that describes how to use SMK. More... | |
| SMK & | reset (void) |
| Erase the json in filename and start with a brand new json structure. More... | |
| SMK & | clean (void) |
| Clean up old entries in filename. Will only keep the last few recent messages. More... | |
| SMK & | add (const std::string &priority, const std::string &msg, const bool unique=false) |
| Add or update a message in filename. More... | |
| SMK & | unique (const std::string &priority, const std::string &msg) |
Same thing as add() but sets the unique parameter to true. More... | |
| SMK & | del (const std::string &parm) |
| Delete a message from the json in filename. More... | |
| SMK & | dump (void) |
| Dump the full json in filename to stdout. More... | |
| SMK & | format (void) |
| Format all the message to an easy-to-read block of text. This can be used as a login message. More... | |
| SMK & | get_all (void) |
| Get a tab-delimited set of all messages. More... | |
| SMK & | get_recent (void) |
| Get a tab-delimited set of recent messages. More... | |
| SMK & | get (const std::string &parm) |
Get a specific message from filename. The parm must be a valid numerical index, starting at 1. More... | |
Protected Member Functions | |
| SMK & | initialize_json (json &j) |
| Insert a few housekeeping items into the json. More... | |
| SMK & | sort_messages_by_timestamp (json &j) |
| Ensure the messages in filename are sorted in order from oldest to newest. More... | |
| std::string | format (const std::time_t now, const std::time_t tt) |
Format the given timestamp as an easy-to-read text string, such as "35 seconds ago" or "2 days ago". More... | |
| std::string | format (const int priority) |
Format the numeric priority index to a text string, such as high or low. More... | |
| SMK & | display_msg (const json &j) |
| Format the given message or messages as a tab-delimited block of text. More... | |
Protected Attributes | |
| std::string | filename |
| The location where the json structure is stored. This file must have read/write permissions. More... | |
| int | s |
| Mutex and semaphores are badly broken on Linux, and file locking not accessible from C++ streams. More... | |
Class to implement reading, writing, adding, deleting, and formatting messages from the SMK .json file.
| SMK::SMK | ( | void | ) |
Constructor.
References s.
| SMK::~SMK | ( | void | ) |
Destructor.
References s.
| SMK & SMK::add | ( | const std::string & | priority, |
| const std::string & | msg, | ||
| const bool | unique = false |
||
| ) |
Add or update a message in filename.
If the message already exists, then the count and timestamp are both updated. If unique is set to true, then the count is set to 1 even if the message already existed.
References clean(), load(), and save().
Referenced by unique().

| SMK & SMK::clean | ( | void | ) |
| SMK & SMK::del | ( | const std::string & | parm | ) |
|
protected |
Format the given message or messages as a tab-delimited block of text.
Referenced by get(), get_all(), and get_recent().

| SMK & SMK::format | ( | void | ) |
Format all the message to an easy-to-read block of text. This can be used as a login message.
References load().
|
protected |
Format the given timestamp as an easy-to-read text string, such as "35 seconds ago" or "2 days ago".
|
protected |
Format the numeric priority index to a text string, such as high or low.
| SMK & SMK::get | ( | const std::string & | parm | ) |
Get a specific message from filename. The parm must be a valid numerical index, starting at 1.
References display_msg(), and load().
| SMK & SMK::get_all | ( | void | ) |
Get a tab-delimited set of all messages.
References display_msg(), and load().
| SMK & SMK::get_recent | ( | void | ) |
Get a tab-delimited set of recent messages.
References display_msg(), and load().
|
protected |
| json SMK::load | ( | void | ) |
| SMK & SMK::reset | ( | void | ) |
Erase the json in filename and start with a brand new json structure.
References initialize_json(), and save().
| SMK & SMK::save | ( | json & | j | ) |
Save the json to filename.
References clean(), filename, initialize_json(), and sort_messages_by_timestamp().
Referenced by add(), clean(), del(), and reset().

| SMK & SMK::show_usage | ( | const std::string & | arg0 | ) |
Show a block of text that describes how to use SMK.
|
protected |
| SMK & SMK::unique | ( | const std::string & | priority, |
| const std::string & | msg | ||
| ) |
|
protected |