summaryrefslogtreecommitdiff
path: root/ace/Vector_T.cpp
blob: 734eab8a2fbbe4f664d576cbceeba9a3752cfcff (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// $Id$

#ifndef ACE_VECTOR_T_C
#define ACE_VECTOR_T_C

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Vector_T.h"

#if !defined (__ACE_INLINE__)
#include "ace/Vector_T.i"
#endif /* __ACE_INLINE__ */

ACE_RCSID(ace, Vector_T, "$Id$")

ACE_ALLOC_HOOK_DEFINE(ACE_Vector)

template <class T, size_t DEFAULT_SIZE>
void ACE_Vector<T, DEFAULT_SIZE>::resize (const size_t new_size,
					  const T& t)
{
  ACE_Array<T>::size (new_size);
  if (new_size > length_)
    for (size_t i = length_; i < new_size; ++i)
      (*this)[i]=t;

  curr_max_size_ = this->max_size ();
  length_ = new_size;
}

template <class T, size_t DEFAULT_SIZE>
void ACE_Vector<T, DEFAULT_SIZE>::push_back (const T& elem)
{
  if (length_ == curr_max_size_)
    {
      ACE_Array<T>::size (curr_max_size_ * 2);
      curr_max_size_ = this->max_size ();
    }
  ++length_;
  (*this)[length_-1] = elem;
}

template <class T, size_t DEFAULT_SIZE>
void ACE_Vector<T, DEFAULT_SIZE>::dump (void) const
{
#if 0
  // Can't do this unless the vector is an object with a dump
  // function.
  for (size_t i = 0; i < this->size (); ++i)
    (*this)[i].dump ();
#endif /* 0 */
}

#if 0
template<class T>
int compare(const ACE_Vector<T>& v1,
	     const ACE_Vector<T>& v2,
             const size_t from_ndx,
	     const size_t to_ndx)
{
  size_t last1 = v1.size () - 1;
  size_t last2 = v2.size () - 1;
  if(last1 < from_ndx || last1 < to_ndx)
    {
      return false;
    }
  if (last2 < from_ndx || last2 < to_ndx)
    {
      return false;
    }
  if (last1 != last2)
    {
      return false;
    }

  //  cout<<"compare() <================="<<endl;
  for (size_t i = from_ndx; i <= to_ndx; ++i)
    {
      //     cout<<"V1["<<i<<"]="<<v1[i];
      //     cout<<", V2["<<i<<"]="<<v2[i];
      //     cout<<": NOT EQUAL == "<<(v1[i]!=v2[i])<<endl;
      if (v1[i] != v2[i])
	{
	  return false;
	}
    }
  //  cout<<"compare() ====================>"<<endl;
  return true;
}

template<class T>
int partial_compare(const ACE_Vector<T>& v1,
		     const ACE_Vector<T>& v2,
                     const size_t from_ndx,
		     const size_t to_ndx)
{
  size_t last1 = v1.size () - 1;
  size_t last2 = v2.size () - 1;
  if (last1 < from_ndx || last1 < to_ndx)
    {
      return false;
    }
  if (last2 < from_ndx || last2 < to_ndx)
    {
      return false;
    }
  //  cout<<"partial_compare() <================="<<endl;
  for (size_t i = from_ndx; i <= to_ndx; ++i)
    {
      //     cout<<"V1["<<i<<"]="<<v1[i];
      //     cout<<", V2["<<i<<"]="<<v2[i];
      //     cout<<": NOT EQUAL == "<<(v1[i]!=v2[i])<<endl;
      if (v1[i] != v2[i])
	{
	  return false;
	}
    }
  //  cout<<"partial_compare() ====================>"<<endl;
  return true;
}
#endif

#endif /* ACE_VECTOR_T_C */