Bobox
Example of Bobolang

This is a sample application (in the bobox/bofe/bobolang directory) which shows the power of Bobolang language. You can perform your own experiments in the model.bobolang file. After you run the application, the file dump.dot is created. To visualize this file, install dot and run this command:

dot -Tpng -O dump.dot

This will create dump.dot.png file. For example, this Bobolang code:

model main<()><()> {
        bobox::stateless_dummy<()><()> stateless;
        bobox::stateful_dummy<()><()> stateful;
        bobox::parallel_dummy<()><()> parallel;

        input -> stateless -> stateful -> parallel -> output;
}

produces this image:

bobolang.png
#include <fstream>

#include "bobox_manager.hpp"
#include "bobox_results.hpp"
#include "bobox_bobolang.hpp"
#include "bobox_basic_object_factory.hpp"

class runtime : public bobox::runtime, public bobox::basic_object_factory {
        virtual bobox::runtime *get_runtime() BOBOX_OVERRIDE { return this; }
};

int main(int argc, char *argv[])
{
        bobox::manager mng(bobox::SS_SMP, 0, bobox::plevel_type(4));

        runtime rt;
        rt.init();

        std::ifstream in("model.bobolang");
        if (!in) {
                std::cerr << "Failed to open file 'model.bobolang'" << std::endl;
                return 1;
        }

        bobox::request_id_type rqid = mng.create_request(bobox::bobolang::compile(in, &rt));

        mng.run_request(rqid);
        mng.wait_on_request(rqid);

        std::ofstream dot("dump.dot");
        mng.dump_request(rqid, dot, false, false);

        switch (mng.get_result(rqid)) {
                case bobox::RRT_ERROR: std::cout << "Error" << std::endl; break;
                case bobox::RRT_CANCELED: std::cout << "Canceled" << std::endl; break;
                case bobox::RRT_DEADLOCK: std::cout << "Deadlock" << std::endl; break;
                case bobox::RRT_MEMORY: std::cout << "Memory" << std::endl; break;
                case bobox::RRT_OK: std::cout << "OK" << std::endl; break;
                case bobox::RRT_TIMEOUT: std::cout << "Timeout" << std::endl; break;
                default: BOBOX_ASSERT(false); break;
        }

        mng.destroy_request(rqid);

        return 0;
}