Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Cameo
cameo
Commits
2f86220a
Commit
2f86220a
authored
Nov 25, 2020
by
legoc
Browse files
(split) Implemented InstanceArray as vector<unique_ptr<Instance>>
parent
5abebb37
Changes
6
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
2f86220a
...
...
@@ -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
()
...
...
ChangeLog
View file @
2f86220a
1.0.2
-----
* Removed JSON.h from include.
* Implemented InstanceArray as vector<unique_ptr<Instance>>.
1.0.1
-----
...
...
include/Application.h
View file @
2f86220a
...
...
@@ -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
...
...
include/cameo.h
View file @
2f86220a
...
...
@@ -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"
...
...
src/Application.cpp
View file @
2f86220a
...
...
@@ -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
...
...
src/Server.cpp
View file @
2f86220a
...
...
@@ -212,7 +212,7 @@ application::InstanceArray Server::connectAll(const std::string& name, Option op
size_t
size
=
array
.
Size
();
// Allocate the array.
instances
.
allocat
e
(
size
);
instances
.
reserv
e
(
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
.
allocat
e
(
aliveInstancesCount
);
aliveInstances
.
reserv
e
(
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
++
;
}
}
...
...
Shervin Nourbakhsh
@nourbakhsh
mentioned in commit
46e44691
·
Apr 23, 2021
mentioned in commit
46e44691
mentioned in commit 46e44691a03808a23a464818487b0dd014a9c57e
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment