Browse Source

express: add PointerToArray.count()

rdb 8 years ago
parent
commit
0281f306e1

+ 26 - 0
panda/src/express/pointerToArray.I

@@ -581,6 +581,19 @@ node_unref() const {
   return ((To *)(this->_void_ptr))->node_unref();
   return ((To *)(this->_void_ptr))->node_unref();
 }
 }
 
 
+/**
+ * Counts the frequency at which the given element occurs in the vector.
+ */
+template<class Element>
+INLINE size_t PointerToArray<Element>::
+count(const Element &value) const {
+  if ((this->_void_ptr) != nullptr) {
+    return std::count(begin(), end(), value);
+  } else {
+    return 0;
+  }
+}
+
 /**
 /**
  *
  *
  */
  */
@@ -1006,6 +1019,19 @@ node_unref() const {
   return ((To *)(this->_void_ptr))->node_unref();
   return ((To *)(this->_void_ptr))->node_unref();
 }
 }
 
 
+/**
+ * Counts the frequency at which the given element occurs in the vector.
+ */
+template<class Element>
+INLINE size_t ConstPointerToArray<Element>::
+count(const Element &value) const {
+  if ((this->_void_ptr) != nullptr) {
+    return std::count(begin(), end(), value);
+  } else {
+    return 0;
+  }
+}
+
 /**
 /**
  *
  *
  */
  */

+ 8 - 0
panda/src/express/pointerToArray.h

@@ -112,6 +112,8 @@ PUBLISHED:
   INLINE int get_ref_count() const;
   INLINE int get_ref_count() const;
   INLINE int get_node_ref_count() const;
   INLINE int get_node_ref_count() const;
 
 
+  INLINE size_t count(const Element &) const;
+
 #ifdef HAVE_PYTHON
 #ifdef HAVE_PYTHON
   EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags));
   EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags));
   EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const);
   EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const);
@@ -214,6 +216,8 @@ public:
   INLINE void node_ref() const;
   INLINE void node_ref() const;
   INLINE bool node_unref() const;
   INLINE bool node_unref() const;
 
 
+  INLINE size_t count(const Element &) const;
+
   // Reassignment is by pointer, not memberwise as with a vector.
   // Reassignment is by pointer, not memberwise as with a vector.
   INLINE PointerToArray<Element> &
   INLINE PointerToArray<Element> &
   operator = (ReferenceCountedVector<Element> *ptr);
   operator = (ReferenceCountedVector<Element> *ptr);
@@ -266,6 +270,8 @@ PUBLISHED:
   INLINE int get_ref_count() const;
   INLINE int get_ref_count() const;
   INLINE int get_node_ref_count() const;
   INLINE int get_node_ref_count() const;
 
 
+  INLINE size_t count(const Element &) const;
+
 #ifdef HAVE_PYTHON
 #ifdef HAVE_PYTHON
   EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const);
   EXTENSION(int __getbuffer__(PyObject *self, Py_buffer *view, int flags) const);
   EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const);
   EXTENSION(void __releasebuffer__(PyObject *self, Py_buffer *view) const);
@@ -341,6 +347,8 @@ PUBLISHED:
   INLINE void node_ref() const;
   INLINE void node_ref() const;
   INLINE bool node_unref() const;
   INLINE bool node_unref() const;
 
 
+  INLINE size_t count(const Element &) const;
+
   // Reassignment is by pointer, not memberwise as with a vector.
   // Reassignment is by pointer, not memberwise as with a vector.
   INLINE ConstPointerToArray<Element> &
   INLINE ConstPointerToArray<Element> &
   operator = (ReferenceCountedVector<Element> *ptr);
   operator = (ReferenceCountedVector<Element> *ptr);

+ 16 - 0
panda/src/linmath/lmatrix4_src.I

@@ -1706,3 +1706,19 @@ INLINE_LINMATH int FLOATNAME(UnalignedLMatrix4)::
 get_num_components() const {
 get_num_components() const {
   return 16;
   return 16;
 }
 }
+
+/**
+ *
+ */
+INLINE_LINMATH bool FLOATNAME(UnalignedLMatrix4)::
+operator == (const FLOATNAME(UnalignedLMatrix4) &other) const {
+  return memcmp(get_data(), other.get_data(), sizeof(FLOATTYPE) * 16) == 0;
+}
+
+/**
+ *
+ */
+INLINE_LINMATH bool FLOATNAME(UnalignedLMatrix4)::
+operator != (const FLOATNAME(UnalignedLMatrix4) &other) const {
+  return !operator == (other);
+}

+ 3 - 0
panda/src/linmath/lmatrix4_src.h

@@ -345,6 +345,9 @@ PUBLISHED:
   INLINE_LINMATH const FLOATTYPE *get_data() const;
   INLINE_LINMATH const FLOATTYPE *get_data() const;
   INLINE_LINMATH int get_num_components() const;
   INLINE_LINMATH int get_num_components() const;
 
 
+  INLINE_LINMATH bool operator == (const FLOATNAME(UnalignedLMatrix4) &other) const;
+  INLINE_LINMATH bool operator != (const FLOATNAME(UnalignedLMatrix4) &other) const;
+
 public:
 public:
   typedef UNALIGNED_LINMATH_MATRIX(FLOATTYPE, 4, 4) UMatrix4;
   typedef UNALIGNED_LINMATH_MATRIX(FLOATTYPE, 4, 4) UMatrix4;
   UMatrix4 _m;
   UMatrix4 _m;

+ 19 - 0
panda/src/linmath/lvecBase4_src.I

@@ -971,3 +971,22 @@ INLINE_LINMATH const FLOATTYPE *FLOATNAME(UnalignedLVecBase4)::
 get_data() const {
 get_data() const {
   return &_v(0);
   return &_v(0);
 }
 }
+
+/**
+ *
+ */
+INLINE_LINMATH bool FLOATNAME(UnalignedLVecBase4)::
+operator == (const FLOATNAME(UnalignedLVecBase4) &other) const {
+  return (_v(0) == other._v(0) &&
+          _v(1) == other._v(1) &&
+          _v(2) == other._v(2) &&
+          _v(3) == other._v(3));
+}
+
+/**
+ *
+ */
+INLINE_LINMATH bool FLOATNAME(UnalignedLVecBase4)::
+operator != (const FLOATNAME(UnalignedLVecBase4) &other) const {
+  return !operator == (other);
+}

+ 3 - 0
panda/src/linmath/lvecBase4_src.h

@@ -243,6 +243,9 @@ PUBLISHED:
   INLINE_LINMATH const FLOATTYPE *get_data() const;
   INLINE_LINMATH const FLOATTYPE *get_data() const;
   CONSTEXPR static int get_num_components() { return 4; }
   CONSTEXPR static int get_num_components() { return 4; }
 
 
+  INLINE_LINMATH bool operator == (const FLOATNAME(UnalignedLVecBase4) &other) const;
+  INLINE_LINMATH bool operator != (const FLOATNAME(UnalignedLVecBase4) &other) const;
+
 public:
 public:
   typedef FLOATTYPE numeric_type;
   typedef FLOATTYPE numeric_type;
   typedef UNALIGNED_LINMATH_MATRIX(FLOATTYPE, 1, 4) UVector4;
   typedef UNALIGNED_LINMATH_MATRIX(FLOATTYPE, 1, 4) UVector4;