Commit 2f86220a authored by legoc's avatar legoc
Browse files

(split) Implemented InstanceArray as vector<unique_ptr<Instance>>

parent 5abebb37
......@@ -2,7 +2,7 @@ if(NOT DEFINED PROJECT_NAME)
cmake_minimum_required(VERSION 3.7.2)
# Project name and version
project(cameo VERSION 1.0.1 LANGUAGES CXX)
project(cameo VERSION 1.0.2 LANGUAGES CXX)
#cmake_policy(SET CMP0048 NEW)
endif()
......
1.0.2
-----
* Removed JSON.h from include.
* Implemented InstanceArray as vector<unique_ptr<Instance>>.
1.0.1
-----
......
......@@ -321,24 +321,7 @@ private:
///////////////////////////////////////////////////////////////////////////
// InstanceArray
class InstanceArray {
friend class cameo::Server;
public:
InstanceArray(const InstanceArray& array);
~InstanceArray();
std::size_t size() const;
std::unique_ptr<Instance>& operator[](std::size_t index);
private:
InstanceArray();
void allocate(std::size_t size);
std::size_t m_size;
std::unique_ptr<Instance>* m_array;
};
typedef std::vector<std::unique_ptr<Instance>> InstanceArray;
///////////////////////////////////////////////////////////////////////////
// Publisher
......
......@@ -19,7 +19,7 @@
#define CAMEO_API_VERSION_MAJOR 1
#define CAMEO_API_VERSION_MINOR 0
#define CAMEO_API_VERSION_REVISION 1
#define CAMEO_API_VERSION_REVISION 2
#include "Application.h"
#include "Server.h"
......
......@@ -759,41 +759,6 @@ std::shared_ptr<OutputStreamSocket> Instance::getOutputStreamSocket() {
return m_outputStreamSocket;
}
///////////////////////////////////////////////////////////////////////////
// InstanceArray
InstanceArray::InstanceArray() :
m_size(0),
m_array(0) {
}
InstanceArray::InstanceArray(const InstanceArray& array) :
m_size(array.m_size),
m_array(new unique_ptr<Instance>[m_size]) {
// transferring pointers
for (size_t i = 0; i < m_size; i++) {
m_array[i] = std::move(array.m_array[i]);
}
}
InstanceArray::~InstanceArray() {
delete [] m_array;
}
void InstanceArray::allocate(std::size_t size) {
m_size = size;
m_array = new unique_ptr<Instance>[size];
}
std::size_t InstanceArray::size() const {
return m_size;
}
std::unique_ptr<Instance>& InstanceArray::operator[](std::size_t index) {
return m_array[index];
}
///////////////////////////////////////////////////////////////////////////////
// Publisher
......
......@@ -212,7 +212,7 @@ application::InstanceArray Server::connectAll(const std::string& name, Option op
size_t size = array.Size();
// Allocate the array.
instances.allocate(size);
instances.reserve(size);
int aliveInstancesCount = 0;
......@@ -241,19 +241,19 @@ application::InstanceArray Server::connectAll(const std::string& name, Option op
instance->setOutputStreamSocket(streamSocket);
}
instances.m_array[i] = std::move(instance);
instances.push_back(std::move(instance));
}
}
// Copy the alive instances.
application::InstanceArray aliveInstances;
aliveInstances.allocate(aliveInstancesCount);
aliveInstances.reserve(aliveInstancesCount);
int j = 0;
for (int i = 0; i < size; ++i) {
if (instances.m_array[i].get() != 0) {
aliveInstances[j] = std::move(instances.m_array[i]);
if (instances[i].get() != nullptr) {
aliveInstances.push_back(std::move(instances[i]));
j++;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment