/** * This file is part of Gomu. * * Copyright 2016 by Jean Fromentin * * Gomu is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Gomu is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Gomu. If not, see . */ #include "../../module.hpp" #include "permutations.hpp" using namespace std; //***************** //* Global object * //***************** extern Gomu::Type* type_PermutationA; extern Gomu::Type* type_PermutationB; extern Gomu::Type* type_PermutationD; extern Gomu::Type* type_PermutationEnumeratorA; extern Gomu::Type* type_PermutationEnumeratorB; extern Gomu::Type* type_PermutationEnumeratorD; namespace Permutations{ template string dispPerm(void*); template void delPerm(void*); template void* copyPerm(void*); template int cmpPerm(void*,void*); template string dispPermE(void*); template void delPermE(void*); template void* copyPermE(void*); template int cmpPermE(void*,void*); //--- Constructors ---// template void* intToPerm(void*); template void* intToPermE(void*); //--- Permutation functions ---// //--- Permutation enumerator functions ---// template void* PE_get(void*); template void* PE_next(void*); template void* PE_reset(void*); template void* PE_size(void*); } namespace Permutations{ template inline string dispPerm(void* P){return ((Permutation*)P)->display();} template inline void delPerm(void* v){delete ((Permutation*)v);} template inline void* copyPerm(void* v){return new Permutation(*((Permutation*)v));} template inline int cmpPerm(void* v1,void* v2){return ((Permutation*)v1)->cmp(*(Permutation*)v2);} template inline string dispPermE(void* P){return ((PermutationEnumerator*)P)->display();} template inline void delPermE(void* v){delete ((PermutationEnumerator*)v);} template inline void* copyPermE(void* v){return new PermutationEnumerator(*((PermutationEnumerator*)v));} template inline int cmpPermE(void* v1,void* v2){return ((PermutationEnumerator*)v1)->cmp(*(PermutationEnumerator*)v2);} //--- Constructors ---// template inline void* intToPerm(void* z){ slong n=Gomu::get_slong(z); if(n<0 or n>15) RuntimeError("A postive integer < 16 is needed"); return new Permutation(n); } template inline void* intToPermE(void* z){ slong n=Gomu::get_slong(z); if(n<0 or n>15) RuntimeError("A postive integer < 16 is needed"); return new PermutationEnumerator(n); } //*********************************** //* PermutationEnumerator functions * //*********************************** template inline void* PE_get(void* PE){return new Permutation(((PermutationEnumerator*)PE)->get());} template inline void* PE_next(void* PE){return Gomu::to_boolean(((PermutationEnumerator*)PE)->next());} template inline void* PE_reset(void* PE){((PermutationEnumerator*)PE)->reset();return nullptr;} template inline void* PE_size(void* PE){return Gomu::to_integer(((PermutationEnumerator*)PE)->size());} }