1 #ifndef CoCoA_ModuleOrdering_H 2 #define CoCoA_ModuleOrdering_H 3 4 // Copyright (c) 2005-2007,2011,2013 John Abbott, Anna Bigatti e Massimo Caboara 5 6 // This file is part of the source of CoCoALib, the CoCoA Library. 7 8 // CoCoALib is free software: you can redistribute it and/or modify 9 // it under the terms of the GNU General Public License as published by 10 // the Free Software Foundation, either version 3 of the License, or 11 // (at your option) any later version. 12 13 // CoCoALib is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU General Public License for more details. 17 18 // You should have received a copy of the GNU General Public License 19 // along with CoCoALib. If not, see <http://www.gnu.org/licenses/>. 20 21 22 #include "CoCoA/PPOrdering.H" 23 #include "CoCoA/SmartPtrIRC.H" 24 #include "CoCoA/SparsePolyRing.H" 25 #include "CoCoA/degree.H" 26 #include "CoCoA/ring.H" 27 28 #include <iosfwd> 29 //using std::ostream; 30 #include <vector> 31 //using std::vector; 32 33 34 namespace CoCoA 35 { 36 37 class OpenMathOutput; // fwd decl -- defined in OpenMath.H 38 39 class ModuleOrderingBase; // fwd decl -- defined later in this file 40 41 class ModuleOrdering 42 { 43 public: ModuleOrdering(const ModuleOrderingBase * ptr)44 explicit ModuleOrdering(const ModuleOrderingBase* ptr): mySmartPtr(ptr) {} 45 // assignment disabled because SmartPtrIRC has no assignment 46 const ModuleOrderingBase* operator->() const { return mySmartPtr.operator->(); } ///< Allow const member fns to be called. myRawPtr()47 const ModuleOrderingBase* myRawPtr() const { return mySmartPtr.myRawPtr(); } ///< Used by "downcasting" functions Is(..), As(...) etc. 48 bool operator==(const ModuleOrdering& MOrd) const { return mySmartPtr==MOrd.mySmartPtr; } 49 private: // data members 50 SmartPtrIRC<const ModuleOrderingBase> mySmartPtr; 51 }; 52 53 54 std::ostream& operator<<(std::ostream& out, const ModuleOrdering& MOrd); 55 OpenMathOutput& operator<<(OpenMathOutput& OMOut, const ModuleOrdering& MOrd); 56 57 //--------------------------------------------------------------------------- 58 class ModuleOrderingBase: private IntrusiveReferenceCount 59 { 60 friend class SmartPtrIRC<const ModuleOrderingBase>; // morally "friend ModuleOrdering", so it can alter ref count. 61 62 protected: 63 ModuleOrderingBase(const PPOrdering& PPO, const std::vector<degree>& shifts); 64 ModuleOrderingBase(const PPOrdering& PPO, const std::vector<degree>& shifts, const std::vector<long>& perm); 65 virtual ~ModuleOrderingBase(); 66 private: 67 ModuleOrderingBase(const ModuleOrderingBase& copy); ///< NEVER DEFINED -- copy ctor disabled 68 ModuleOrderingBase& operator=(const ModuleOrderingBase&); ///< NEVER DEFINED -- assignment disabled 69 public: 70 virtual void myOutputSelf(std::ostream& out) const; 71 virtual void myOutputSelf(OpenMathOutput& OMOut) const; 72 virtual void myOutputName(std::ostream& out) const = 0; 73 virtual void myOutputName(OpenMathOutput& OMOut) const = 0; 74 // virtual void myOrdMat(matrix& M) const = 0; 75 const std::vector<degree>& myShifts() const; 76 const std::vector<long>& myPerm() const; 77 const PPOrdering& myPPOrdering() const; 78 79 protected: 80 PPOrdering myPPO; ///< the PPOrdering (on the base ring) 81 std::vector<degree> myShiftsValue; ///< the components shifts (degrees) 82 std::vector<long> myPermutationValue; ///< the components priorities 83 }; 84 85 const std::vector<degree>& shifts(const ModuleOrdering& O); 86 long NumComponents(const ModuleOrdering& MOrd); 87 long GradingDim(const ModuleOrdering& MOrd); 88 const PPOrdering& ModPPOrdering(const ModuleOrdering& MOrd); 89 90 //--------------------------------------------------------------------------- 91 // Pseudo-constructors for ModuleOrderings 92 ModuleOrdering NewOrdPosn(const PPOrdering& PPO, long NumComponents); 93 ModuleOrdering NewPosnOrd(const PPOrdering& PPO, long NumComponents); 94 ModuleOrdering NewWDegPosnOrd(const PPOrdering& PPO, long NumComponents); 95 96 ModuleOrdering NewOrdPosn(const PPOrdering& PPO, const std::vector<degree>& shifts); 97 ModuleOrdering NewWDegPosnOrd(const PPOrdering& PPO, const std::vector<degree>& shifts); 98 ModuleOrdering NewPosnOrd(const PPOrdering& PPO, const std::vector<degree>& shifts); 99 100 ModuleOrdering NewOrdPosn(const PPOrdering& PPO, const std::vector<long>& perm); 101 ModuleOrdering NewWDegPosnOrd(const PPOrdering& PPO, const std::vector<long>& perm); 102 ModuleOrdering NewOrdPosn(const PPOrdering& PPO, const std::vector<degree>& shifts, const std::vector<long>& perm); 103 104 ModuleOrdering NewWDegPosnOrd(const PPOrdering& PPO, const std::vector<degree>& shifts, const std::vector<long>& perm); 105 106 // ModuleOrdering NewMatrixOrdering(ConstMatrix OrderMatrix, ??); 107 108 // ??? Compiler bug: the friend declarations below need explicit namespace 109 // scoping with g++ 3.2.2, otherwise g++ thinks New... etc are 110 // in the CoCoA::MOrd namespace. Very odd! 111 112 // ANNA: philosophical problem: WDeg must include shifts; what about Ord? 113 bool IsOrdPosn(const ModuleOrdering& MOrd); 114 bool IsPosnOrd(const ModuleOrdering& MOrd); 115 bool IsWDegPosnOrd(const ModuleOrdering& MOrd); 116 117 //---------------------------------------------------------------------- 118 class ModuleOrderingCtor 119 { 120 public: ~ModuleOrderingCtor()121 virtual ~ModuleOrderingCtor() {} 122 virtual ModuleOrdering operator()(const PPOrdering& PPO, long NumCompts) const = 0; 123 virtual ModuleOrdering operator()(const PPOrdering& PPO, const std::vector<degree>& shifts) const = 0; 124 }; 125 126 struct PosnOrdCtor: public ModuleOrderingCtor 127 { operatorPosnOrdCtor128 ModuleOrdering operator()(const PPOrdering& PPO, long NumCompts) const 129 { return NewPosnOrd(PPO, NumCompts); } 130 ModuleOrdering operator()(const PPOrdering& PPO, const std::vector<degree>& shifts) const; // NYI!!! 131 }; 132 133 struct OrdPosnCtor: public ModuleOrderingCtor 134 { operatorOrdPosnCtor135 ModuleOrdering operator()(const PPOrdering& PPO, long NumCompts) const 136 { return NewOrdPosn(PPO, NumCompts); } operatorOrdPosnCtor137 ModuleOrdering operator()(const PPOrdering& PPO, const std::vector<degree>& shifts) const 138 { return NewOrdPosn(PPO, shifts); } 139 }; 140 141 struct WDegPosnOrdCtor: public ModuleOrderingCtor 142 { operatorWDegPosnOrdCtor143 ModuleOrdering operator()(const PPOrdering& PPO, long NumCompts) const 144 { return NewWDegPosnOrd(PPO, NumCompts); } operatorWDegPosnOrdCtor145 ModuleOrdering operator()(const PPOrdering& PPO, const std::vector<degree>& shifts) const 146 { return NewWDegPosnOrd(PPO, shifts); } 147 }; 148 149 extern OrdPosnCtor OrdPosn; 150 extern PosnOrdCtor PosnOrd; 151 extern WDegPosnOrdCtor WDegPosnOrd; 152 153 //--------------------------------------------------------------------- 154 155 } // end of namespace CoCoA 156 157 158 159 // RCS header/log in the next few lines 160 // $Header: /Volumes/Home_1/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/ModuleOrdering.H,v 1.3 2015/12/01 13:11:00 abbott Exp $ 161 // $Log: ModuleOrdering.H,v $ 162 // Revision 1.3 2015/12/01 13:11:00 abbott 163 // Summary: Changed mem fn PPOrderingCtor::myCtor into operator(); also for ModuleOrderingCtor; see issue 829 164 // 165 // Revision 1.2 2014/07/31 13:10:46 bigatti 166 // -- GetMatrix(PPO) --> OrdMat(PPO) 167 // -- added OrdMat and GradingMat to PPOrdering, PPMonoid, SparsePolyRing 168 // 169 // Revision 1.1 2013/06/03 08:51:58 bigatti 170 // -- was ModuleTermOrdering 171 // 172 // Revision 1.5 2013/05/31 10:31:09 abbott 173 // Moved NYI impl body of PosnOrdCtor::myCtor to *.C file to avoid multiple compiler 174 // warnings about unused parameter. 175 // 176 // Revision 1.4 2013/05/27 16:35:05 bigatti 177 // -- major reorganisation of the implementation, changed names 178 // ---- WDegPosTO --> WDegPosnOrd, WDegTOPos --> OrdPosn, PosWDegTO --> PosnOrd 179 // 180 // Revision 1.3 2011/03/10 16:39:35 abbott 181 // Replaced (very many) size_t by long in function interfaces (for rings, 182 // PPMonoids and modules). Also replaced most size_t inside fn defns. 183 // 184 // Revision 1.2 2007/10/30 17:14:12 abbott 185 // Changed licence from GPL-2 only to GPL-3 or later. 186 // New version for such an important change. 187 // 188 // Revision 1.1.1.1 2007/03/09 15:16:11 abbott 189 // Imported files 190 // 191 // Revision 1.7 2006/12/06 17:14:12 cocoa 192 // -- removed #include "config.H" 193 // 194 // Revision 1.6 2006/11/24 17:14:10 cocoa 195 // -- reorganized includes of header files 196 // -- SmartPtrIRC for reference counting 197 // 198 // Revision 1.5 2006/11/10 13:30:57 cocoa 199 // -- fixed: "const &" to PPOrdering arguments 200 // -- some more documentation 201 // 202 // Revision 1.4 2006/11/10 13:06:03 cocoa 203 // -- cleaned code 204 // 205 // Revision 1.3 2006/11/02 13:25:44 cocoa 206 // Simplification of header files: the OpenMath classes have been renamed. 207 // Many minor consequential changes. 208 // 209 // Revision 1.2 2006/10/06 14:04:15 cocoa 210 // Corrected position of #ifndef in header files. 211 // Separated CoCoA_ASSERT into assert.H from config.H; 212 // many minor consequential changes (have to #include assert.H). 213 // A little tidying of #include directives (esp. in Max's code). 214 // 215 // Revision 1.1.1.1 2006/05/30 11:39:37 cocoa 216 // Imported files 217 // 218 // Revision 1.7 2006/05/12 16:10:58 cocoa 219 // Added OpenMathFwd.H, and tidied OpenMath.H. 220 // Many consequential but trivial changes. 221 // 222 // Revision 1.6 2006/05/11 15:59:23 cocoa 223 // -- changed reference count is done using SmartPtrIRC 224 // 225 // Revision 1.5 2006/05/04 14:19:02 cocoa 226 // -- moved some code from .H to .C 227 // 228 // Revision 1.4 2006/04/28 11:32:17 cocoa 229 // -- moved concrete class definition from .H to .C 230 // 231 // Revision 1.3 2006/03/15 18:09:31 cocoa 232 // Changed names of member functions which print out their object 233 // into myOutputSelf -- hope this will appease the Intel C++ compiler. 234 // 235 // Revision 1.2 2006/03/12 21:28:34 cocoa 236 // Major check in after many changes 237 // 238 // Revision 1.1.1.1 2005/10/17 10:46:54 cocoa 239 // Imported files 240 // 241 // Revision 1.1 2005/09/28 11:50:35 cocoa 242 // -- new code for graded modules 243 // 244 245 #endif 246