Chemical Data Processing Library C++ API - Version 1.1.1
Array.hpp
Go to the documentation of this file.
1 /*
2  * Array.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library 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 GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_UTIL_ARRAY_HPP
30 #define CDPL_UTIL_ARRAY_HPP
31 
32 #include <vector>
33 #include <string>
34 #include <cstddef>
35 #include <utility>
36 #include <memory>
37 
38 #include "CDPL/Base/Exceptions.hpp"
39 #include "CDPL/Util/BitSet.hpp"
40 
41 #ifndef CDPL_UTIL_ARRAY_CHECK_INDEX
42 # ifdef CDPL_UTIL_ARRAY_CHECKS_DISABLE
43 # define CDPL_UTIL_ARRAY_CHECK_INDEX(idx, allow_end)
44 # else // !CDPL_UTIL_ARRAY_CHECKS_DISABLE
45 # define CDPL_UTIL_ARRAY_CHECK_INDEX(idx, allow_end) checkIndex(idx, allow_end)
46 # endif // CDPL_UTIL_ARRAY_CHECKS_DISABLE
47 #endif // !CDPL_UTIL_ARRAY_CHECK_INDEX
48 
49 #ifndef CDPL_UTIL_ARRAY_CHECK_ITER
50 # ifdef CDPL_UTIL_ARRAY_CHECKS_DISABLE
51 # define CDPL_UTIL_ARRAY_CHECK_ITER(it, allow_end)
52 # else // !CDPL_UTIL_ARRAY_CHECKS_DISABLE
53 # define CDPL_UTIL_ARRAY_CHECK_ITER(it, allow_end) checkIterator(it, allow_end)
54 # endif // CDPL_UTIL_ARRAY_CHECKS_DISABLE
55 #endif // !CDPL_UTIL_ARRAY_CHECK_INDEX
56 
57 
58 namespace CDPL
59 {
60 
61  namespace Util
62  {
63 
90  template <typename ValueType>
91  class Array
92  {
93 
94  public:
95  typedef std::vector<ValueType> StorageType;
96 
100  typedef std::shared_ptr<Array> SharedPointer;
101 
105  typedef ValueType ElementType;
106 
110  typedef std::size_t SizeType;
111 
119  typedef Array BaseType;
120 
125  typedef typename StorageType::const_iterator ConstElementIterator;
126 
131  typedef typename StorageType::const_reverse_iterator ConstReverseElementIterator;
132 
137  typedef typename StorageType::iterator ElementIterator;
138 
143  typedef typename StorageType::reverse_iterator ReverseElementIterator;
144 
148  Array():
149  data() {}
150 
156  Array(std::size_t num_elem, const ValueType& value = ValueType()):
157  data(num_elem, value) {}
158 
164  template <typename InputIter>
165  Array(const InputIter& first, const InputIter& last):
166  data(first, last)
167  {}
168 
172  virtual ~Array() {}
173 
175 
176  const StorageType& getData() const;
177 
184 
190  const BaseType& getBase() const;
191 
196  std::size_t getSize() const;
197 
202  std::size_t size() const;
203 
208  bool isEmpty() const;
209 
215  void resize(std::size_t num_elem, const ValueType& value = ValueType());
216 
228  void reserve(std::size_t num_elem);
229 
238  std::size_t getCapacity() const;
239 
243  void clear();
244 
249  void swap(Array& array);
250 
260  void assign(std::size_t num_elem, const ValueType& value = ValueType());
261 
272  template <typename InputIter>
273  void assign(const InputIter& first, const InputIter& last);
274 
279  void addElement(const ValueType& value = ValueType());
280 
287  void insertElement(std::size_t idx, const ValueType& value = ValueType());
288 
295  ElementIterator insertElement(const ElementIterator& it, const ValueType& value = ValueType());
296 
304  void insertElements(std::size_t idx, std::size_t num_elem, const ValueType& value = ValueType());
305 
313  void insertElements(const ElementIterator& it, std::size_t num_elem, const ValueType& value = ValueType());
314 
322  template <typename InputIter>
323  void insertElements(std::size_t idx, const InputIter& first, const InputIter& last);
324 
333  template <typename InputIter>
334  void insertElements(const ElementIterator& it, const InputIter& first, const InputIter& last);
335 
341 
347  void removeElement(std::size_t idx);
348 
357 
368 
374  const ValueType& getFirstElement() const;
375 
381  const ValueType& getLastElement() const;
382 
388  ValueType& getFirstElement();
389 
395  ValueType& getLastElement();
396 
402 
408 
414 
420 
426 
432 
438 
444 
450 
456 
462 
468 
478  const ValueType& getElement(std::size_t idx) const;
479 
489  ValueType& getElement(std::size_t idx);
490 
497  void setElement(std::size_t idx, const ValueType& value = ValueType());
498 
505  const ValueType& operator[](std::size_t idx) const;
506 
513  ValueType& operator[](std::size_t idx);
514 
515  protected:
516  void checkIfNonEmpty() const;
517  void checkIndex(std::size_t idx, bool allow_end) const;
518  void checkIterator(const ElementIterator& it, bool allow_end);
519  void checkIterator(const ConstElementIterator& it, bool allow_end) const;
520 
548  virtual const char* getClassName() const;
549 
550  private:
551  void throwIndexError() const;
552  void throwRangeError() const;
553  void throwOperationFailed() const;
554 
555  StorageType data;
556  };
557 
558 
563 
568 
573 
577  typedef std::pair<std::size_t, std::size_t> STPair;
578 
583 
588 
593 
598 
607  template <typename ValueType>
608  bool operator==(const Array<ValueType>& array1, const Array<ValueType>& array2);
609 
618  template <typename ValueType>
619  bool operator!=(const Array<ValueType>& array1, const Array<ValueType>& array2);
620 
629  template <typename ValueType>
630  bool operator<=(const Array<ValueType>& array1, const Array<ValueType>& array2);
631 
640  template <typename ValueType>
641  bool operator>=(const Array<ValueType>& array1, const Array<ValueType>& array2);
642 
651  template <typename ValueType>
652  bool operator<(const Array<ValueType>& array1, const Array<ValueType>& array2);
653 
662  template <typename ValueType>
663  bool operator>(const Array<ValueType>& array1, const Array<ValueType>& array2);
664 
665  } // namespace Util
666 } // namespace CDPL
667 
668 
669 // Implementation
670 
671 template <typename ValueType>
673 {
674  return data;
675 }
676 
677 template <typename ValueType>
679 {
680  return data;
681 }
682 
683 template <typename ValueType>
685 {
686  return *this;
687 }
688 
689 template <typename ValueType>
691 {
692  return *this;
693 }
694 
695 template <typename ValueType>
697 {
698  return data.size();
699 }
700 
701 template <typename ValueType>
703 {
704  return data.size();
705 }
706 
707 template <typename ValueType>
709 {
710  return data.empty();
711 }
712 
713 template <typename ValueType>
714 void CDPL::Util::Array<ValueType>::resize(std::size_t n, const ValueType& value)
715 {
716  data.resize(n, value);
717 }
718 
719 template <typename ValueType>
721 {
722  return data.capacity();
723 }
724 
725 template <typename ValueType>
726 void CDPL::Util::Array<ValueType>::reserve(std::size_t min_size)
727 {
728  data.reserve(min_size);
729 }
730 
731 template <typename ValueType>
733 {
734  data.clear();
735 }
736 
737 template <typename ValueType>
739 {
740  data.swap(array.data);
741 }
742 
743 template <typename ValueType>
744 void CDPL::Util::Array<ValueType>::assign(std::size_t n, const ValueType& value)
745 {
746  data.assign(n, value);
747 }
748 
749 template <typename ValueType>
750 template <typename InputIter>
751 void CDPL::Util::Array<ValueType>::assign(const InputIter& first, const InputIter& last)
752 {
753  data.assign(first, last);
754 }
755 
756 template <typename ValueType>
757 void CDPL::Util::Array<ValueType>::addElement(const ValueType& value)
758 {
759  data.push_back(value);
760 }
761 
762 template <typename ValueType>
763 void CDPL::Util::Array<ValueType>::insertElement(std::size_t idx, const ValueType& value)
764 {
765  CDPL_UTIL_ARRAY_CHECK_INDEX(idx, true);
766 
767  data.insert(data.begin() + idx, value);
768 }
769 
770 template <typename ValueType>
772  const ValueType& value)
773 {
774  CDPL_UTIL_ARRAY_CHECK_ITER(it, true);
775 
776  return data.insert(it, value);
777 }
778 
779 template <typename ValueType>
780 void CDPL::Util::Array<ValueType>::insertElements(std::size_t idx, std::size_t n, const ValueType& value)
781 {
782  CDPL_UTIL_ARRAY_CHECK_INDEX(idx, true);
783 
784  data.insert(data.begin() + idx, n, value);
785 }
786 
787 template <typename ValueType>
788 void CDPL::Util::Array<ValueType>::insertElements(const ElementIterator& it, std::size_t n, const ValueType& value)
789 {
790  CDPL_UTIL_ARRAY_CHECK_ITER(it, true);
791 
792  data.insert(it, n, value);
793 }
794 
795 template <typename ValueType>
796 template <typename InputIter>
797 void CDPL::Util::Array<ValueType>::insertElements(std::size_t idx, const InputIter& first, const InputIter& last)
798 {
799  CDPL_UTIL_ARRAY_CHECK_INDEX(idx, true);
800 
801  data.insert(data.begin() + idx, first, last);
802 }
803 
804 template <typename ValueType>
805 template <typename InputIter>
806 void CDPL::Util::Array<ValueType>::insertElements(const ElementIterator& it, const InputIter& first, const InputIter& last)
807 {
808  CDPL_UTIL_ARRAY_CHECK_ITER(it, true);
809 
810  data.insert(it, first, last);
811 }
812 
813 template <typename ValueType>
815 {
816  if (data.empty())
817  throw Base::OperationFailed("Array: attempt to pop element from an empty array");
818 
819  data.pop_back();
820 }
821 
822 template <typename ValueType>
824 {
825  CDPL_UTIL_ARRAY_CHECK_INDEX(idx, false);
826 
827  data.erase(data.begin() + idx);
828 }
829 
830 template <typename ValueType>
832 {
833  CDPL_UTIL_ARRAY_CHECK_ITER(it, false);
834 
835  return data.erase(it);
836 }
837 
838 template <typename ValueType>
840  const ElementIterator& last)
841 {
842  CDPL_UTIL_ARRAY_CHECK_ITER(first, true);
843  CDPL_UTIL_ARRAY_CHECK_ITER(last, true);
844 
845  if (first > last)
846  throw Base::RangeError(std::string(getClassName()) + ": invalid iterator range: first > last");
847 
848  return data.erase(first, last);
849 }
850 
851 template <typename ValueType>
853 {
854  checkIfNonEmpty();
855 
856  return data.front();
857 }
858 
859 template <typename ValueType>
861 {
862  checkIfNonEmpty();
863 
864  return data.back();
865 }
866 
867 template <typename ValueType>
869 {
870  checkIfNonEmpty();
871 
872  return data.front();
873 }
874 
875 template <typename ValueType>
877 {
878  checkIfNonEmpty();
879 
880  return data.back();
881 }
882 
883 template <typename ValueType>
885 {
886  return data.begin();
887 }
888 
889 template <typename ValueType>
891 {
892  return data.begin();
893 }
894 
895 template <typename ValueType>
897 {
898  return data.end();
899 }
900 
901 template <typename ValueType>
903 {
904  return data.end();
905 }
906 
907 template <typename ValueType>
909 {
910  return data.begin();
911 }
912 
913 template <typename ValueType>
915 {
916  return data.begin();
917 }
918 
919 template <typename ValueType>
921 {
922  return data.end();
923 }
924 
925 template <typename ValueType>
927 {
928  return data.end();
929 }
930 
931 template <typename ValueType>
933 {
934  return data.rbegin();
935 }
936 
937 template <typename ValueType>
939 {
940  return data.rbegin();
941 }
942 
943 template <typename ValueType>
945 {
946  return data.rend();
947 }
948 
949 template <typename ValueType>
951 {
952  return data.rend();
953 }
954 
955 template <typename ValueType>
956 const ValueType& CDPL::Util::Array<ValueType>::getElement(std::size_t idx) const
957 {
958  CDPL_UTIL_ARRAY_CHECK_INDEX(idx, false);
959 
960  return data[idx];
961 }
962 
963 template <typename ValueType>
964 ValueType& CDPL::Util::Array<ValueType>::getElement(std::size_t idx)
965 {
966  CDPL_UTIL_ARRAY_CHECK_INDEX(idx, false);
967 
968  return data[idx];
969 }
970 
971 template <typename ValueType>
972 void CDPL::Util::Array<ValueType>::setElement(std::size_t idx, const ValueType& value)
973 {
974  CDPL_UTIL_ARRAY_CHECK_INDEX(idx, false);
975 
976  data[idx] = value;
977 }
978 
979 template <typename ValueType>
980 const ValueType& CDPL::Util::Array<ValueType>::operator[](std::size_t idx) const
981 {
982  CDPL_UTIL_ARRAY_CHECK_INDEX(idx, false);
983 
984  return data[idx];
985 }
986 
987 template <typename ValueType>
988 ValueType& CDPL::Util::Array<ValueType>::operator[](std::size_t idx)
989 {
990  CDPL_UTIL_ARRAY_CHECK_INDEX(idx, false);
991 
992  return data[idx];
993 }
994 
995 template <typename ValueType>
997 {
998  if (data.empty())
999  throwOperationFailed();
1000 }
1001 
1002 template <typename ValueType>
1003 void CDPL::Util::Array<ValueType>::checkIndex(std::size_t idx, bool allow_end) const
1004 {
1005  if ((allow_end && idx > data.size()) || (!allow_end && idx >= data.size()))
1006  throwIndexError();
1007 }
1008 
1009 template <typename ValueType>
1011 {
1012  if (it < data.begin() || (allow_end && it > data.end()) || (!allow_end && it >= data.end()))
1013  throwRangeError();
1014 }
1015 
1016 template <typename ValueType>
1018 {
1019  if (it < data.begin() || (allow_end && it > data.end()) || (!allow_end && it >= data.end()))
1020  throwRangeError();
1021 }
1022 
1023 template <typename ValueType>
1025 {
1026  throw Base::IndexError(std::string(getClassName()) + ": element index out of bounds");
1027 }
1028 
1029 template <typename ValueType>
1031 {
1032  throw Base::RangeError(std::string(getClassName()) + ": invalid iterator");
1033 }
1034 
1035 template <typename ValueType>
1037 {
1038  throw Base::OperationFailed(std::string(getClassName()) + ": operation requires non-empty array");
1039 }
1040 
1041 template <typename ValueType>
1043 {
1044  return "Array";
1045 }
1046 
1047 // \cond DOC_IMPL_DETAILS
1048 
1049 template <typename ValueType>
1050 bool CDPL::Util::operator==(const Array<ValueType>& array1, const Array<ValueType>& array2)
1051 {
1052  return (array1.getData() == array2.getData());
1053 }
1054 
1055 template <typename ValueType>
1056 bool CDPL::Util::operator!=(const Array<ValueType>& array1, const Array<ValueType>& array2)
1057 {
1058  return (array1.getData() != array2.getData());
1059 }
1060 
1061 template <typename ValueType>
1062 bool CDPL::Util::operator<=(const Array<ValueType>& array1, const Array<ValueType>& array2)
1063 {
1064  return (array1.getData() <= array2.getData());
1065 }
1066 
1067 template <typename ValueType>
1068 bool CDPL::Util::operator>=(const Array<ValueType>& array1, const Array<ValueType>& array2)
1069 {
1070  return (array1.getData() >= array2.getData());
1071 }
1072 
1073 template <typename ValueType>
1074 bool CDPL::Util::operator<(const Array<ValueType>& array1, const Array<ValueType>& array2)
1075 {
1076  return (array1.getData() < array2.getData());
1077 }
1078 
1079 template <typename ValueType>
1080 bool CDPL::Util::operator>(const Array<ValueType>& array1, const Array<ValueType>& array2)
1081 {
1082  return (array1.getData() > array2.getData());
1083 }
1084 
1085 // \endcond
1086 
1087 #endif // CDPL_UTIL_ARRAY_HPP
CDPL::Util::LArray
Array< long > LArray
An array of unsigned integers of type long.
Definition: Array.hpp:572
CDPL::Util::Array::getElementsReverseEnd
ReverseElementIterator getElementsReverseEnd()
Returns a mutable iterator pointing to the end of the reversed array.
Definition: Array.hpp:950
CDPL::Util::SArray
Array< std::string > SArray
An array of std::string objects.
Definition: Array.hpp:592
CDPL::Util::Array::setElement
void setElement(std::size_t idx, const ValueType &value=ValueType())
Assigns a new value to the element specified by the index idx.
Definition: Array.hpp:972
CDPL::Util::Array::StorageType
std::vector< ValueType > StorageType
Definition: Array.hpp:95
CDPL::Util::operator!=
bool operator!=(const Array< ValueType > &array1, const Array< ValueType > &array2)
Inequality comparison operator.
CDPL::Util::Array::removeElements
ElementIterator removeElements(const ElementIterator &first, const ElementIterator &last)
Removes the elements pointed to by the iterators in the range [first, last).
Definition: Array.hpp:839
CDPL::Util::Array::popLastElement
void popLastElement()
Removes the last element of the array.
Definition: Array.hpp:814
CDPL::Util::Array::ReverseElementIterator
StorageType::reverse_iterator ReverseElementIterator
A mutable random access iterator used to iterate over the elements of the array in reverse order.
Definition: Array.hpp:143
CDPL::Util::Array::SizeType
std::size_t SizeType
The type of objects stored by the array.
Definition: Array.hpp:110
CDPL::Util::Array::insertElements
void insertElements(const ElementIterator &it, std::size_t num_elem, const ValueType &value=ValueType())
Inserts num_elem copies of value before the location specified by the iterator it.
Definition: Array.hpp:788
CDPL::Util::Array::getElementsEnd
ConstElementIterator getElementsEnd() const
Returns a constant iterator pointing to the end of the array.
Definition: Array.hpp:896
CDPL::Util::Array::end
ElementIterator end()
Returns a mutable iterator pointing to the end of the array.
Definition: Array.hpp:926
CDPL::Util::Array::end
ConstElementIterator end() const
Returns a constant iterator pointing to the end of the array.
Definition: Array.hpp:920
CDPL::Base::OperationFailed
Thrown to indicate that some requested operation has failed (e.g. due to unfulfilled preconditions or...
Definition: Base/Exceptions.hpp:211
CDPL::Base::RangeError
Thrown to indicate that a value is out of range.
Definition: Base/Exceptions.hpp:114
CDPL::Util::Array::getElementsReverseBegin
ReverseElementIterator getElementsReverseBegin()
Returns a mutable iterator pointing to the beginning of the reversed array.
Definition: Array.hpp:938
CDPL::Util::Array
A dynamic array class providing amortized constant time access to arbitrary elements.
Definition: Array.hpp:92
CDPL::Util::Array::reserve
void reserve(std::size_t num_elem)
Preallocates memory for (at least) num_elem elements.
Definition: Array.hpp:726
CDPL::Util::Array::getElementsReverseEnd
ConstReverseElementIterator getElementsReverseEnd() const
Returns a constant iterator pointing to the end of the reversed array.
Definition: Array.hpp:944
CDPL::Util::Array::resize
void resize(std::size_t num_elem, const ValueType &value=ValueType())
Inserts or erases elements at the end so that the size becomes num_elem.
Definition: Array.hpp:714
CDPL::Util::Array::checkIndex
void checkIndex(std::size_t idx, bool allow_end) const
Definition: Array.hpp:1003
CDPL::Util::Array::getLastElement
ValueType & getLastElement()
Returns a non-const reference to the last element of the array.
Definition: Array.hpp:876
CDPL::Util::BitSetArray
Array< BitSet > BitSetArray
An array of Util::BitSet objects.
Definition: Array.hpp:597
CDPL::Util::Array::ConstReverseElementIterator
StorageType::const_reverse_iterator ConstReverseElementIterator
A constant random access iterator used to iterate over the elements of the array in reverse order.
Definition: Array.hpp:131
CDPL::Util::Array::getElementsBegin
ConstElementIterator getElementsBegin() const
Returns a constant iterator pointing to the beginning of the array.
Definition: Array.hpp:884
BitSet.hpp
Definition of the type CDPL::Util::BitSet.
CDPL::Util::Array::insertElements
void insertElements(std::size_t idx, std::size_t num_elem, const ValueType &value=ValueType())
Inserts num_elem copies of value before the location specified by the index idx.
Definition: Array.hpp:780
CDPL::Util::Array::checkIfNonEmpty
void checkIfNonEmpty() const
Definition: Array.hpp:996
CDPL::Util::Array::clear
void clear()
Erases all elements.
Definition: Array.hpp:732
CDPL::Util::Array::checkIterator
void checkIterator(const ConstElementIterator &it, bool allow_end) const
Definition: Array.hpp:1017
CDPL::Base::IndexError
Thrown to indicate that an index is out of range.
Definition: Base/Exceptions.hpp:152
CDPL::Util::Array::Array
Array(const InputIter &first, const InputIter &last)
Creates and initializes the array with copies of the elements in the range [first,...
Definition: Array.hpp:165
CDPL::Util::Array::getElement
ValueType & getElement(std::size_t idx)
Returns a non-const reference to the element at index idx.
Definition: Array.hpp:964
CDPL::Util::Array::getElementsBegin
ElementIterator getElementsBegin()
Returns a mutable iterator pointing to the beginning of the array.
Definition: Array.hpp:890
CDPL::Util::Array::BaseType
Array BaseType
Specifies for derived classes the type of the Array base class.
Definition: Array.hpp:119
CDPL::Util::Array::checkIterator
void checkIterator(const ElementIterator &it, bool allow_end)
Definition: Array.hpp:1010
CDPL::Util::Array::getData
StorageType & getData()
Definition: Array.hpp:672
CDPL::Util::operator<
bool operator<(const Array< ValueType > &array1, const Array< ValueType > &array2)
Less than comparison operator.
CDPL::Util::operator>=
bool operator>=(const Array< ValueType > &array1, const Array< ValueType > &array2)
Greater or equal comparison operator.
CDPL::Util::Array::addElement
void addElement(const ValueType &value=ValueType())
Inserts a new element at the end of the array.
Definition: Array.hpp:757
CDPL::Util::Array::getClassName
virtual const char * getClassName() const
Returns the name of the (derived) array class.
Definition: Array.hpp:1042
CDPL::Util::Array::getSize
std::size_t getSize() const
Returns the number of elements stored in the array.
Definition: Array.hpp:696
CDPL::Util::Array::getElement
const ValueType & getElement(std::size_t idx) const
Returns a const reference to the element at index idx.
Definition: Array.hpp:956
CDPL::Util::Array::ConstElementIterator
StorageType::const_iterator ConstElementIterator
A constant random access iterator used to iterate over the elements of the array.
Definition: Array.hpp:125
CDPL::Util::Array::isEmpty
bool isEmpty() const
Tells whether the array is empty (getSize() == 0).
Definition: Array.hpp:708
CDPL::Util::Array::swap
void swap(Array &array)
Swaps the contents with array.
Definition: Array.hpp:738
CDPL_UTIL_ARRAY_CHECK_ITER
#define CDPL_UTIL_ARRAY_CHECK_ITER(it, allow_end)
Definition: Array.hpp:53
CDPL::Util::Array::getFirstElement
const ValueType & getFirstElement() const
Returns a const reference to the first element of the array.
Definition: Array.hpp:852
CDPL::Util::STPairArray
Array< STPair > STPairArray
An array of pairs of unsigned integers of type std::size_t.
Definition: Array.hpp:582
Array< BitSet >
CDPL::Util::Array::removeElement
ElementIterator removeElement(const ElementIterator &it)
Removes the element at the position specified by the iterator it.
Definition: Array.hpp:831
Exceptions.hpp
Definition of exception classes.
CDPL::Util::operator<=
bool operator<=(const Array< ValueType > &array1, const Array< ValueType > &array2)
Less or equal comparison operator.
CDPL::Util::Array::getData
const StorageType & getData() const
Definition: Array.hpp:678
CDPL::Util::Array::getElementsEnd
ElementIterator getElementsEnd()
Returns a mutable iterator pointing to the end of the array.
Definition: Array.hpp:902
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Util::Array::operator[]
ValueType & operator[](std::size_t idx)
Returns a non-const reference to the element at index idx.
Definition: Array.hpp:988
CDPL::Util::Array::Array
Array()
Creates an empty array.
Definition: Array.hpp:148
CDPL::Util::STArray
Array< std::size_t > STArray
An array of unsigned integers of type std::size_t.
Definition: Array.hpp:567
CDPL::Util::Array::insertElements
void insertElements(const ElementIterator &it, const InputIter &first, const InputIter &last)
Inserts the range of elements [first, last) before the location specified by the iterator it.
Definition: Array.hpp:806
CDPL::Util::Array::getFirstElement
ValueType & getFirstElement()
Returns a non-const reference to the first element of the array.
Definition: Array.hpp:868
CDPL::Util::Array::insertElements
void insertElements(std::size_t idx, const InputIter &first, const InputIter &last)
Inserts the range of elements [first, last) before the location specified by the index idx.
Definition: Array.hpp:797
CDPL::Util::Array::getCapacity
std::size_t getCapacity() const
Returns the number of elements for which memory has been allocated.
Definition: Array.hpp:720
CDPL::Util::Array::Array
Array(std::size_t num_elem, const ValueType &value=ValueType())
Creates and initializes the array with num_elem copies of value.
Definition: Array.hpp:156
CDPL::Util::Array::assign
void assign(std::size_t num_elem, const ValueType &value=ValueType())
This function fills the array with num_elem copies of the given value.
Definition: Array.hpp:744
CDPL::Util::Array::ElementType
ValueType ElementType
The type of objects stored by the array.
Definition: Array.hpp:105
CDPL::Util::Array::begin
ElementIterator begin()
Returns a mutable iterator pointing to the beginning of the array.
Definition: Array.hpp:914
CDPL::Util::Array::~Array
virtual ~Array()
Virtual destructor.
Definition: Array.hpp:172
CDPL::Util::Array::insertElement
ElementIterator insertElement(const ElementIterator &it, const ValueType &value=ValueType())
Inserts a new element before the location specified by the iterator it.
Definition: Array.hpp:771
CDPL::Util::Array::getLastElement
const ValueType & getLastElement() const
Returns a const reference to the last element of the array.
Definition: Array.hpp:860
CDPL::Util::DArray
Array< double > DArray
An array of double precision floating-point numbers.
Definition: Array.hpp:587
CDPL::Util::Array::getBase
BaseType & getBase()
Returns a non-const reference to itself.
Definition: Array.hpp:684
CDPL::Util::Array::getBase
const BaseType & getBase() const
Returns a const reference to itself.
Definition: Array.hpp:690
CDPL::Util::UIArray
Array< unsigned int > UIArray
An array of unsigned integers.
Definition: Array.hpp:562
CDPL::Util::operator>
bool operator>(const Array< ValueType > &array1, const Array< ValueType > &array2)
Greater than comparison operator.
CDPL::Util::Array::insertElement
void insertElement(std::size_t idx, const ValueType &value=ValueType())
Inserts a new element before the location specified by the index idx.
Definition: Array.hpp:763
CDPL_UTIL_ARRAY_CHECK_INDEX
#define CDPL_UTIL_ARRAY_CHECK_INDEX(idx, allow_end)
Definition: Array.hpp:45
CDPL::Util::operator==
bool operator==(const Array< ValueType > &array1, const Array< ValueType > &array2)
Equality comparison operator.
CDPL::Util::STPair
std::pair< std::size_t, std::size_t > STPair
A pair of unsigned integers of type std::size_t.
Definition: Array.hpp:577
CDPL::Util::Array::ElementIterator
StorageType::iterator ElementIterator
A mutable random access iterator used to iterate over the elements of the array.
Definition: Array.hpp:137
CDPL::Util::Array::removeElement
void removeElement(std::size_t idx)
Removes the element at the position specified by the index idx.
Definition: Array.hpp:823
CDPL::Util::Array::SharedPointer
std::shared_ptr< Array > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Array instances.
Definition: Array.hpp:100
CDPL::Util::Array::operator[]
const ValueType & operator[](std::size_t idx) const
Returns a const reference to the element at index idx.
Definition: Array.hpp:980
CDPL::Util::Array::begin
ConstElementIterator begin() const
Returns a constant iterator pointing to the beginning of the array.
Definition: Array.hpp:908
CDPL::Util::Array::assign
void assign(const InputIter &first, const InputIter &last)
This function fills a vector with copies of the elements in the range [first, last).
Definition: Array.hpp:751
CDPL::Util::Array::getElementsReverseBegin
ConstReverseElementIterator getElementsReverseBegin() const
Returns a constant iterator pointing to the beginning of the reversed array.
Definition: Array.hpp:932
CDPL::Util::Array::size
std::size_t size() const
Returns the number of elements stored in the array.
Definition: Array.hpp:702