Jelajahi Sumber

Queue: clear method implemented, Test: connections added

mikymod 13 tahun lalu
induk
melakukan
6e47b33180

+ 5 - 2
src/CMakeLists.txt

@@ -238,11 +238,14 @@ set (WIN_SRC
 )
 
 set (NETWORK_SRC
-	network/BitMessage.h
+	network/BitMessage.cpp
+	network/Connection.cpp
+	
 )
 
 set (NETWORK_HEADERS
-	network/BitMessage.cpp
+	network/BitMessage.h
+	network/Connection.h
 )
 
 set (SOURCES

+ 9 - 0
src/core/containers/Queue.h

@@ -58,6 +58,8 @@ public:
 	void			pop_back();
 	void			push_front(const T& item);
 	void			pop_front();
+	
+	void 			clear();
 
 	T*				begin();
 	const T*		begin() const;
@@ -206,6 +208,13 @@ inline void Queue<T>::pop_front()
 	m_size--;
 }
 
+//-----------------------------------------------------------------------------
+template <typename T>
+inline void Queue<T>::clear()
+{
+	m_size = 0;
+}
+
 //-----------------------------------------------------------------------------
 template <typename T>
 inline T* Queue<T>::begin()

+ 9 - 5
src/network/Connection.cpp

@@ -5,15 +5,19 @@ namespace crown
 namespace network
 {
 
-Connection::Connection()
+Connection::Connection(Allocator& allocator) :
+ 	m_reliable_send(allocator),
+ 	m_reliable_receive(allocator)
 {
+  
 }
 
 Connection::~Connection()
 {
+  
 }
 
-void Connection::init(const NetAddress addr, const int id)
+void Connection::init(const os::NetAddress addr, const int id)
 {
 	m_remote_address = addr;
 	m_id = id;
@@ -102,7 +106,7 @@ bool Connection::unsent_fragments_left() const
   
 }
 
-bool Connection::process(const NetAddress from, BitMessage &msg, int &sequence, int time)
+bool Connection::process(const os::NetAddress from, BitMessage &msg, int &sequence, int time)
 {
   
 }
@@ -119,8 +123,8 @@ bool Connection::get_reliable_message(BitMessage &msg)
 
 void Connection::clear_reliable_messages()
 {
-	m_reliable_send = NULL;
-	m_reliable_receive = NULL;
+	m_reliable_send.clear();
+	m_reliable_receive.clear();
 }
 
 void Connection::_write_message(BitMessage &out, const BitMessage &msg)

+ 2 - 1
src/network/Connection.h

@@ -2,6 +2,7 @@
 
 #include "Types.h"
 #include "OS.h"
+#include "Allocator.h"
 #include "BitMessage.h"
 #include "Queue.h"
 
@@ -16,7 +17,7 @@ namespace network
 	{
 	public:
 	  
-								Connection();
+								Connection(Allocator& allocator);
 								~Connection();
   
 		void					init(const os::NetAddress addr, const int id);

+ 3 - 0
tests/CMakeLists.txt

@@ -9,9 +9,12 @@ add_executable(allocators allocators.cpp)
 add_executable(containers containers.cpp)
 add_executable(messages messages.cpp)
 add_executable(compressors compressors.cpp)
+add_executable(connections connections.cpp)
 
 
 target_link_libraries(allocators crown)
 target_link_libraries(containers crown)
 target_link_libraries(messages crown)
 target_link_libraries(compressors crown)
+target_link_libraries(connections crown)
+

+ 10 - 0
tests/connections.cpp

@@ -0,0 +1,10 @@
+#include <cstdio>
+
+#include "Connection.h"
+
+using namespace crown;
+
+int main()
+{
+	return 0;
+}