Advertisement
Guest User

Untitled

a guest
Nov 10th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. /// This file has been generated, if you wish to
  2. /// modify it in a permanent way, please refer
  3. /// to the script file : gen/generator_c.rb
  4.  
  5. #include "interface.hh"
  6. #include <cstdlib>
  7.  
  8. template<typename Lang, typename Cxx>
  9. Cxx lang2cxx(Lang in)
  10. {
  11.   return in;
  12. }
  13.  
  14. template<>
  15. std::string lang2cxx<char*, std::string>(char* in)
  16. {
  17.   return in;
  18. }
  19.  
  20. template<typename Lang, typename Lang_array, typename Cxx>
  21. std::vector<Cxx> lang2cxx_array(Lang_array in)
  22. {
  23.   std::vector<Cxx> out(in.length);
  24.   for (size_t i = 0; i < in.length; ++i)
  25.     out[i] = lang2cxx<Lang, Cxx>(in.datas[i]);
  26.   return out;
  27. }
  28.  
  29. template<typename Lang, typename Cxx>
  30. Lang cxx2lang(Cxx in)
  31. {
  32.   return in;
  33. }
  34.  
  35. template<>
  36. char* cxx2lang<char*, std::string>(std::string in)
  37. {
  38.   size_t l = in.length();
  39.   char* out = (char *) malloc(l + 1);
  40.   for (int i = 0; i < l; i++) out[i] = in[i];
  41.   out[l] = 0;
  42.   return out;
  43. }
  44.  
  45. template<typename Lang, typename Lang_array, typename Cxx>
  46. Lang_array cxx2lang_array(const std::vector<Cxx>& in)
  47. {
  48.   Lang_array out = { NULL, in.size() };
  49.   out.datas = (Lang *)malloc((out.length) * sizeof(Lang));
  50.   for (int i = 0; i < out.length; ++i)
  51.     out.datas[i] = cxx2lang<Lang, Cxx>(in[i]);
  52.   return out;
  53. }
  54. /// Position on the TicTacToe board
  55. template<>
  56. __internal__cxx__position lang2cxx<position, __internal__cxx__position>(position in)
  57. {
  58.   __internal__cxx__position out;
  59.   out.x = lang2cxx<int, int >(in.x);
  60.   out.y = lang2cxx<int, int >(in.y);
  61.   return out;
  62. }
  63.  
  64. template<>
  65. position cxx2lang<position, __internal__cxx__position>(__internal__cxx__position in)
  66. {
  67.   position out;
  68.   out.x = cxx2lang<int, int >(in.x);
  69.   out.y = cxx2lang<int, int >(in.y);
  70.   return out;
  71. }
  72.  
  73.  
  74. extern "C" {
  75. /// Play at the given position
  76. error play(position pos)
  77. {
  78.   return cxx2lang<error, error >(api_play(lang2cxx<position, __internal__cxx__position >(pos)));
  79. }
  80.  
  81.  
  82. /// Returns your team number
  83. int my_team(void)
  84. {
  85.   return cxx2lang<int, int >(api_my_team());
  86. }
  87.  
  88.  
  89. /// Returns the TicTacToe board
  90. int_array board(void)
  91. {
  92.   return cxx2lang_array<int, int_array, int >(api_board());
  93. }
  94.  
  95.  
  96. /// Cancels the last played action
  97. bool cancel(void)
  98. {
  99.   return cxx2lang<bool, bool >(api_cancel());
  100. }
  101.  
  102.  
  103. /// Affiche le contenu d'une valeur de type error
  104. void afficher_error(error v)
  105. {
  106.   api_afficher_error(lang2cxx<error, error >(v));
  107. }
  108.  
  109.  
  110. /// Affiche le contenu d'une valeur de type position
  111. void afficher_position(position v)
  112. {
  113.   api_afficher_position(lang2cxx<position, __internal__cxx__position >(v));
  114. }
  115.  
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement