[svn] commit: r126 - in /experiments/jelte-configuration: data.cc data.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Oct 27 21:51:59 UTC 2009
Author: jelte
Date: Tue Oct 27 21:51:59 2009
New Revision: 126
Log:
second find function (returns false if for whatever reason not found, stores result in given reference)
need to think about naming
Modified:
experiments/jelte-configuration/data.cc
experiments/jelte-configuration/data.h
Modified: experiments/jelte-configuration/data.cc
==============================================================================
--- experiments/jelte-configuration/data.cc (original)
+++ experiments/jelte-configuration/data.cc Tue Oct 27 21:51:59 2009
@@ -428,6 +428,21 @@
}
}
+bool
+MapElement::find(const std::string& id, ElementPtr& t) {
+ ElementPtr p;
+ try {
+ p = find(id);
+ if (p) {
+ t = p;
+ return true;
+ }
+ } catch (TypeError e) {
+ // ignore
+ }
+ return false;
+}
+
int main(int argc, char **argv)
{
@@ -464,6 +479,18 @@
exit(0);
}
cout << "find aaa/bbb/ccc: " << e->find("aaa/bbb/ccc") << endl;
+
+ ElementPtr founde;
+ if (e->find("aaa/bbb", founde)) {
+ cout << "found aaa/bbb: " << founde << endl;
+ } else {
+ cout << "aaa/bbb not found" << endl;
+ }
+ if (e->find("aaa/ccc", founde)) {
+ cout << "found aaa/ccc: " << founde << endl;
+ } else {
+ cout << "aaa/ccc not found" << endl;
+ }
//cout << "part: " << e->get("test")->str() << endl;
/*
int i;
Modified: experiments/jelte-configuration/data.h
==============================================================================
--- experiments/jelte-configuration/data.h (original)
+++ experiments/jelte-configuration/data.h Tue Oct 27 21:51:59 2009
@@ -74,6 +74,7 @@
virtual void set(const std::string& name, ElementPtr element) { throw TypeError(); };
virtual void remove(const std::string& name) { throw TypeError(); };
virtual ElementPtr find(const std::string& identifier) { throw TypeError(); };
+ virtual bool find(const std::string& id, ElementPtr& t) { return false; };
//
// the _value() functions return false if the given reference
@@ -179,7 +180,17 @@
void set(const std::string& s, ElementPtr p) { m[s] = p; };
std::string str();
std::string str_xml(size_t prefix = 0);
+ // we should name the two finds better...
+ // find the element at id; raises TypeError if one of the
+ // elements at path except the one we're looking for is not a
+ // mapelement.
+ // returns an empty element if the item could not be found
ElementPtr find(const std::string& id);
+ // find the Element at 'id', and store the element pointer in t
+ // returns true if found, or false if not found (either because
+ // it doesnt exist or one of the elements in the path is not
+ // a MapElement)
+ bool find(const std::string& id, ElementPtr& t);
};
} }
More information about the bind10-changes
mailing list