SmallArray[ GAMB | Source | Keywords | Summary | Ancestors | All Members | Descendants ]
| public: | |
| // STL compliance defintions | |
| typedef DataT* | iterator; |
| typedef const DataT* | const_iterator; |
| typedef DataT& | reference; |
| typedef const DataT& | const_reference; |
| // Constructors/Destructor | |
| explicit | SmallArray(unsigned short size); |
| SmallArray(const SmallArray< DataT>& sa); | |
| ~SmallArray(); | |
| bool | push_back(const DataT& elem); |
| // OPERATORS | |
| SmallArray< DataT>& | operator=(const SmallArray< DataT>& sa); |
| reference | operator[](unsigned short index); |
| const_reference | operator[](unsigned short index) const; |
| iterator | begin(); |
| const_iterator | begin() const; |
| iterator | end(); |
| const_iterator | end() const; |
| unsigned short | size() const ; |
| unsigned short | max_size() const ; |
| unsigned short | capacity() const ; |
| bool | empty() ; |
| bool | full() ; |
| protected: |
Copyright: SAMBA group, Tel-Aviv Univ. Israel, 1999.
// in this example we assume the molecule number is given
typedef SmallArray<ReferenceFrame> TransInfo;
typedef SmallArray<TransInfo> TransInfoArray;
ifstream ini_file(iniFileName);
assert(iniFileName);
char buffer[1024];
int i=0;
bool found = false;
while (!ini_file.eof()) {
ini_file.getline(buffer,100);
if (!(*buffer=='#')) {
if (strncmp(buffer, "-->TRANSFORMATIONS_START",24) == 0) {
found = true;
i=0;
}
else if (found && i <max_trans) {
istrstream ist(buffer,100);
ist >> r1 >> r2 >> r3 >> t1 >> t2 >> t3;
ReferenceFrame tmp =
ReferenceFrame(RigidTrans3(Vector3(r1,r2,r3),
Vector3(t1,t2,t3)));
trans_array[mol_number].push_back(tmp);
++i;
}
}
For printing this array we only need to take two iterators and go through the motion of printing them. One might notice that I used the capabilities of the operator[] though they are not necessary and one might have used (*it).begin() insteand.
for (TransInfoArray::const_iterator it = trans_array.begin();
it != trans_array.end() ; ++it) {
s << "Transformations from mol 0 to mol " << it-trans_array.begin()+1
<< endl;
for(TransInfo::iterator jt=trans_array[it-trans_array.begin()].begin();
jt != trans_array[it].end(); ++jt)
s << *jt << endl;
s << "--------------------------------------------------\n";
}
typedef DataT* iterator;
STL compliant typedef.
typedef DataT* iterator;
typedef const DataT* const_iterator;
STL compliant typedef.
typedef const DataT* const_iterator;
typedef DataT& reference;
STL compliant typedef.
typedef DataT& reference;
typedef const DataT& const_reference;
STL compliant typedef.
typedef const DataT& const_reference;
explicit SmallArray(unsigned short size);
Constructor receives initial space to allocate. Default is 3.
explicit SmallArray(unsigned short size);
SmallArray(const SmallArray< DataT>& sa);
Copy constructor
SmallArray(const SmallArray< DataT>& sa);
~SmallArray();
Destructor. Deletes vector data.
~SmallArray();
bool push_back(const DataT& elem);
Adds an item at the end of the array add to the occ and return true.
// Return flase if no space left
bool push_back(const DataT& elem);
SmallArray< DataT>& operator=(const SmallArray< DataT>& sa);
assignment operator
SmallArray< DataT>& operator=(const SmallArray< DataT>& sa);
reference operator[](unsigned short index);
Returns reference to indexed element of the array.
checking bounds
reference operator[](unsigned short index);
const_reference operator[](unsigned short index) const;
Returns a const reference to indexed element of the array.
cheking bounds
const_reference operator[](unsigned short index) const;
iterator begin();
Returns a pointer to the vector's head.
iterator begin();
const_iterator begin() const;
Returns a pointer to the vector's head.
const_iterator begin() const;
iterator end();
Returns a pointer to the vector's end. The end is past the last element
of the vector.
iterator end();
const_iterator end() const;
Returns a pointer to the vector's end. The end is past the last element
of the vector.
const_iterator end() const;
unsigned short size() const ;
This function return the current size of the array
inline unsigned short size() const ;
Function is currently defined inline.
unsigned short max_size() const ;
This function returns the maximum size of the array
the demand is that always size() <= max_size()
inline unsigned short max_size() const ;
Function is currently defined inline.
unsigned short capacity() const ;
This function returns the maximum size of the array
the demand is that always size() <= capacity()
we add this function to be compliant with the STL vector
inline unsigned short capacity() const ;
Function is currently defined inline.
bool empty() ;
returns true if there are no elements in the array
inline bool empty() ;
Function is currently defined inline.
bool full() ;
returns true if there is no room left in the array
inline bool full() ;
Function is currently defined inline.
| public: | ||
|---|---|---|
| // STL compliance defintions | ||
| typedef DataT* | iterator; | |
| typedef const DataT* | const_iterator; | |
| typedef DataT& | reference; | |
| typedef const DataT& | const_reference; | |
| // Constructors/Destructor | ||
| explicit | SmallArray(unsigned short size); | |
| bool | push_back(const DataT& elem); | |
| // OPERATORS | ||
| SmallArray< DataT>& | operator=(const SmallArray< DataT>& sa); | |
| reference | operator[](unsigned short index); | |
| const_reference | operator[](unsigned short index) const; | |
| iterator | begin(); | |
| const_iterator | begin() const; | |
| iterator | end(); | |
| const_iterator | end() const; | |
| unsigned short | size() const ; | |
| unsigned short | max_size() const ; | |
| unsigned short | capacity() const ; | |
| bool | empty() ; | |
| bool | full() ; | |
| protected: | ||
Report problems to jkotula@unimax.com