[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] gvars3 gvars3/GUI.h src/GUI.cc
From: |
Georg Klein |
Subject: |
[libcvd-members] gvars3 gvars3/GUI.h src/GUI.cc |
Date: |
Tue, 13 Feb 2007 00:22:03 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: gvars3
Changes by: Georg Klein <georgklein> 07/02/13 00:22:03
Modified files:
gvars3 : GUI.h
src : GUI.cc
Log message:
Finer-grained UnRegisterCommand(): only remove *thisptr's commands.
Also: UnRegisterAllCommands(void* thisptr): remove all this class's
commands.
Goes nicely in your class destructor.
Also some 64-bit string handling cleanups.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gvars3/gvars3/GUI.h?cvsroot=libcvd&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gvars3/src/GUI.cc?cvsroot=libcvd&r1=1.12&r2=1.13
Patches:
Index: gvars3/GUI.h
===================================================================
RCS file: /cvsroot/libcvd/gvars3/gvars3/GUI.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- gvars3/GUI.h 14 Apr 2006 12:14:59 -0000 1.4
+++ gvars3/GUI.h 13 Feb 2007 00:22:03 -0000 1.5
@@ -46,6 +46,8 @@
GUI(GVars2*);//Dummy gvars2
void RegisterCommand(std::string sCommandName, GUICallbackProc
callback, void* thisptr=NULL);
+ void UnRegisterAllCommands(void* thisptr);
+ void UnRegisterCommand(std::string sCommandName, void* thisptr);
void UnRegisterCommand(std::string sCommandName);
void ParseLine(std::string s, bool bSilentFailure = false);
void ParseStream(std::istream& is);
Index: src/GUI.cc
===================================================================
RCS file: /cvsroot/libcvd/gvars3/src/GUI.cc,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- src/GUI.cc 11 Feb 2007 00:09:14 -0000 1.12
+++ src/GUI.cc 13 Feb 2007 00:22:03 -0000 1.13
@@ -41,7 +41,7 @@
bool setvar(string s)
{
//Execution failed. Maybe its an assignment.
- int n;
+ string::size_type n;
n=s.find("=");
if(n != string::npos)
@@ -50,7 +50,7 @@
string val = s.substr(n+1);
//Strip whitespace from around var;
- int s=0, e = var.length()-1;
+ string::size_type s=0, e = var.length()-1;
for(; isspace(var[s]) && s < var.length(); s++);
for(; isspace(var[e]) && e >=0; e--);
@@ -132,6 +132,19 @@
mmCallBackMap.erase(sCommandName);
};
+void GUI::UnRegisterAllCommands(void* thisptr)
+{
+ for(map<string, CallbackVector>::iterator i=mmCallBackMap.begin();
i!=mmCallBackMap.end(); i++)
+ UnRegisterCommand(i->first, thisptr);
+};
+
+void GUI::UnRegisterCommand(string sCommandName, void* thisptr)
+{
+ CallbackVector &cbv = mmCallBackMap[sCommandName];
+ for(int i = cbv.size() - 1; i>=0; i--)
+ if(cbv[i].thisptr == thisptr)
+ cbv.erase(cbv.begin() + i);
+};
void GUI::RegisterCommand(string sCommandName, GUICallbackProc callback, void*
thisptr)
{
@@ -167,6 +180,8 @@
//Make a copy of this callback vector, since the command might call
Unregister.
CallbackVector cbv = mmCallBackMap[sCommand];
+ if(cbv.size() == 0)
+ return false;
for(CallbackVector::iterator i = cbv.begin(); i<cbv.end();i++)
i->cbp(i->thisptr, sCommand, sParams);
@@ -207,10 +222,10 @@
-int FindCloseBrace(const string& s, int start, char op, char cl)
+string::size_type FindCloseBrace(const string& s, string::size_type start,
char op, char cl)
{
- int open=1;
- int i;
+ string::size_type open=1;
+ string::size_type i;
for(i=start+1; i < s.size() ; i++)
{
@@ -254,9 +269,9 @@
// (Without double braces, the it would try to make two buttons!)
{ // Brace expansion wrapper follows:
- int nOpenBracePos = s.find("{");
+ string::size_type nOpenBracePos = s.find("{");
//int nCloseBracePos = s.rfind("}");
- int nCloseBracePos = FindCloseBrace(s, nOpenBracePos, '{', '}');
+ string::size_type nCloseBracePos = FindCloseBrace(s, nOpenBracePos, '{',
'}');
if( (nOpenBracePos !=s.npos) &&
(nCloseBracePos !=s.npos) &&
(nCloseBracePos > nOpenBracePos))
@@ -266,7 +281,7 @@
string sVarName =
s.substr(nOpenBracePos+1,nCloseBracePos-nOpenBracePos-1);
string sEnd = s.substr(nCloseBracePos+1);
- int nLength = sVarName.size(); // Check if it's a double brace:
{{foo}} in which case remove one pair, but don't expand.
+ string::size_type nLength = sVarName.size(); // Check if it's a
double brace: {{foo}} in which case remove one pair, but don't expand.
bool bIsDoubleQuoted = false;
if(nLength>2)
@@ -281,7 +296,7 @@
//ER: look at the end of the string for '$'s to also perform
the substitution
vector<string> chopped;
string end;
- int dollarpos=-1, lastpos=0;
+ string::size_type dollarpos=-1, lastpos=0;
while((dollarpos = sEnd.find("$", dollarpos+1)) != s.npos)
{
chopped.push_back(sEnd.substr(lastpos, dollarpos -
lastpos));
@@ -315,9 +330,9 @@
{ // Round expansion wrapper follows:
- int nOpenBracePos = s.find("(");
+ string::size_type nOpenBracePos = s.find("(");
//int nCloseBracePos = s.rfind(")");
- int nCloseBracePos = FindCloseBrace(s, nOpenBracePos, '(', ')');
+ string::size_type nCloseBracePos = FindCloseBrace(s,
nOpenBracePos, '(', ')');
// cerr << "((( " << nOpenBracePos << " " << nCloseBracePos <<
endl;
@@ -332,7 +347,7 @@
//cerr << "varname = --" << sVarName << "--\n";
- int nLength = sVarName.size(); // Check if it's a
double brace: {{foo}} in which case remove one pair, but don't expand.
+ string::size_type nLength = sVarName.size(); // Check
if it's a double brace: {{foo}} in which case remove one pair, but don't expand.
bool bIsDoubleQuoted = false;
if(nLength>2)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] gvars3 gvars3/GUI.h src/GUI.cc,
Georg Klein <=