Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
8565d36b
Commit
8565d36b
authored
19 years ago
by
jpbl
Browse files
Options
Downloads
Patches
Plain Diff
*** empty log message ***
parent
a587ca18
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
utilspp/singleton/LifetimeLibrary.cpp
+72
-0
72 additions, 0 deletions
utilspp/singleton/LifetimeLibrary.cpp
utilspp/singleton/PrivateMembers.cpp
+46
-0
46 additions, 0 deletions
utilspp/singleton/PrivateMembers.cpp
with
118 additions
and
0 deletions
utilspp/singleton/LifetimeLibrary.cpp
0 → 100644
+
72
−
0
View file @
8565d36b
#include
"SingletonHolder.hpp"
#include
"LifetimeLibrary.hpp"
utilspp
::
LifetimeLibraryImpl
::
LifetimeLibraryImpl
()
:
mTrackerArray
(
NULL
),
mNbElements
(
0
)
{}
utilspp
::
LifetimeLibraryImpl
::~
LifetimeLibraryImpl
()
{
terminate
();
}
void
utilspp
::
LifetimeLibraryImpl
::
add
(
utilspp
::
PrivateMembers
::
LifetimeTracker
*
tracker
)
{
utilspp
::
PrivateMembers
::
TrackerArray
newArray
=
static_cast
<
utilspp
::
PrivateMembers
::
TrackerArray
>
(
std
::
realloc
(
mTrackerArray
,
mNbElements
+
1
));
if
(
newArray
==
NULL
)
{
throw
std
::
bad_alloc
();
}
mTrackerArray
=
newArray
;
utilspp
::
PrivateMembers
::
TrackerArray
pos
=
std
::
upper_bound
(
mTrackerArray
,
mTrackerArray
+
mNbElements
,
tracker
,
&
utilspp
::
PrivateMembers
::
LifetimeTracker
::
compare
);
std
::
copy_backward
(
pos
,
mTrackerArray
+
mNbElements
,
mTrackerArray
+
mNbElements
+
1
);
*
pos
=
tracker
;
mNbElements
++
;
};
void
utilspp
::
LifetimeLibraryImpl
::
terminate
()
{
//The number of elements MUST always be equal or over zero.
assert
(
mNbElements
>=
0
);
while
(
mNbElements
>
0
)
{
//At this point the mTrackerArray MUST not be NULL.
assert
(
mTrackerArray
!=
NULL
);
//Pick the element at the top of the stack.
utilspp
::
PrivateMembers
::
LifetimeTracker
*
top
=
mTrackerArray
[
mNbElements
-
1
];
//Remove that object off the stack.
//Don't check errors-realloc with less memory, cause that can't fail.
mTrackerArray
=
static_cast
<
utilspp
::
PrivateMembers
::
TrackerArray
>
(
std
::
realloc
(
mTrackerArray
,
--
mNbElements
));
//Destroy the element.
delete
top
;
}
}
unsigned
int
utilspp
::
getLongevity
(
utilspp
::
LifetimeLibraryImpl
*
)
{
return
0
;
}
This diff is collapsed.
Click to expand it.
utilspp/singleton/PrivateMembers.cpp
0 → 100644
+
46
−
0
View file @
8565d36b
#include
<cstdlib>
#include
"PrivateMembers.hpp"
utilspp
::
PrivateMembers
::
TrackerArray
utilspp
::
PrivateMembers
::
mTrackerArray
=
NULL
;
int
utilspp
::
PrivateMembers
::
mNbElements
=
0
;
utilspp
::
PrivateMembers
::
LifetimeTracker
::
LifetimeTracker
(
unsigned
int
longevity
)
:
mLongevity
(
longevity
)
{}
utilspp
::
PrivateMembers
::
LifetimeTracker
::~
LifetimeTracker
()
{}
bool
utilspp
::
PrivateMembers
::
LifetimeTracker
::
compare
(
const
LifetimeTracker
*
l
,
const
LifetimeTracker
*
r
)
{
return
l
->
mLongevity
<
r
->
mLongevity
;
}
void
utilspp
::
PrivateMembers
::
atExitFunc
()
{
assert
((
mTrackerArray
!=
NULL
)
&&
(
mNbElements
>
0
));
//Pick the element at the top of the stack.
LifetimeTracker
*
top
=
mTrackerArray
[
mNbElements
-
1
];
//Remove that object off the stack.
//Don't check errors-realloc with less memory, cause that can't fail.
mTrackerArray
=
static_cast
<
utilspp
::
PrivateMembers
::
TrackerArray
>
(
std
::
realloc
(
mTrackerArray
,
--
mNbElements
));
//Destroy the element.
delete
top
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment