-
Notifications
You must be signed in to change notification settings - Fork 0
Hello world
In a program execution, sometimes is necessary to save an information in oder read it later. Landb was made to turn that process easy by giving you a bunch of methods to manage your program data. Basically it's a library that helps you to write and read variable from files.
In landb, a variable is stored in a structure called db_bit
. A db_bit
stores data and some important information like the variable name and type. Various db_bits
can be connected creating a context.
•-•-•-•-•-• -> main context
|
•-•-• -> x context
|
•-•-•-•-• -> y context
A context is a space where variables can be stored together, presuming that they have any relationship. They are three types of context: the main context, arrays and containers.
The main context is the default context, where everything begins. When we declare a variable without specifying it's context, landb stores it in the main context, we will talk more about arrays and containers in another chapter.
Contexts are just like lists, where every element is a db_bit
. The way that landb works is by reading and writing that elements.
Including the libraries
#include <iostream>
#include "landb.hpp"
In the main()
function, we create a database
int main(int argc, const char * argv[]) {
// Database
lan::db database;
Then we create a landb variable by using the set()
method, that requires a data type (<std::string>
in this case) , the variable name ("message"
), the variable content ("Hello world"
) and the variable type (lan::String
)
// Creating a variable called message in the main context
database.set<std::string>("message", "Hello world", lan::String);
After creating a variable, it's time to get and print it in the screen, we can do this by using the get()
method, witch requires a data type (<std::string>
), the variable name ("message"
) and the variable type (lan::String
). Ater getting the value, we print it using std::cout
std::cout << database.get<std::string>("message", lan::String) << std::endl;
And
return 0;
}
#include <iostream>
#include "landb.hpp"
int main(int argc, const char * argv[]) {
// Database
lan::db database;
// Creating a variable called message in the main context
database.set<std::string>("message", "Hello world", lan::String);
std::cout << database.get<std::string>("message", lan::String) << std::endl;
return 0;
}
Don't forget to add landb.hpp
to your source's directory.
Compiler | Statically | Dynamically |
---|---|---|
g++ |
g++ main.cpp liblandb.a -std=c++17 or g++ main.cpp -L. -llandb -std=c++17
|
g++ main.cpp liblandbD.so -std=c++17 or g++ main.cpp -L. -llandbD -std=c++17 -rpath PATH_TO_liblandbD.so
|
Xcode | Add liblandb.a to Frameworks and Libraries |
Add liblandbD.dylib to Frameworks and Libraries |
The program should output Hello world
.
Go back to Home.