File: apvector.h

package info (click to toggle)
wing 0.7-33
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,744 kB
  • sloc: cpp: 2,526; sh: 65; makefile: 16
file content (67 lines) | stat: -rw-r--r-- 1,982 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef _APVECTOR_H
#define _APVECTOR_H

//****************************************************************
//
// apvector class template
//
// Implements dynamically-allocated 1-D arrays
//   with subscript range checking.
//
// The template data type parameter itemType must be either a built-in
//   type or support a default constructor and assignment.
//
//****************************************************************

template <class itemType> 
class apvector {

  public:
  
  // Constructors/destructor:

    apvector();           // Default constructor: builds an
                          //   empty vector of size 0

    apvector(int size);   // Builds a vector of a given size

    apvector(int size, const itemType &fillValue);
                          // Builds a vector of a given size and sets
                          //   all its elements to fillValue

    apvector(const apvector &vec);
                          // Copy constructor: builds a vector equal to
                          //  a given vector

    ~apvector();          // Destructor
    
  // Assignment:

    const apvector &operator= (const apvector &vec);

  // Overloaded subscripting operators (perform subscript range checking):

    itemType &operator[] (int k);
    const itemType &operator[] (int k) const;

  // length() and resize(...) member functions:

    int  length() const;   // Returns the current size of the vector

    void resize(int newSize);
                           // Changes the size to a specified new size
                           //   (can result in losing values if the tail
                           //    is chopped off)

  private:
                                                
    int mSize;             // Number of elements in the vector.
    itemType *mList;       // Pointer to the array buffer.
};

#include "apvector.cpp"
// Continued in apvector.cpp...

#endif // _APVECTOR_H