diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 1fa2ed47..04921418 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -198,16 +198,18 @@ namespace netgen constexpr Index (t_invalid inv) : i(long(BASE)-1) { ; } // TIndex & operator= (const TIndex &ai) { i = ai.i; return *this; } // private: - constexpr operator const int& () const { return i; } - explicit constexpr operator int& () { return i; } + constexpr operator T () const { return i; } + explicit constexpr operator T& () { return i; } public: constexpr operator TIndex() const { return TIndex(i); } constexpr operator TIndex&() { return static_cast(*this); } + TIndex operator++ (int) { TIndex hi(*this); i++; return hi; } TIndex operator-- (int) { TIndex hi(*this); i--; return hi; } TIndex & operator++ () { i++; return *this; } TIndex operator-- () { i--; return *this; } - TIndex operator+= (int add) { i += add; return *this; } + constexpr TIndex & operator+= (T add) & { i += add; return *this; } + constexpr TIndex operator+= (T add) && { i += add; return *this; } void Invalidate() { i = long(TIndex::BASE)-1; } bool IsValid() const { return i+1 != TIndex::BASE; } // operator bool() const { return IsValid(); } @@ -216,19 +218,17 @@ namespace netgen }; - /* template - auto operator+ (Index pi, int i) -> TIndex { return TIndex(pi.i+i); } + // constexpr auto operator+ (Index ind, int i) { return TIndex(T(ind)+i); } + constexpr auto operator+ (Index ind, int i) { return TIndex(ind)+=i; } template - inline TIndex operator+ (Index pi, size_t i) { return TIndex(pi.i+i); } + constexpr TIndex operator+ (Index pi, size_t i) { return TIndex(pi.i+i); } template - inline TIndex operator+ (int i, Index pi) { return TIndex(pi.i+i); } + constexpr TIndex operator+ (int i, Index pi) { return TIndex(pi.i+i); } template inline TIndex operator+ (size_t i, Index pi) { return TIndex(pi.i+i); } - template constexpr inline auto operator- (Index pi, int i) -> TIndex { return TIndex(pi.i-i); } - template inline int operator- (Index pa, Index pb) { return pa.i-pb.i; } template @@ -243,143 +243,15 @@ namespace netgen inline bool operator== (Index a, Index b) { return a.i == b.i; } template inline bool operator!= (Index a, Index b) { return a.i != b.i; } - */ - - - - /* - class PointIndex - { - int i; - public: - class t_invalid { public: constexpr t_invalid() = default; }; - static constexpr t_invalid INVALID{}; - - PointIndex () = default; - PointIndex (const PointIndex&) = default; - PointIndex (PointIndex &&) = default; - PointIndex & operator= (const PointIndex&) = default; - PointIndex & operator= (PointIndex&&) = default; - - constexpr PointIndex (int ai) : i(ai) - { -#ifdef DEBUG - if (ai < PointIndex::BASE) - cout << "illegal PointIndex, use PointIndex::INVALID instead" << endl; - // throw Exception("illegal PointIndex, use PointIndex::INVALID instead"); -#endif - } - constexpr PointIndex (t_invalid inv) : i(PointIndex::BASE-1) { ; } - // PointIndex & operator= (const PointIndex &ai) { i = ai.i; return *this; } - constexpr operator const int& () const { return i; } - explicit constexpr operator int& () { return i; } - PointIndex operator++ (int) { PointIndex hi(*this); i++; return hi; } - PointIndex operator-- (int) { PointIndex hi(*this); i--; return hi; } - PointIndex & operator++ () { i++; return *this; } - PointIndex operator-- () { i--; return *this; } - PointIndex operator+= (int add) { i += add; return *this; } - void Invalidate() { i = PointIndex::BASE-1; } - bool IsValid() const { return i != PointIndex::BASE-1; } -#ifdef BASE0 - static constexpr size_t BASE = 0; -#else - static constexpr size_t BASE = 1; -#endif - - void DoArchive (Archive & ar) { ar & i; } - } - */ - - - // #define BASE0 - - - /* - class PointIndex - { - int i; - public: - class t_invalid { public: constexpr t_invalid() = default; }; - static constexpr t_invalid INVALID{}; - - PointIndex () = default; - PointIndex (const PointIndex&) = default; - PointIndex (PointIndex &&) = default; - PointIndex & operator= (const PointIndex&) = default; - PointIndex & operator= (PointIndex&&) = default; - - // private: - constexpr PointIndex (int ai) : i(ai) - { -#ifdef DEBUG - if (ai < PointIndex::BASE) - cout << "illegal PointIndex, use PointIndex::INVALID instead" << endl; - // throw Exception("illegal PointIndex, use PointIndex::INVALID instead"); -#endif - } - - friend constexpr netgen::PointIndex ngcore::IndexBASE (); - template friend class PointIndices; - - friend constexpr PointIndex operator+ (PointIndex, int); - friend constexpr PointIndex operator+ (PointIndex, size_t); - friend constexpr PointIndex operator+ (int, PointIndex); - friend constexpr PointIndex operator+ (size_t, PointIndex); - friend constexpr PointIndex operator- (PointIndex, int); - friend constexpr int operator- (PointIndex, PointIndex); - friend bool operator< (PointIndex a, PointIndex b); - friend bool operator> (PointIndex a, PointIndex b); - friend bool operator>= (PointIndex a, PointIndex b); - friend bool operator<= (PointIndex a, PointIndex b); - friend constexpr bool operator== (PointIndex a, PointIndex b); - friend constexpr bool operator!= (PointIndex a, PointIndex b); - - public: - constexpr PointIndex (t_invalid inv) : i(long(PointIndex::BASE)-1) { ; } - // PointIndex & operator= (const PointIndex &ai) { i = ai.i; return *this; } - // private: - constexpr operator const int& () const { return i; } - explicit constexpr operator int& () { return i; } - public: - PointIndex operator++ (int) { PointIndex hi(*this); i++; return hi; } - PointIndex operator-- (int) { PointIndex hi(*this); i--; return hi; } - PointIndex & operator++ () { i++; return *this; } - PointIndex operator-- () { i--; return *this; } - PointIndex operator+= (int add) { i += add; return *this; } - void Invalidate() { i = long(PointIndex::BASE)-1; } - bool IsValid() const { return i+1 != PointIndex::BASE; } - // operator bool() const { return IsValid(); } -#ifdef BASE0 - static constexpr size_t BASE = 0; -#else - static constexpr size_t BASE = 1; -#endif - - void DoArchive (Archive & ar) { ar & i; } - }; - - */ class PointIndex : public Index { public: using Index::Index; }; - - constexpr inline PointIndex operator+ (PointIndex pi, int i) { return PointIndex(pi.i+i); } - constexpr inline PointIndex operator+ (PointIndex pi, size_t i) { return PointIndex(pi.i+i); } - constexpr inline PointIndex operator+ (int i, PointIndex pi) { return PointIndex(pi.i+i); } - constexpr inline PointIndex operator+ (size_t i, PointIndex pi) { return PointIndex(pi.i+i); } - constexpr inline PointIndex operator- (PointIndex pi, int i) { return PointIndex(pi.i-i); } - constexpr inline int operator- (PointIndex pa, PointIndex pb) { return pa.i-pb.i; } - inline bool operator< (PointIndex a, PointIndex b) { return a.i-b.i < 0; } - inline bool operator> (PointIndex a, PointIndex b) { return a.i-b.i > 0; } - inline bool operator>= (PointIndex a, PointIndex b) { return a.i-b.i >= 0; } - inline bool operator<= (PointIndex a, PointIndex b) { return a.i-b.i <= 0; } - inline constexpr bool operator== (PointIndex a, PointIndex b) { return a.i == b.i; } - inline constexpr bool operator!= (PointIndex a, PointIndex b) { return a.i != b.i; } + } namespace ngcore @@ -396,16 +268,15 @@ namespace netgen { // int i; ist >> i; pi = PointIndex(i); return ist; int i; ist >> i; - // pi = PointIndex(i); pi = IndexBASE()+i-1; return ist; } inline ostream & operator<< (ostream & ost, const PointIndex & pi) { + // return (ost << int(pi)); int intpi = pi - IndexBASE() + 1; return (ost << intpi); - // return (ost << int(pi)); } template class PointIndices; @@ -571,25 +442,12 @@ namespace std namespace netgen { - class ElementIndex + class ElementIndex : public Index { - int i; public: - ElementIndex () = default; - constexpr /* explicit */ ElementIndex (int ai) : i(ai) { ; } - ElementIndex & operator= (const ElementIndex & ai) { i = ai.i; return *this; } - ElementIndex & operator= (int ai) { i = ai; return *this; } - - constexpr /* explicit */ operator int () const { return i; } - ElementIndex operator++ (int) { return ElementIndex(i++); } - ElementIndex operator-- (int) { return ElementIndex(i--); } - ElementIndex & operator++ () { ++i; return *this; } - ElementIndex & operator-- () { --i; return *this; } - - int operator- (ElementIndex ei2) const { return i-ei2.i; } - friend constexpr ElementIndex ngcore::IndexBASE(); + using Index::Index; }; - + inline istream & operator>> (istream & ist, ElementIndex & pi) { int i; ist >> i; pi = i; return ist; @@ -600,64 +458,31 @@ namespace netgen return (ost << ei-IndexBASE()); } - inline ElementIndex operator+ (ElementIndex ei, int i) { return ElementIndex { int(ei) + i }; } - inline ElementIndex operator+ (size_t s, ElementIndex ei) { return ElementIndex(int(ei) + s); } - inline ElementIndex operator+ (ElementIndex ei, size_t s) { return ElementIndex(int(ei) + s); } - inline bool operator== (ElementIndex ei1, ElementIndex ei2) { return int(ei1) == int(ei2); }; - inline bool operator!= (ElementIndex ei1, ElementIndex ei2) { return int(ei1) != int(ei2); }; - inline bool operator< (ElementIndex ei1, ElementIndex ei2) { return int(ei1) < int(ei2); }; - inline bool operator> (ElementIndex ei1, ElementIndex ei2) { return int(ei1) > int(ei2); }; - inline bool operator>= (ElementIndex ei1, ElementIndex ei2) { return int(ei1) >= int(ei2); }; - inline bool operator<= (ElementIndex ei1, ElementIndex ei2) { return int(ei1) <= int(ei2); }; - - // these should not be needed: - inline bool operator== (ElementIndex ei1, int ei2) { return int(ei1) == int(ei2); }; - inline bool operator< (size_t s, ElementIndex ei2) { return int(s) < int(ei2); }; - inline bool operator< (ElementIndex ei1, size_t s) { return int(ei1) < int(s); }; // should not need - inline bool operator< (ElementIndex ei1, int s) { return int(ei1) < int(s); }; // should not need - inline bool operator>= (size_t s, ElementIndex ei2) { return int(s) >= int(ei2); }; - - class SurfaceElementIndex + // these should not be needed soon + inline bool operator== (Index ei1, int ei2) { return int(ei1) == int(ei2); }; + inline bool operator< (size_t s, Index ei2) { return int(s) < int(ei2); }; + inline bool operator< ( Index ei1, size_t s) { return int(ei1) < int(s); }; // should not need + inline bool operator< ( Index ei1, int s) { return int(ei1) < int(s); }; // should not need + inline bool operator>= (size_t s, Index ei2) { return int(s) >= int(ei2); }; + + + class SurfaceElementIndex : public Index { - int i; public: - SurfaceElementIndex () = default; - constexpr SurfaceElementIndex (int ai) : i(ai) { ; } - /* - SurfaceElementIndex & operator= (const SurfaceElementIndex & ai) - { i = ai.i; return *this; } - */ - SurfaceElementIndex & operator= (const SurfaceElementIndex & ai) = default; - SurfaceElementIndex & operator= (int ai) { i = ai; return *this; } - constexpr operator int () const { return i; } - SurfaceElementIndex operator++ (int) { SurfaceElementIndex hi(*this); i++; return hi; } - SurfaceElementIndex operator-- (int) { SurfaceElementIndex hi(*this); i--; return hi; } - SurfaceElementIndex & operator++ () { ++i; return *this; } - SurfaceElementIndex & operator-- () { --i; return *this; } - SurfaceElementIndex & operator+= (int inc) { i+=inc; return *this; } - void DoArchive (Archive & ar) { ar & i; } + using Index::Index; }; - inline SurfaceElementIndex operator+ (SurfaceElementIndex ei, int i) { return SurfaceElementIndex { int(ei) + i }; } - inline SurfaceElementIndex operator+ (size_t s, SurfaceElementIndex ei) { return SurfaceElementIndex(int(ei) + s); } - inline SurfaceElementIndex operator+ (SurfaceElementIndex ei, size_t s) { return SurfaceElementIndex(int(ei) + s); } - inline bool operator== (SurfaceElementIndex ei1, SurfaceElementIndex ei2) { return int(ei1) == int(ei2); }; - inline bool operator!= (SurfaceElementIndex ei1, SurfaceElementIndex ei2) { return int(ei1) != int(ei2); }; - inline bool operator< (SurfaceElementIndex ei1, SurfaceElementIndex ei2) { return int(ei1) < int(ei2); }; - inline bool operator> (SurfaceElementIndex ei1, SurfaceElementIndex ei2) { return int(ei1) > int(ei2); }; - inline bool operator>= (SurfaceElementIndex ei1, SurfaceElementIndex ei2) { return int(ei1) >= int(ei2); }; - inline bool operator<= (SurfaceElementIndex ei1, SurfaceElementIndex ei2) { return int(ei1) <= int(ei2); }; - - // these should not be needed: - inline bool operator== (SurfaceElementIndex ei1, int ei2) { return int(ei1) == int(ei2); }; - inline bool operator== (int ei2, SurfaceElementIndex ei1) { return int(ei1) == int(ei2); }; - inline bool operator!= (SurfaceElementIndex ei1, int ei2) { return int(ei1) != int(ei2); }; - inline bool operator< (size_t s, SurfaceElementIndex ei2) { return int(s) < int(ei2); }; - inline bool operator< (SurfaceElementIndex ei1, size_t s) { return int(ei1) < int(s); }; // should not need - inline bool operator< (SurfaceElementIndex ei1, int s) { return int(ei1) < int(s); }; // should not need - inline bool operator>= (size_t s, SurfaceElementIndex ei2) { return int(s) >= int(ei2); }; - inline bool operator>= (SurfaceElementIndex ei1, int s) { return int(ei1) >= int(s); }; + + // these should not be needed soon + inline bool operator== (Index ei1, int ei2) { return int(ei1) == int(ei2); }; + inline bool operator== (int ei2, Index ei1) { return int(ei1) == int(ei2); }; + inline bool operator!= (Index ei1, int ei2) { return int(ei1) != int(ei2); }; + inline bool operator< (size_t s, Index ei2) { return int(s) < int(ei2); }; + inline bool operator< (Index ei1, size_t s) { return int(ei1) < int(s); }; // should not need + inline bool operator< (Index ei1, int s) { return int(ei1) < int(s); }; // should not need + inline bool operator>= (size_t s, Index ei2) { return int(s) >= int(ei2); }; + inline bool operator>= (Index ei1, int s) { return int(ei1) >= int(s); }; inline void SetInvalid (SurfaceElementIndex & id) { id = -1; } @@ -673,20 +498,11 @@ namespace netgen return (ost << int(pi)); } - class SegmentIndex + + class SegmentIndex : public Index { - int i; public: - SegmentIndex () = default; - constexpr SegmentIndex (int ai) : i(ai) { ; } - SegmentIndex & operator= (const SegmentIndex & ai) - { i = ai.i; return *this; } - SegmentIndex & operator= (int ai) { i = ai; return *this; } - constexpr operator int () const { return i; } - SegmentIndex& operator++ () { ++i; return *this; } - SegmentIndex& operator-- () { --i; return *this; } - SegmentIndex operator++ (int) { return i++; } - SegmentIndex operator-- (int) { return i--; } + using Index::Index; }; inline void SetInvalid (SegmentIndex & id) { id = -1; } diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 3faa7d51..1a133165 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -268,7 +268,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def(py::init()) .def("__repr__", &ToString) .def("__str__", &ToString) - .def_property_readonly("nr", &PointIndex::operator const int&) + .def_property_readonly("nr", &PointIndex::operator int) .def("__eq__" , FunctionPointer( [](PointIndex &self, PointIndex &other) { return static_cast(self)==static_cast(other); }) ) .def("__hash__" , FunctionPointer( [](PointIndex &self ) { return static_cast(self); }) )