yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
NumberlikeArray< Blk > Class Template Reference

#include <NumberlikeArray.hh>

+ Collaboration diagram for NumberlikeArray< Blk >:

Public Types

typedef unsigned int Index
 

Public Member Functions

 NumberlikeArray (Index c)
 
 NumberlikeArray ()
 
 ~NumberlikeArray ()
 
void allocate (Index c)
 
void allocateAndCopy (Index c)
 
 NumberlikeArray (const NumberlikeArray< Blk > &x)
 
void operator= (const NumberlikeArray< Blk > &x)
 
 NumberlikeArray (const Blk *b, Index blen)
 
Index getCapacity () const
 
Index getLength () const
 
Blk getBlock (Index i) const
 
bool isEmpty () const
 
bool operator== (const NumberlikeArray< Blk > &x) const
 
bool operator!= (const NumberlikeArray< Blk > &x) const
 

Data Fields

Index cap
 
Index len
 
Blk * blk
 

Static Public Attributes

static const unsigned int N = 8 * sizeof(Blk)
 

Detailed Description

template<class Blk>
class NumberlikeArray< Blk >

Definition at line 21 of file NumberlikeArray.hh.

Member Typedef Documentation

template<class Blk>
typedef unsigned int NumberlikeArray< Blk >::Index

Definition at line 25 of file NumberlikeArray.hh.

Constructor & Destructor Documentation

template<class Blk>
NumberlikeArray< Blk >::NumberlikeArray ( Index  c)
inline

Definition at line 37 of file NumberlikeArray.hh.

37  : cap(c), len(0) {
38  blk = (cap > 0) ? (new Blk[cap]) : NULL;
39  }
#define NULL
template<class Blk>
NumberlikeArray< Blk >::NumberlikeArray ( )
inline

Definition at line 45 of file NumberlikeArray.hh.

45  : cap(0), len(0) {
46  blk = NULL;
47  }
#define NULL
template<class Blk>
NumberlikeArray< Blk >::~NumberlikeArray ( )
inline

Definition at line 50 of file NumberlikeArray.hh.

50  {
51  delete [] blk;
52  }
template<class Blk>
NumberlikeArray< Blk >::NumberlikeArray ( const NumberlikeArray< Blk > &  x)

Definition at line 123 of file NumberlikeArray.hh.

124  : len(x.len) {
125  // Create array
126  cap = len;
127  blk = new Blk[cap];
128  // Copy blocks
129  Index i;
130  for (i = 0; i < len; i++)
131  blk[i] = x.blk[i];
132 }
unsigned int Index
template<class Blk>
NumberlikeArray< Blk >::NumberlikeArray ( const Blk *  b,
Index  blen 
)

Definition at line 151 of file NumberlikeArray.hh.

152  : cap(blen), len(blen) {
153  // Create array
154  blk = new Blk[cap];
155  // Copy blocks
156  Index i;
157  for (i = 0; i < len; i++)
158  blk[i] = b[i];
159 }
unsigned int Index

Member Function Documentation

template<class Blk >
void NumberlikeArray< Blk >::allocate ( Index  c)

Definition at line 94 of file NumberlikeArray.hh.

94  {
95  // If the requested capacity is more than the current capacity...
96  if (c > cap) {
97  // Delete the old number array
98  delete [] blk;
99  // Allocate the new array
100  cap = c;
101  blk = new Blk[cap];
102  }
103 }

+ Here is the caller graph for this function:

template<class Blk >
void NumberlikeArray< Blk >::allocateAndCopy ( Index  c)

Definition at line 106 of file NumberlikeArray.hh.

106  {
107  // If the requested capacity is more than the current capacity...
108  if (c > cap) {
109  Blk *oldBlk = blk;
110  // Allocate the new number array
111  cap = c;
112  blk = new Blk[cap];
113  // Copy number blocks
114  Index i;
115  for (i = 0; i < len; i++)
116  blk[i] = oldBlk[i];
117  // Delete the old array
118  delete [] oldBlk;
119  }
120 }
unsigned int Index
template<class Blk>
Blk NumberlikeArray< Blk >::getBlock ( Index  i) const
inline

Definition at line 74 of file NumberlikeArray.hh.

74 { return blk[i]; }
template<class Blk>
Index NumberlikeArray< Blk >::getCapacity ( ) const
inline

Definition at line 72 of file NumberlikeArray.hh.

72 { return cap; }

+ Here is the caller graph for this function:

template<class Blk>
Index NumberlikeArray< Blk >::getLength ( ) const
inline

Definition at line 73 of file NumberlikeArray.hh.

73 { return len; }

+ Here is the caller graph for this function:

template<class Blk>
bool NumberlikeArray< Blk >::isEmpty ( ) const
inline

Definition at line 75 of file NumberlikeArray.hh.

75 { return len == 0; }

+ Here is the caller graph for this function:

template<class Blk>
bool NumberlikeArray< Blk >::operator!= ( const NumberlikeArray< Blk > &  x) const
inline

Definition at line 82 of file NumberlikeArray.hh.

82  {
83  return !operator ==(x);
84  }
bool operator==(const NumberlikeArray< Blk > &x) const

+ Here is the caller graph for this function:

template<class Blk>
void NumberlikeArray< Blk >::operator= ( const NumberlikeArray< Blk > &  x)

Definition at line 135 of file NumberlikeArray.hh.

135  {
136  /* Calls like a = a have no effect; catch them before the aliasing
137  * causes a problem */
138  if (this == &x)
139  return;
140  // Copy length
141  len = x.len;
142  // Expand array if necessary
143  allocate(len);
144  // Copy number blocks
145  Index i;
146  for (i = 0; i < len; i++)
147  blk[i] = x.blk[i];
148 }
void allocate(Index c)
unsigned int Index

+ Here is the caller graph for this function:

template<class Blk>
bool NumberlikeArray< Blk >::operator== ( const NumberlikeArray< Blk > &  x) const

Definition at line 162 of file NumberlikeArray.hh.

162  {
163  if (len != x.len)
164  // Definitely unequal.
165  return false;
166  else {
167  // Compare corresponding blocks one by one.
168  Index i;
169  for (i = 0; i < len; i++)
170  if (blk[i] != x.blk[i])
171  return false;
172  // No blocks differed, so the objects are equal.
173  return true;
174  }
175 }
unsigned int Index

+ Here is the caller graph for this function:

Field Documentation

template<class Blk>
Blk* NumberlikeArray< Blk >::blk

Definition at line 34 of file NumberlikeArray.hh.

template<class Blk>
Index NumberlikeArray< Blk >::cap

Definition at line 30 of file NumberlikeArray.hh.

template<class Blk>
Index NumberlikeArray< Blk >::len

Definition at line 32 of file NumberlikeArray.hh.

template<class Blk>
const unsigned int NumberlikeArray< Blk >::N = 8 * sizeof(Blk)
static

Definition at line 27 of file NumberlikeArray.hh.


The documentation for this class was generated from the following file: