Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
HexapodFMBO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Control System
Tango devices
Motion
Hexapods
HexapodFMBO
Commits
83eadbef
Commit
83eadbef
authored
May 29, 2015
by
Alain BUTEAU
Browse files
Options
Downloads
Patches
Plain Diff
JIRA TANGODEVIC-774
parent
01b3d1ba
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/CslHexapodApi/Observer.cpp
+72
-0
72 additions, 0 deletions
src/CslHexapodApi/Observer.cpp
src/CslHexapodApi/Observer.h
+73
-0
73 additions, 0 deletions
src/CslHexapodApi/Observer.h
with
145 additions
and
0 deletions
src/CslHexapodApi/Observer.cpp
0 → 100644
+
72
−
0
View file @
83eadbef
#include
"Observer.h"
namespace
CslHexapodApi
{
Observer
::~
Observer
()
{
//pour chaque objet observ,
//on lui dit qu'on doit supprimer l'Observer courant
const_iterator
ite
=
m_list
.
end
();
for
(
iterator
itb
=
m_list
.
begin
();
itb
!=
ite
;
++
itb
)
{
(
*
itb
)
->
DelObs
(
this
);
}
}
void
Observer
::
AddObs
(
Observable
*
obs
)
{
m_list
.
push_back
(
obs
);
}
void
Observer
::
DelObs
(
Observable
*
obs
)
{
//on enlve l'objet observ.
iterator
it
=
std
::
find
(
m_list
.
begin
(),
m_list
.
end
(),
obs
);
if
(
it
!=
m_list
.
end
())
m_list
.
erase
(
it
);
}
void
Observable
::
AddObs
(
Observer
*
obs
)
{
//on ajoute l'Observer notre liste
m_list
.
push_back
(
obs
);
//et on lui donne un nouvel objet observ.
obs
->
AddObs
(
this
);
}
void
Observable
::
DelObs
(
Observer
*
obs
)
{
//mme chose que dans Observer::DelObs
iterator
it
=
find
(
m_list
.
begin
(),
m_list
.
end
(),
obs
);
if
(
it
!=
m_list
.
end
())
m_list
.
erase
(
it
);
}
void
Observable
::
Notify
(
void
)
{
//on prvient chaque Observer que l'on change de valeur
iterator
itb
=
m_list
.
begin
();
const_iterator
ite
=
m_list
.
end
();
for
(;
itb
!=
ite
;
++
itb
)
{
(
*
itb
)
->
Update
();
}
}
Observable
::~
Observable
()
{
//mme chose qu'avec Observer::~Observer
std
::
cout
<<
"Observable::~Observable () <-"
<<
std
::
endl
;
iterator
itb
=
m_list
.
begin
();
const_iterator
ite
=
m_list
.
end
();
for
(;
itb
!=
ite
;
++
itb
)
{
(
*
itb
)
->
DelObs
(
this
);
}
}
}
//- namespace
This diff is collapsed.
Click to expand it.
src/CslHexapodApi/Observer.h
0 → 100644
+
73
−
0
View file @
83eadbef
#ifndef __OBSERVER_H
#define __OBSERVER_H
#include
<iostream>
#include
<list>
#include
<iterator>
#include
<algorithm>
#include
<string>
namespace
CslHexapodApi
{
typedef
double
Info
;
class
Observable
;
//*******************************************************************
//
// Class Observer : Read Pattern Description
//
// http://en.wikipedia.org/wiki/Observer_pattern
//
//*******************************************************************
class
Observer
{
protected:
//- ce n'est pas necessaire pour nous
std
::
list
<
Observable
*>
m_list
;
typedef
std
::
list
<
Observable
*>::
iterator
iterator
;
typedef
std
::
list
<
Observable
*>::
const_iterator
const_iterator
;
virtual
~
Observer
()
=
0
;
public:
Observer
()
{
};
virtual
void
Update
()
=
0
;
void
AddObs
(
Observable
*
obs
);
void
DelObs
(
Observable
*
obs
);
};
//*******************************************************************
//
// Class Observable : Read Pattern Description
//
// http://en.wikipedia.org/wiki/Observer_pattern
//
//*******************************************************************
class
Observable
{
std
::
list
<
Observer
*>
m_list
;
typedef
std
::
list
<
Observer
*>::
iterator
iterator
;
typedef
std
::
list
<
Observer
*>::
const_iterator
const_iterator
;
public:
Observable
()
{
};
void
AddObs
(
Observer
*
obs
);
void
DelObs
(
Observer
*
obs
);
virtual
~
Observable
();
protected
:
void
Notify
(
void
);
private
:
};
}
//- namespace
#endif //- __OBSERVER_H
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