NamedObject.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 $Header$
00004 
00005 */
00006 
00007 #include "pcrecpp.h"
00008 #include "Error.h"
00009 #include "Core.h"
00010 
00011 #include "NamedObject.h"
00012 
00013 using namespace pcrecpp;
00014 
00015 // Public methods.
00016 
00017 NamedObject::NamedObject(const String &name, const String &manual) :
00018   Object(),
00019   _name(name),
00020   _manual(manual)
00021 {
00022 }
00023 
00024 NamedObject::~NamedObject()
00025 {
00026 }
00027 
00028 int NamedObject::get(const String &name, NamedObject **obj, const bool ignoreCase)
00029 {
00030   if (!obj)
00031     return ERROR(MSG_NULL_POINTER);
00032 
00033   if (name.empty()) {
00034     *obj = NULL;
00035     return ERROR(MSG_OBJECT_INVALID_NAME, CSTRING(name));
00036   }
00037 
00038   Object::ObjectList::const_iterator i = Object::_objects.begin();
00039   Object::ObjectList::const_iterator e = Object::_objects.end();
00040   NamedObject *nobj;
00041 
00042   *obj = NULL;
00043   while (i != e) {
00044     if ((nobj = queryInterface<NamedObject>(i->second)))
00045       if (nobj->name().equals(name, ignoreCase)) {
00046         *obj = nobj;
00047         break;
00048       }
00049     ++i;
00050   }
00051   return *obj ? OK : ERROR(MSG_NAMED_OBJECT_NOT_FOUND, CSTRING(name));
00052 }
00053 
00054 int NamedObject::manual(const String &name, String &manual, const bool ignoreCase)
00055 {
00056   Core::ServiceList::const_iterator f = Core::_services.find(name);
00057 
00058   if (f != Core::_services.end()) {
00059     manual = f->second.manual();
00060     return OK;
00061   }
00062 
00063   NamedObject *obj;
00064   int res;
00065 
00066   if (FAILED(res = get(name, &obj, ignoreCase)))
00067     return ERROR_BACKTRACE(res);
00068 
00069   manual = obj->manual();
00070 
00071   return OK;
00072 }
00073 
00074 StringSet NamedObject::names()
00075 {
00076   StringSet list;
00077 
00078   {
00079     Object::ObjectList::const_iterator i = Object::_objects.begin();
00080     Object::ObjectList::const_iterator e = Object::_objects.end();
00081     NamedObject *obj;
00082 
00083     while (i != e) {
00084       if ((obj = queryInterface<NamedObject>(i->second)))
00085         list.insert(obj->name());
00086       ++i;
00087     }
00088   }
00089 
00090   {
00091     Core::ServiceList::const_iterator i = Core::_services.begin();
00092     Core::ServiceList::const_iterator e = Core::_services.end();
00093 
00094     while (i != e) {
00095       list.insert(i->first);
00096       ++i;
00097     }
00098   }
00099 
00100   return list;
00101 }
00102 
00103 StringSet NamedObject::apropos(const String &regExp, const bool ignoreCase)
00104 {
00105   StringSet list;
00106 
00107   if (regExp.empty())
00108     return list;
00109 
00110   RE re(regExp, RE_Options().set_caseless(ignoreCase).set_multiline(true));
00111 
00112   {
00113     Object::ObjectList::const_iterator i = Object::_objects.begin();
00114     Object::ObjectList::const_iterator e = Object::_objects.end();
00115     NamedObject *obj;
00116 
00117     while (i != e) {
00118       if ((obj = queryInterface<NamedObject>(i->second)))
00119         if (re.PartialMatch(RE::QuoteMeta(obj->name())) || re.PartialMatch(RE::QuoteMeta(obj->manual())))
00120           list.insert(obj->name());
00121       ++i;
00122     }
00123   }
00124 
00125   {
00126     Core::ServiceList::const_iterator i = Core::_services.begin();
00127     Core::ServiceList::const_iterator e = Core::_services.end();
00128 
00129     while (i != e) {
00130       if (re.PartialMatch(RE::QuoteMeta(i->first)) || re.PartialMatch(RE::QuoteMeta(i->second.manual())))
00131         list.insert(i->first);
00132       ++i;
00133     }
00134   }
00135 
00136   return list;
00137 }
00138 
00139 // Protected methods.
00140 
00141 int NamedObject::setName(const String &name)
00142 {
00143   _name = name;
00144   return OK;
00145 }

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1