123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- /*****************************************************************************
- * HVector.h
- *****************************************************************************
- *
- * Project: HALCON/C++
- * Description: Vector class for engine and HDevelop export
- *
- * (c) 2014-2020 by MVTec Software GmbH
- * www.mvtec.com
- *
- *****************************************************************************
- *
- *
- *****************************************************************************/
- #ifndef HCPP_VECTOR_H
- #define HCPP_VECTOR_H
- #include "halconcpp/HTuple.h"
- #include "halconcpp/HObjectBase.h"
- #include "halconcpp/HObject.h"
- namespace HalconCpp
- {
- class Hvector;
- class LIntExport HVector
- {
- protected:
- // No public constructors, create HTupleVector or HObjectVector instead
- // Create an empty vector
- HVector(Hlong dimension);
-
- // Copy constructor
- HVector(const HVector& vector);
- public:
- // Destroy vector
- virtual ~HVector();
- /* Operator overloads */
- // Assignment operator
- HVector& operator=(const HVector& vector);
- // Comparison operators
- bool operator==(const HVector& vector) const;
- bool operator!=(const HVector& vector) const;
- // Non-const indexing operator. If necessary, the vector
- // will be enlarged to accomodate the index
- HVector& operator[](Hlong index);
- // Const indexing operator. An exception will be raised if the
- // index is out of range.
- const HVector& operator[](Hlong index) const;
- /* Methods */
-
- // Dimension of vector;
- Hlong Dimension() const
- {
- return mDimension;
- }
- // Length of vector
- Hlong Length() const;
-
- // Clear contents of vector
- HVector& Clear();
- // Remove element from vector
- HVector& Remove(Hlong index);
- // Insert element into vector
- HVector& Insert(Hlong index, const HVector& vector);
- // Return a simple string representation of the vector contents,
- // mainly for logging and debugging purposes. The result should not
- // be parsed and text format may change in the future.
- virtual HString ToString() const;
- // Assistive functionality for engine and code export
-
- // Raise exception on dimension mismatch
- void AssertDimension(Hlong dimension) const;
- // Assistive functionality for internal vector use
- protected:
- // FOR INTERNAL IMPLEMENTATION ONLY. NOT INTENDED
- // TO BE USED IN USER-DERIVED CLASSES
- // Increase length of vector (with dimension > 0) to ensure index is valid
- void AssertSize(Hlong index);
- // Test for equality
- virtual bool EqualImpl(const HVector& vector) const;
- // Create empty element to initialize gaps in vector
- virtual void ClearImpl();
- // Create concatenation of two vectors on the heap.
- HVector* ConcatImpl(const HVector& vector) const;
- // Create deep copy of all subvectors and elements
- virtual HVector* CloneImpl() const = 0;
- // Create empty element to initialize gaps in vector
- virtual HVector* GetDefaultElement() const = 0;
- // Returns new copy of this instance on the heap
- HVector* Clone() const;
- // Member variables
- protected:
-
- Hlong mDimension;
- // Data container
- Hvector* mVector;
- };
- class LIntExport HTupleVector : public HVector
- {
- public:
- // Create empty vector of specified dimension. In case of dimension
- // 0 a leaf vector for an empty tuple is created
- explicit HTupleVector(Hlong dimension)
- : HVector(dimension)
- {
- }
- // Create leaf vector of dimension 0 for the specified tuple
- explicit HTupleVector(const HTuple& tuple)
- : HVector(0),
- mTuple(tuple)
- {
- }
- // Create 1-dimensional vector by splitting input tuple into
- // blocks of fixed size (except possibly for the last block)
- // This corresponds to convert_tuple_to_vector_1d in HDevelop.
- explicit HTupleVector(const HTuple& tuple, Hlong block_size);
- // Copy constructor
- HTupleVector(const HTupleVector& vector);
- /* Operator overloads */
- // Assignment operator
- HTupleVector& operator=(const HTupleVector& vector);
- // Comparison operator
- bool operator==(const HTupleVector& vector) const;
- bool operator!=(const HTupleVector& vector) const;
- // Non-const indexing operator. If necessary, the vector
- // will be enlarged to accomodate the index
- HTupleVector& operator[](Hlong index);
- // Const indexing operator. An exception will be raised if the
- // index is out of range.
- const HTupleVector& operator[](Hlong index) const;
- /* Methods */
- // Clear contents of vector
- HTupleVector& Clear();
- // Remove element from vector
- HTupleVector& Remove(Hlong index);
- // Insert element into vector
- HTupleVector& Insert(Hlong index, const HTupleVector& vector);
- // Concatenate two vectors (creating new vector)
- HTupleVector Concat(const HTupleVector& vector);
- /* Value access (for leaf vectors of dimension 0) */
- const HTuple& T() const;
- HTuple& T();
- // Concatenates all tuples stored in the vector
- HTuple ConvertVectorToTuple() const;
- // Return a simple string representation of the vector contents,
- // mainly for logging and debugging purposes. The result should not
- // be parsed and text format may change in the future.
- virtual HString ToString() const;
- // Assistive functionality for internal vector use
- protected:
- // Test for equality
- virtual bool EqualImpl(const HVector& vector) const;
- // Create deep copy of all subvectors and elements
- virtual HVector* CloneImpl() const;
- // Create empty element to initialize gaps in vector
- virtual HVector* GetDefaultElement() const;
- protected:
- HTuple mTuple;
- };
- class LIntExport HObjectVector : public HVector
- {
- public:
- // Create empty vector of specified dimension. In case of dimension
- // 0 a leaf vector for an empty object is created
- explicit HObjectVector(Hlong dimension);
- // Create leaf vector of dimension 0 for the specified object
- explicit HObjectVector(const HObject& obj)
- : HVector(0),
- mObject(obj)
- {
- }
- // Copy constructor
- HObjectVector(const HObjectVector& vector);
- /* Operator overloads */
- // Assignment operator
- HObjectVector& operator=(const HObjectVector& vector);
- // Comparison operator
- bool operator==(const HObjectVector& vector) const;
- bool operator!=(const HObjectVector& vector) const;
- // Non-const indexing operator. If necessary, the vector
- // will be enlarged to accomodate the index
- HObjectVector& operator[](Hlong index);
- // Const indexing operator. An exception will be raised if the
- // index is out of range.
- const HObjectVector& operator[](Hlong index) const;
- /* Methods */
- // Clear contents of vector
- HObjectVector& Clear();
- // Remove element from vector
- HObjectVector& Remove(Hlong index);
- // Insert element into vector
- HObjectVector& Insert(Hlong index, const HObjectVector& vector);
- // Concatenate two vectors (creating new vector)
- HObjectVector Concat(const HObjectVector& vector);
- /* Value access (for leaf vectors of dimension 0) */
- const HObject& O() const;
- HObject& O();
- // Return a simple string representation of the vector contents,
- // mainly for logging and debugging purposes. The result should not
- // be parsed and text format may change in the future.
- virtual HString ToString() const;
- // Assistive functionality for internal vector use
- protected:
- // Test for equality
- virtual bool EqualImpl(const HVector& vector) const;
- // Create deep copy of all subvectors and elements
- virtual HVector* CloneImpl() const;
- // Create empty element to initialize gaps in vector
- virtual HVector* GetDefaultElement() const;
- protected:
- HObject mObject;
- };
- }
- #endif
|