variable_watch: Store client data as pointers
The STL containers create extra copies which makes keeping track of the owner of the client data much messier.
This commit is contained in:
parent
1e0539cd2c
commit
fc7c3b4dc8
@ -37,21 +37,35 @@ cmVariableWatch::cmVariableWatch()
|
|||||||
|
|
||||||
cmVariableWatch::~cmVariableWatch()
|
cmVariableWatch::~cmVariableWatch()
|
||||||
{
|
{
|
||||||
|
cmVariableWatch::StringToVectorOfPairs::iterator svp_it;
|
||||||
|
|
||||||
|
for ( svp_it = this->WatchMap.begin();
|
||||||
|
svp_it != this->WatchMap.end(); ++svp_it )
|
||||||
|
{
|
||||||
|
cmVariableWatch::VectorOfPairs::iterator p_it;
|
||||||
|
|
||||||
|
for ( p_it = svp_it->second.begin();
|
||||||
|
p_it != svp_it->second.end(); ++p_it )
|
||||||
|
{
|
||||||
|
delete *p_it;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmVariableWatch::AddWatch(const std::string& variable,
|
void cmVariableWatch::AddWatch(const std::string& variable,
|
||||||
WatchMethod method, void* client_data /*=0*/)
|
WatchMethod method, void* client_data /*=0*/)
|
||||||
{
|
{
|
||||||
cmVariableWatch::Pair p;
|
cmVariableWatch::Pair* p = new cmVariableWatch::Pair;
|
||||||
p.Method = method;
|
p->Method = method;
|
||||||
p.ClientData = client_data;
|
p->ClientData = client_data;
|
||||||
cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
|
cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
|
||||||
cmVariableWatch::VectorOfPairs::size_type cc;
|
cmVariableWatch::VectorOfPairs::size_type cc;
|
||||||
for ( cc = 0; cc < vp->size(); cc ++ )
|
for ( cc = 0; cc < vp->size(); cc ++ )
|
||||||
{
|
{
|
||||||
cmVariableWatch::Pair* pair = &(*vp)[cc];
|
cmVariableWatch::Pair* pair = (*vp)[cc];
|
||||||
if ( pair->Method == method )
|
if ( pair->Method == method )
|
||||||
{
|
{
|
||||||
|
delete pair;
|
||||||
(*vp)[cc] = p;
|
(*vp)[cc] = p;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -66,8 +80,9 @@ void cmVariableWatch::RemoveWatch(const std::string& variable,
|
|||||||
cmVariableWatch::VectorOfPairs::iterator it;
|
cmVariableWatch::VectorOfPairs::iterator it;
|
||||||
for ( it = vp->begin(); it != vp->end(); ++it )
|
for ( it = vp->begin(); it != vp->end(); ++it )
|
||||||
{
|
{
|
||||||
if ( it->Method == method )
|
if ( (*it)->Method == method )
|
||||||
{
|
{
|
||||||
|
delete *it;
|
||||||
vp->erase(it);
|
vp->erase(it);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -87,7 +102,7 @@ void cmVariableWatch::VariableAccessed(const std::string& variable,
|
|||||||
cmVariableWatch::VectorOfPairs::const_iterator it;
|
cmVariableWatch::VectorOfPairs::const_iterator it;
|
||||||
for ( it = vp->begin(); it != vp->end(); it ++ )
|
for ( it = vp->begin(); it != vp->end(); it ++ )
|
||||||
{
|
{
|
||||||
it->Method(variable, access_type, it->ClientData,
|
(*it)->Method(variable, access_type, (*it)->ClientData,
|
||||||
newValue, mf);
|
newValue, mf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ protected:
|
|||||||
Pair() : Method(0), ClientData(0) {}
|
Pair() : Method(0), ClientData(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector< Pair > VectorOfPairs;
|
typedef std::vector< Pair* > VectorOfPairs;
|
||||||
typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs;
|
typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs;
|
||||||
|
|
||||||
StringToVectorOfPairs WatchMap;
|
StringToVectorOfPairs WatchMap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user