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
a3133d0a
Commit
a3133d0a
authored
19 years ago
by
jpbl
Browse files
Options
Downloads
Patches
Plain Diff
*** empty log message ***
parent
3ac53f0d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/gui/server/factory.cpp
+99
-0
99 additions, 0 deletions
src/gui/server/factory.cpp
with
99 additions
and
0 deletions
src/gui/server/factory.cpp
0 → 100644
+
99
−
0
View file @
a3133d0a
#include
<iostream>
#include
<map>
#include
<stdexcept>
#include
<string>
class
Request
{
public:
Request
()
{
std
::
cout
<<
"This is a Normal Request"
<<
std
::
endl
;
}
};
class
SpecificRequest
:
public
Request
{
public:
SpecificRequest
()
{
std
::
cout
<<
"This is a Specific Request"
<<
std
::
endl
;
}
};
class
RequestCreatorBase
{
public:
virtual
Request
*
create
()
=
0
;
virtual
RequestCreatorBase
*
clone
()
=
0
;
};
template
<
typename
T
>
class
RequestCreator
:
public
RequestCreatorBase
{
public:
virtual
Request
*
create
()
{
return
new
T
();
}
virtual
RequestCreatorBase
*
clone
()
{
return
new
RequestCreator
<
T
>
();
}
};
class
RequestFactory
{
public:
Request
*
create
(
const
std
::
string
&
requestname
)
{
std
::
map
<
std
::
string
,
RequestCreatorBase
*
>::
iterator
pos
=
mRequests
.
find
(
requestname
);
if
(
pos
==
mRequests
.
end
())
{
throw
std
::
runtime_error
(
"there's no request of that name"
);
}
return
pos
->
second
->
create
();
}
template
<
typename
T
>
void
registerRequest
(
const
std
::
string
&
requestname
)
{
std
::
map
<
std
::
string
,
RequestCreatorBase
*
>::
iterator
pos
=
mRequests
.
find
(
requestname
);
if
(
pos
!=
mRequests
.
end
())
{
delete
pos
->
second
;
mRequests
.
erase
(
pos
);
}
mRequests
.
insert
(
std
::
make_pair
(
requestname
,
new
RequestCreator
<
T
>
()));
}
private
:
std
::
map
<
std
::
string
,
RequestCreatorBase
*
>
mRequests
;
};
int
main
(
int
,
char
**
)
{
RequestFactory
factory
;
factory
.
registerRequest
<
Request
>
(
"requestsimple"
);
factory
.
registerRequest
<
SpecificRequest
>
(
"requestspecific"
);
std
::
cout
<<
"First one"
<<
std
::
endl
;
delete
factory
.
create
(
"requestsimple"
);
std
::
cout
<<
"Second one"
<<
std
::
endl
;
delete
factory
.
create
(
"requestspecific"
);
factory
.
registerRequest
<
SpecificRequest
>
(
"requestsimple"
);
std
::
cout
<<
"Third one"
<<
std
::
endl
;
delete
factory
.
create
(
"requestsimple"
);
return
0
;
}
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