1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// **********************************************************************
//
// Copyright (c) 2003
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// **********************************************************************
#include <Ice/UserExceptionFactoryManager.h>
#include <Ice/UserExceptionFactory.h>
#include <Ice/Functional.h>
#include <Ice/LocalException.h>
using namespace std;
using namespace Ice;
using namespace IceInternal;
void IceInternal::incRef(UserExceptionFactoryManager* p) { p->__incRef(); }
void IceInternal::decRef(UserExceptionFactoryManager* p) { p->__decRef(); }
void
IceInternal::UserExceptionFactoryManager::add(const UserExceptionFactoryPtr& factory, const string& id)
{
IceUtil::Mutex::Lock sync(*this);
if(_factoryMap.find(id) != _factoryMap.end())
{
AlreadyRegisteredException ex(__FILE__, __LINE__);
ex.kindOfObject = "user exception factory";
ex.id = id;
throw ex;
}
_factoryMapHint = _factoryMap.insert(_factoryMapHint, pair<const string, UserExceptionFactoryPtr>(id, factory));
}
void
IceInternal::UserExceptionFactoryManager::remove(const string& id)
{
UserExceptionFactoryPtr factory;
{
IceUtil::Mutex::Lock sync(*this);
map<string, UserExceptionFactoryPtr>::iterator p = _factoryMap.find(id);
if(p == _factoryMap.end())
{
NotRegisteredException ex(__FILE__, __LINE__);
ex.kindOfObject = "user exception factory";
ex.id = id;
throw ex;
}
factory = p->second;
_factoryMap.erase(p);
_factoryMapHint = _factoryMap.end();
}
factory->destroy();
}
UserExceptionFactoryPtr
IceInternal::UserExceptionFactoryManager::find(const string& id)
{
IceUtil::Mutex::Lock sync(*this);
if(_factoryMapHint != _factoryMap.end())
{
if(_factoryMapHint->first == id)
{
return _factoryMapHint->second;
}
}
map<string, UserExceptionFactoryPtr>::iterator p = _factoryMap.find(id);
if(p != _factoryMap.end())
{
_factoryMapHint = p;
return p->second;
}
else
{
return 0;
}
}
IceInternal::UserExceptionFactoryManager::UserExceptionFactoryManager() :
_factoryMapHint(_factoryMap.end())
{
}
void
IceInternal::UserExceptionFactoryManager::destroy()
{
IceUtil::Mutex::Lock sync(*this);
for_each(_factoryMap.begin(), _factoryMap.end(),
Ice::secondVoidMemFun<const string, UserExceptionFactory>(&UserExceptionFactory::destroy));
_factoryMap.clear();
_factoryMapHint = _factoryMap.end();
}
|