init.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * This file is part of Gomu.
  3. *
  4. * Copyright 2016 by Jean Fromentin <jean.fromentin@math.cnrs.fr>
  5. *
  6. * Gomu is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Gomu is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Gomu. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "../../module.hpp"
  20. #include "permutations.hpp"
  21. using namespace std;
  22. //*****************
  23. //* Global object *
  24. //*****************
  25. extern Gomu::Type* type_PermutationA;
  26. extern Gomu::Type* type_PermutationB;
  27. extern Gomu::Type* type_PermutationD;
  28. extern Gomu::Type* type_PermutationEnumeratorA;
  29. extern Gomu::Type* type_PermutationEnumeratorB;
  30. extern Gomu::Type* type_PermutationEnumeratorD;
  31. namespace Permutations{
  32. template<CoxeterType T> string dispPerm(void*);
  33. template<CoxeterType T> void delPerm(void*);
  34. template<CoxeterType T> void* copyPerm(void*);
  35. template<CoxeterType T> int cmpPerm(void*,void*);
  36. template<CoxeterType T> string dispPermE(void*);
  37. template<CoxeterType T> void delPermE(void*);
  38. template<CoxeterType T> void* copyPermE(void*);
  39. template<CoxeterType T> int cmpPermE(void*,void*);
  40. //--- Constructors ---//
  41. template<CoxeterType T> void* intToPerm(void*);
  42. template<CoxeterType T> void* intToPermE(void*);
  43. //--- Permutation functions ---//
  44. //--- Permutation enumerator functions ---//
  45. template<CoxeterType T> void* PE_get(void*);
  46. template<CoxeterType T> void* PE_next(void*);
  47. template<CoxeterType T> void* PE_reset(void*);
  48. template<CoxeterType T> void* PE_size(void*);
  49. }
  50. namespace Permutations{
  51. template<CoxeterType T> inline string dispPerm(void* P){return ((Permutation<T>*)P)->display();}
  52. template<CoxeterType T> inline void delPerm(void* v){delete ((Permutation<T>*)v);}
  53. template<CoxeterType T> inline void* copyPerm(void* v){return new Permutation<T>(*((Permutation<T>*)v));}
  54. template<CoxeterType T> inline int cmpPerm(void* v1,void* v2){return ((Permutation<T>*)v1)->cmp(*(Permutation<T>*)v2);}
  55. template<CoxeterType T> inline string dispPermE(void* P){return ((PermutationEnumerator<T>*)P)->display();}
  56. template<CoxeterType T> inline void delPermE(void* v){delete ((PermutationEnumerator<T>*)v);}
  57. template<CoxeterType T> inline void* copyPermE(void* v){return new PermutationEnumerator<T>(*((PermutationEnumerator<T>*)v));}
  58. template<CoxeterType T> inline int cmpPermE(void* v1,void* v2){return ((PermutationEnumerator<T>*)v1)->cmp(*(PermutationEnumerator<T>*)v2);}
  59. //--- Constructors ---//
  60. template<CoxeterType T>
  61. inline void*
  62. intToPerm(void* z){
  63. slong n=Gomu::get_slong(z);
  64. if(n<0 or n>15) RuntimeError("A postive integer < 16 is needed");
  65. return new Permutation<T>(n);
  66. }
  67. template<CoxeterType T>
  68. inline void*
  69. intToPermE(void* z){
  70. slong n=Gomu::get_slong(z);
  71. if(n<0 or n>15) RuntimeError("A postive integer < 16 is needed");
  72. return new PermutationEnumerator<T>(n);
  73. }
  74. //***********************************
  75. //* PermutationEnumerator functions *
  76. //***********************************
  77. template<CoxeterType T> inline void* PE_get(void* PE){return new Permutation<T>(((PermutationEnumerator<T>*)PE)->get());}
  78. template<CoxeterType T> inline void* PE_next(void* PE){return Gomu::to_boolean(((PermutationEnumerator<T>*)PE)->next());}
  79. template<CoxeterType T> inline void* PE_reset(void* PE){((PermutationEnumerator<T>*)PE)->reset();return nullptr;}
  80. template<CoxeterType T> inline void* PE_size(void* PE){return Gomu::to_integer(((PermutationEnumerator<T>*)PE)->size());}
  81. }