Changeset - r9335:2e113380d3f6
[Not reviewed]
master
0 1 0
peter1138 - 16 years ago 2008-05-24 10:02:49
peter1138@openttd.org
(svn r13227) -Codechange: Apply code style
1 file changed with 16 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/misc/smallvec.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file smallvec.h Simple vector class that allows allocating an item without the need to copy data needlessly. */
 
/** @file smallvec.h Simple vector class that allows allocating an item without the need to copy this->data needlessly. */
 

	
 
#ifndef SMALLVEC_H
 
#define SMALLVEC_H
 

	
 
template <typename T, uint S> struct SmallVector {
 
template <typename T, uint S>
 
struct SmallVector {
 
	T *data;
 
	uint items;
 
	uint capacity;
 
@@ -14,7 +15,7 @@ template <typename T, uint S> struct Sma
 

	
 
	~SmallVector()
 
	{
 
		free(data);
 
		free(this->data);
 
	}
 

	
 
	/**
 
@@ -22,42 +23,42 @@ template <typename T, uint S> struct Sma
 
	 */
 
	T *Append()
 
	{
 
		if (items == capacity) {
 
			capacity += S;
 
			data = ReallocT(data, capacity);
 
		if (this->items == this->capacity) {
 
			this->capacity += S;
 
			this->data = ReallocT(this->data, this->capacity);
 
		}
 

	
 
		return &data[items++];
 
		return &this->data[this->items++];
 
	}
 

	
 
	const T *Begin() const
 
	{
 
		return data;
 
		return this->data;
 
	}
 

	
 
	T *Begin()
 
	{
 
		return data;
 
		return this->data;
 
	}
 

	
 
	const T *End() const
 
	{
 
		return &data[items];
 
		return &this->data[this->items];
 
	}
 

	
 
	T *End()
 
	{
 
		return &data[items];
 
		return &this->data[this->items];
 
	}
 

	
 
	const T *Get(size_t index) const
 
	const T *Get(uint index) const
 
	{
 
		return &data[index];
 
		return &this->data[index];
 
	}
 

	
 
	T *Get(size_t index)
 
	T *Get(uint index)
 
	{
 
		return &data[index];
 
		return &this->data[index];
 
	}
 
};
 

	
0 comments (0 inline, 0 general)