libcodemsg
is a library for organising CODE-MESSAGE style value paris.
Using C
style macro and string, it's simple and easy. No more hassle, no more mismatch.
Use macro DEF_MSG
to define a macro and message pair:
DEF_MSG(CODE_OK, "OK!")
DEF_MSG(CODE_FAIL, "Fail!")
CODE_OK
is the macro to use, and "OK!"
is the corresponding message.
Use get_message()
or just gm()
to get the message:
get_message(CODE_FAIL); // will return "Fail!"
gm(CODE_FAIL); // works exactly the same as above
Use MSG_NUM
to find out how many macros have been defined. This will automatically increse, you don't need to do anything.
Predefined messages:
MSG_OK: OK
MSG_BOTTOM: Message bottom
To make the lib fully functional, there are several steps, once done, you won't need to go through it any more.
- Create the message definition header files.
- Create the message entry header file.
- Tell libcodemsg where your message entry header file is.
You can refer to the example project for real world usage.
Every definition file should include message_inc.h
to use the DEF_MSG
macro.
#include <message_inc.h>
Then define some CODE-MESSAGEs:
DEF_MSG(JUST_SAY_HI, "Hi!")
Messages with a prefix:
#define MSG_HEAD_HELLO "Hello: "
DEF_MSG(HELLO_WORLD, MSG_HEAD_HELLO "world!")
DEF_MSG(HELLO_YOU, MSG_HEAD_HELLO "you!")
A sufix, or anything string you want.
Then name the file, for example message_hello.h
. You can create as many definition files as you like, but remember, the macros should be unique.
Create a header file with any name you like, e.g., message_hello.h
.
Include the definition header files in it:
#include "message_hello.h"
...
#include "message_anything.h"
CMake needs to know where your entry header file is, define variable CODE_MESSAGE_ENTRY
to do this.
For example:
set(CODE_MESSAGE_ENTRY "path/to/message_all.h")
Just include one header file:
#include <message_def.h>
Then you get access to all the macros and get_message()
function.
mkdir build
cd build
cmake -DBUILD_EXAMPLE=ON ..
make