Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// This file has been generated, if you wish to
- /// modify it in a permanent way, please refer
- /// to the script file : gen/generator_c.rb
- #include "interface.hh"
- #include <cstdlib>
- template<typename Lang, typename Cxx>
- Cxx lang2cxx(Lang in)
- {
- return in;
- }
- template<>
- std::string lang2cxx<char*, std::string>(char* in)
- {
- return in;
- }
- template<typename Lang, typename Lang_array, typename Cxx>
- std::vector<Cxx> lang2cxx_array(Lang_array in)
- {
- std::vector<Cxx> out(in.length);
- for (size_t i = 0; i < in.length; ++i)
- out[i] = lang2cxx<Lang, Cxx>(in.datas[i]);
- return out;
- }
- template<typename Lang, typename Cxx>
- Lang cxx2lang(Cxx in)
- {
- return in;
- }
- template<>
- char* cxx2lang<char*, std::string>(std::string in)
- {
- size_t l = in.length();
- char* out = (char *) malloc(l + 1);
- for (int i = 0; i < l; i++) out[i] = in[i];
- out[l] = 0;
- return out;
- }
- template<typename Lang, typename Lang_array, typename Cxx>
- Lang_array cxx2lang_array(const std::vector<Cxx>& in)
- {
- Lang_array out = { NULL, in.size() };
- out.datas = (Lang *)malloc((out.length) * sizeof(Lang));
- for (int i = 0; i < out.length; ++i)
- out.datas[i] = cxx2lang<Lang, Cxx>(in[i]);
- return out;
- }
- /// Position on the TicTacToe board
- template<>
- __internal__cxx__position lang2cxx<position, __internal__cxx__position>(position in)
- {
- __internal__cxx__position out;
- out.x = lang2cxx<int, int >(in.x);
- out.y = lang2cxx<int, int >(in.y);
- return out;
- }
- template<>
- position cxx2lang<position, __internal__cxx__position>(__internal__cxx__position in)
- {
- position out;
- out.x = cxx2lang<int, int >(in.x);
- out.y = cxx2lang<int, int >(in.y);
- return out;
- }
- extern "C" {
- /// Play at the given position
- error play(position pos)
- {
- return cxx2lang<error, error >(api_play(lang2cxx<position, __internal__cxx__position >(pos)));
- }
- /// Returns your team number
- int my_team(void)
- {
- return cxx2lang<int, int >(api_my_team());
- }
- /// Returns the TicTacToe board
- int_array board(void)
- {
- return cxx2lang_array<int, int_array, int >(api_board());
- }
- /// Cancels the last played action
- bool cancel(void)
- {
- return cxx2lang<bool, bool >(api_cancel());
- }
- /// Affiche le contenu d'une valeur de type error
- void afficher_error(error v)
- {
- api_afficher_error(lang2cxx<error, error >(v));
- }
- /// Affiche le contenu d'une valeur de type position
- void afficher_position(position v)
- {
- api_afficher_position(lang2cxx<position, __internal__cxx__position >(v));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement