Skip to content

Commit

Permalink
Clean up implicit sharing internal data classes
Browse files Browse the repository at this point in the history
Remove all assignment operators, because they are never used. Make copy constructor and destructor private, becuase they are only used by friend pointer class.
  • Loading branch information
ropez committed Mar 1, 2010
1 parent a03a44a commit f649ae5
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 77 deletions.
15 changes: 7 additions & 8 deletions include/Pieces/byte_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,6 @@ class ByteArray
// Creates a deep copy of the 'size' first bytes at location 'data'.
Data(const void* data, size_t size);

// Creates a deep copy (called automatically by SharedDataPointer if needed).
Data(const Data& other);

// Creates a deep copy (called automatically by SharedDataPointer if needed).
Data& operator=(const Data& other);

// Calculate number of bytes to allocate and allocate uninitialized space.
// Deletes any old data.
void allocate(size_t size);
Expand All @@ -285,13 +279,18 @@ class ByteArray
// Pointer to allocated data.
byte_t* data;

protected:
private:

// Make data pointer able to call destructor.
// Make data pointer able to copy and delete
friend class SharedDataPointer<Data>;

// Creates a deep copy (called automatically by SharedDataPointer if needed).
Data(const Data& other);

// Protected to prevent stack allocation.
~Data();

DISABLE_ASSIGNMENT(Data);
};

SharedDataPointer<Data> d;
Expand Down
11 changes: 8 additions & 3 deletions include/Pieces/datagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,16 @@ class Datagram
Data();
Data(const ByteArray& data, const SocketAddress& addr);

Data(const Data& other);
Data& operator=(const Data& other);

ByteArray data;
SocketAddress address;

private:
friend class SharedDataPointer<Data>;

Data(const Data& other);
~Data() {}

DISABLE_ASSIGNMENT(Data);
};

SharedDataPointer<Data> d;
Expand Down
9 changes: 7 additions & 2 deletions include/Pieces/frame_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,15 @@ class FrameData
public:
Data();

map_t objectData;

private:
friend class SharedDataPointer<Data>;

Data(const Data& other);
Data& operator=(const Data& other);
~Data() {}

map_t objectData;
DISABLE_ASSIGNMENT(Data);
};

SharedDataPointer<Data> d;
Expand Down
11 changes: 8 additions & 3 deletions include/Pieces/game_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ class GameData
public:
Data();

Data(const Data& other);
Data& operator=(const Data& other);

size_t maxFrames;
map_t frameData;

private:
friend class SharedDataPointer<Data>;

Data(const Data& other);
~Data() {}

DISABLE_ASSIGNMENT(Data);
};

SharedDataPointer<Data> d;
Expand Down
1 change: 1 addition & 0 deletions include/Pieces/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// Macro to disable copy operations
#define DISABLE_COPY(c) c(const c&); c& operator=(const c&);
#define DISABLE_ASSIGNMENT(c) c& operator=(const c&);


/**
Expand Down
11 changes: 8 additions & 3 deletions include/Pieces/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,17 @@ class Message
public:
Data();

Data(const Data& other);
Data& operator=(const Data& other);

int type;
flags_t flags;
PropertyList properties;

private:
friend class SharedDataPointer<Data>;

Data(const Data& other);
~Data() {}

DISABLE_ASSIGNMENT(Data);
};

SharedDataPointer<Data> d;
Expand Down
9 changes: 8 additions & 1 deletion include/Pieces/property_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,16 @@ class PropertyList
{
public:
Data();
Data(const Data& other);

map_t properties;

private:
friend class SharedDataPointer<Data>;

Data(const Data& other);
~Data() {}

DISABLE_ASSIGNMENT(Data);
};

SharedDataPointer<Data> d;
Expand Down
9 changes: 8 additions & 1 deletion include/Pieces/value_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,16 @@ class ValueList
{
public:
Data();
Data(const Data& other);

list_t values;

private:
friend class SharedDataPointer<Data>;

Data(const Data& other);
~Data() {}

DISABLE_ASSIGNMENT(Data);
};

SharedDataPointer<Data> d;
Expand Down
17 changes: 4 additions & 13 deletions include/Pieces/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class Vector
{
public:
Data();
Data(const Data& other);
Data(const stl_vector_t& other);

Data(size_type n);
Expand All @@ -106,15 +105,15 @@ class Vector
template <class InputIterator>
Data(InputIterator f, InputIterator l);

Data& operator=(const Data& other);

stl_vector_t data;

protected:

private:
friend class SharedDataPointer<Data>;

Data(const Data& other);
~Data();

DISABLE_ASSIGNMENT(Data);
};

SharedDataPointer<Data> d;
Expand Down Expand Up @@ -452,14 +451,6 @@ Vector<T>::Data::Data(InputIterator f, InputIterator l)
}


template<typename T>
typename Vector<T>::Data& Vector<T>::Data::operator=(const Data& other)
{
data = other.data;
return *this;
}


template<typename T>
Vector<T>::Data::~Data()
{
Expand Down
16 changes: 0 additions & 16 deletions src/pieces/byte_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,6 @@ ByteArray::Data::Data(const Data& other)
}


ByteArray::Data& ByteArray::Data::operator=(const Data& other)
{
if (this != &other)
{
delete[] data;

allocated = other.allocated;
size = other.size;
data = new byte_t[allocated];

std::memcpy(this->data, other.data, other.size);
}
return *this;
}


ByteArray::Data::~Data()
{
delete[] data;
Expand Down
9 changes: 0 additions & 9 deletions src/pieces/datagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,4 @@ Datagram::Data::Data(const Data& other)
{
}


Datagram::Data& Datagram::Data::operator=(const Data& other)
{
data = other.data;
address = other.address;

return *this;
}

} // namespace pcs
8 changes: 0 additions & 8 deletions src/pieces/game_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,4 @@ GameData::Data::Data(const Data& other)
{
}


GameData::Data& GameData::Data::operator=(const Data& other)
{
maxFrames = other.maxFrames;
frameData = other.frameData;
return *this;
}

} // namespace pcs
10 changes: 0 additions & 10 deletions src/pieces/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,6 @@ Message::Data::Data(const Data& other)
}


Message::Data& Message::Data::operator=(const Data& other)
{
type = other.type;
flags = other.flags;
properties = other.properties;

return *this;
}


DataStream& operator<<(DataStream& ds, const Message& msg)
{
return ds << msg.getMessageType() << msg.getFlags() << msg.getProperties();
Expand Down

0 comments on commit f649ae5

Please sign in to comment.