Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gauthier Quesnel
bits
Commits
41017a06
Commit
41017a06
authored
Apr 06, 2019
by
Gauthier Quesnel
Browse files
next14
parent
5bd921ce
Pipeline
#2314
failed with stage
in 1 minute and 7 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/bits/allocator.hpp
View file @
41017a06
...
...
@@ -11,6 +11,34 @@
namespace
bits
{
class
allocator_malloc
{
public:
allocator_malloc
()
=
default
;
allocator_malloc
(
const
allocator_malloc
&
)
=
default
;
allocator_malloc
&
operator
=
(
const
allocator_malloc
&
)
=
default
;
bool
operator
==
(
const
allocator_malloc
&
)
{
return
true
;
}
bool
operator
!=
(
const
allocator_malloc
&
)
{
return
false
;
}
void
*
allocate
(
size_t
n
,
int
/*flags*/
=
0
)
{
return
malloc
(
n
);
}
void
deallocate
(
void
*
p
,
size_t
/*n*/
)
{
free
(
p
);
}
};
template
<
class
T
,
std
::
size_t
capacity
=
1024
>
class
fixed_memory_allocator
{
...
...
include/bits/data-array.hpp
View file @
41017a06
...
...
@@ -197,6 +197,8 @@ struct data_array
bool
full
()
const
noexcept
;
int
size
()
const
noexcept
;
item
*
items
=
nullptr
;
// items vector.
int
max_size
=
0
;
// total size
int
max_used
=
0
;
// highest index ever alloced
...
...
@@ -218,7 +220,7 @@ data_array<T, Identifier>::init(int capacity_)
{
clear
();
if
(
capacity_
<
0
||
capacity_
>
size
<
ID
>
())
if
(
capacity_
<
0
||
capacity_
>
bits
::
size
<
ID
>
())
return
false
;
items
=
new
item
[
capacity_
*
sizeof
(
item
)];
...
...
@@ -300,11 +302,11 @@ data_array<T, Identifier>::alloc()
Do_alloc
<
T
,
Identifier
>
(
items
[
new_index
].
item
,
std
::
is_trivial
<
T
>
());
std
::
printf
(
"new index: %d next key: %u and ID: %lu
\n
"
,
new_index
,
ne
xt_key
,
static_cast
<
long
unsigned
int
>
(
make_id
<
Identifier
>
(
next_key
,
new_index
)));
std
::
printf
(
"new index: %d next key: %u and ID: %lu
\n
"
,
ne
w_index
,
next_key
,
static_cast
<
long
unsigned
int
>
(
make_id
<
Identifier
>
(
next_key
,
new_index
)));
items
[
new_index
].
id
=
make_id
<
Identifier
>
(
next_key
,
new_index
);
next_key
=
make_next_key
<
Identifier
>
(
next_key
);
...
...
@@ -429,6 +431,13 @@ data_array<T, Identifier>::full() const noexcept
return
free_head
==
-
1
&&
max_used
==
capacity
;
}
template
<
typename
T
,
typename
Identifier
>
int
data_array
<
T
,
Identifier
>::
size
()
const
noexcept
{
return
max_size
;
}
}
// bits
#endif // ORG_VLEPROJECT_BITS_DATAARRAY_HPP
include/bits/linker.hpp
View file @
41017a06
...
...
@@ -53,14 +53,23 @@ public:
bits_expects
(
size
>
0
);
}
void
emplace
(
const
identifier_type
id
,
const
referenced_type
value
)
noexcept
void
emplace
(
const
identifier_type
id
,
const
referenced_type
value
)
noexcept
{
bits_expects
(
bits
::
valid
(
id
));
items
[
bits
::
get_index
(
id
)]
=
value
;
}
template
<
typename
DataArray
>
typename
DataArray
::
value_type
*
try_to_get
(
DataArray
*
array
,
identifier_type
id
)
const
noexcept
{
bits_expects
(
bits
::
valid
(
id
));
return
array
->
try_to_get
(
items
[
bits
::
get_index
(
id
)]);
}
referenced_type
operator
[](
const
identifier_type
id
)
const
noexcept
{
bits_expects
(
bits
::
valid
(
id
));
...
...
@@ -103,8 +112,7 @@ struct multi_linker_node
template
<
typename
Identifier
,
typename
Referenced
,
typename
IdentifierAllocator
=
std
::
allocator
<
int
>,
typename
NodeAllocator
=
std
::
allocator
<
multi_linker_node
<
Referenced
>>>
typename
NodeAllocator
=
std
::
allocator
<
multi_linker_node
<
Referenced
>>>
class
multi_linker
{
public:
...
...
@@ -143,9 +151,7 @@ private:
iterator
(
const
iterator
&
)
noexcept
=
default
;
iterator
&
operator
=
(
const
iterator
&
)
noexcept
=
default
;
iterator
(
this_type
*
list_
,
DataArray
*
dataarray_
,
int
elem_
)
noexcept
iterator
(
this_type
*
list_
,
DataArray
*
dataarray_
,
int
elem_
)
noexcept
:
list
(
list_
)
,
dataarray
(
dataarray_
)
,
elem
(
elem_
)
...
...
test/vpz.cpp
View file @
41017a06
...
...
@@ -319,10 +319,89 @@ struct SimDynamics
//
unsigned
dynamics_id
;
unsigned
state
_id
;
ID
model
_id
;
bool
debug
;
};
struct
Ball
{
double
start
(
double
t
)
{
return
t
;
}
double
transition
(
double
t
)
{
return
t
;
}
void
output
()
{}
};
/* to be declare in model.cpp in DECLARE_DYNAMICS for example */
struct
data_array_wrapper
{
bits
::
data_array
<
Ball
,
ID
>
ball_models
;
ID
alloc
()
{
auto
&
mdl
=
ball_models
.
alloc
();
return
ball_models
.
get_id
(
mdl
);
}
void
free
(
ID
model
)
{
ball_models
.
free
(
model
);
}
int
size
()
const
noexcept
{
return
ball_models
.
size
();
}
double
start
(
ID
model
,
double
time
)
{
auto
*
mdl
=
ball_models
.
try_to_get
(
model
);
bits_assert
(
mdl
);
return
mdl
->
start
(
time
);
}
double
transition
(
ID
model
,
double
time
)
{
auto
*
mdl
=
ball_models
.
try_to_get
(
model
);
bits_assert
(
mdl
);
return
mdl
->
transition
(
time
);
}
void
output
(
ID
model
)
{
auto
*
mdl
=
ball_models
.
try_to_get
(
model
);
bits_assert
(
mdl
);
return
mdl
->
output
();
}
};
struct
AllDynamics
{
std
::
vector
<
data_array_wrapper
>
all_dynamics
;
ID
alloc
(
unsigned
dynamics_id
)
{
bits_expects
(
dynamics_id
<
all_dynamics
.
size
());
return
all_dynamics
[
dynamics_id
].
alloc
();
}
void
free
(
unsigned
dynamics_id
,
ID
model_id
)
{
bits_expects
(
dynamics_id
<
all_dynamics
.
size
());
bits_expects
(
model_id
<
all_dynamics
[
dynamics_id
].
size
());
all_dynamics
[
dynamics_id
].
free
(
model_id
);
}
};
struct
SimElement
{
double
tn
;
...
...
@@ -529,11 +608,10 @@ struct Vpz
void
write
(
FILE
&
f
)
{
fprintf
(
&
f
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
"
"<!DOCTYPE vle_project PUBLIC
\"
-//VLE TEAM//DTD Strict // EN
\"
"
"
\"
https://www.vle-project.org/vle-1.1.0.dtd
\"
>
\n
"
);
fprintf
(
&
f
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
"
"<!DOCTYPE vle_project PUBLIC
\"
-//VLE TEAM//DTD Strict // EN
\"
"
"
\"
https://www.vle-project.org/vle-1.1.0.dtd
\"
>
\n
"
);
{
write_dynamics
(
f
);
...
...
@@ -811,13 +889,13 @@ struct Vpz
real64
.
free
(
*
x
);
}
case
value_type
::
vec2_32
:
{
auto
*
x
=
vec2_32
.
try_to_get
(
named_value_links
[
named_values
.
get_id
(
value
)]);
auto
*
x
=
vec2_32
.
try_to_get
(
named_value_links
[
named_values
.
get_id
(
value
)]);
vec2_32
.
free
(
*
x
);
}
case
value_type
::
vec3_32
:
{
auto
*
x
=
vec3_32
.
try_to_get
(
named_value_links
[
named_values
.
get_id
(
value
)]);
auto
*
x
=
vec3_32
.
try_to_get
(
named_value_links
[
named_values
.
get_id
(
value
)]);
vec3_32
.
free
(
*
x
);
}
case
value_type
::
none
:
...
...
@@ -1006,7 +1084,7 @@ struct Vpz
}
// vle
int
main
(
int
/* argc */
,
char
*
/* argv */
[])
main
(
int
/* argc */
,
char
*
/* argv */
[])
{
std
::
cout
<<
"ID: get_max_key: "
<<
bits
::
get_max_key
<
vle
::
ID
>
()
<<
'\n'
;
...
...
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