Added toString() method and search by string in lists.
git-svn-id: http://voip.null.ro/svn/yate@122 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
fc420d1d80
commit
16c96b1c98
|
@ -90,9 +90,7 @@ ObjList *ObjList::operator[](int index) const
|
|||
|
||||
ObjList *ObjList::find(const GenObject *obj) const
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Debugger debug("ObjList::find","(%p) [%p]",obj,this);
|
||||
#endif
|
||||
DDebug("ObjList::find(%p) [%p]",obj,this);
|
||||
const ObjList *n = this;
|
||||
while (n && (n->get() != obj))
|
||||
n = n->next();
|
||||
|
@ -100,6 +98,19 @@ ObjList *ObjList::find(const GenObject *obj) const
|
|||
return const_cast<ObjList *>(n);
|
||||
}
|
||||
|
||||
ObjList *ObjList::find(const String &str) const
|
||||
{
|
||||
DDebug("ObjList::find(\"%s\") [%p]",str.c_str(),this);
|
||||
const ObjList *n = this;
|
||||
while (n) {
|
||||
if (n->get() && str.matches(n->get()->toString()))
|
||||
break;
|
||||
n = n->next();
|
||||
}
|
||||
DDebug(DebugInfo,"ObjList::find returning %p",n);
|
||||
return const_cast<ObjList *>(n);
|
||||
}
|
||||
|
||||
GenObject *ObjList::set(const GenObject *obj, bool delold)
|
||||
{
|
||||
if (m_obj == obj)
|
||||
|
|
|
@ -136,6 +136,13 @@ void StringMatchPrivate::fixup()
|
|||
count = c;
|
||||
}
|
||||
|
||||
static String s_empty;
|
||||
|
||||
const String& String::empty()
|
||||
{
|
||||
return s_empty;
|
||||
}
|
||||
|
||||
String::String()
|
||||
: m_string(0), m_length(0), m_hash(0), m_matches(0)
|
||||
{
|
||||
|
@ -789,3 +796,18 @@ NamedString::NamedString(const char *name, const char *value)
|
|||
{
|
||||
DDebug(DebugAll,"NamedString::NamedString(\"%s\",\"%s\") [%p]",name,value,this);
|
||||
}
|
||||
|
||||
const String& GenObject::toString() const
|
||||
{
|
||||
return String::empty();
|
||||
}
|
||||
|
||||
const String& String::toString() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
const String& NamedString::toString() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
|
44
yatengine.h
44
yatengine.h
|
@ -151,7 +151,9 @@ bool Debug(const char *facility, int level, const char *format, ...) FORMAT_CHEC
|
|||
void Output(const char *format, ...) FORMAT_CHECK(1);
|
||||
|
||||
/**
|
||||
* An object that logs messages on creation and destruction
|
||||
* This class is used as an automatic variable that logs messages on creation
|
||||
* and destruction (when the instruction block is left or function returns)
|
||||
* @short An object that logs messages on creation and destruction
|
||||
*/
|
||||
class Debugger
|
||||
{
|
||||
|
@ -206,6 +208,8 @@ struct TokenDict {
|
|||
int value;
|
||||
};
|
||||
|
||||
class String;
|
||||
|
||||
/**
|
||||
* An object with just a public virtual destructor
|
||||
*/
|
||||
|
@ -222,6 +226,14 @@ public:
|
|||
*/
|
||||
virtual void destruct()
|
||||
{ delete this; }
|
||||
|
||||
/**
|
||||
* Get a string representation of this object
|
||||
* @return A reference to a String representing this object
|
||||
* which is either null, the object itself (for objects derived from
|
||||
* String) or some form of identification
|
||||
*/
|
||||
virtual const String& toString() const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -350,6 +362,13 @@ public:
|
|||
*/
|
||||
ObjList *find(const GenObject *obj) const;
|
||||
|
||||
/**
|
||||
* Get the item in the list that holds an object by String value
|
||||
* @param str String value (toString) of the object to search for
|
||||
* @return Pointer to the found item or NULL
|
||||
*/
|
||||
ObjList *find(const String &str) const;
|
||||
|
||||
/**
|
||||
* Insert an object at this point
|
||||
* @param obj Pointer to the object to insert
|
||||
|
@ -465,6 +484,11 @@ public:
|
|||
*/
|
||||
virtual ~String();
|
||||
|
||||
/**
|
||||
* A static null String
|
||||
*/
|
||||
static const String &empty();
|
||||
|
||||
/**
|
||||
* Get the value of the stored string.
|
||||
* @return The stored C string which may be NULL.
|
||||
|
@ -530,6 +554,12 @@ public:
|
|||
*/
|
||||
String& trimBlanks();
|
||||
|
||||
/**
|
||||
* Override GenObject's method to return this String
|
||||
* @return A reference to this String
|
||||
*/
|
||||
virtual const String& toString() const;
|
||||
|
||||
/**
|
||||
* Convert the string to an integer value.
|
||||
* @param defvalue Default to return if the string is not a number
|
||||
|
@ -767,11 +797,11 @@ public:
|
|||
* @param value String to check for match
|
||||
* @return True if matches, false otherwise
|
||||
*/
|
||||
virtual bool matches(const String &value)
|
||||
virtual bool matches(const String &value) const
|
||||
{ return operator==(value); }
|
||||
|
||||
/**
|
||||
* Checks if matches a regular expression
|
||||
* Checks if matches a regular expression and fill the match substrings
|
||||
* @param rexp Regular expression to check for match
|
||||
* @return True if matches, false otherwise
|
||||
*/
|
||||
|
@ -979,7 +1009,7 @@ public:
|
|||
* @param value String to check for match
|
||||
* @return True if matches, false otherwise
|
||||
*/
|
||||
virtual bool matches(const String &value)
|
||||
virtual bool matches(const String &value) const
|
||||
{ return matches(value.safe()); }
|
||||
|
||||
protected:
|
||||
|
@ -1015,6 +1045,12 @@ public:
|
|||
inline const String& name() const
|
||||
{ return m_name; }
|
||||
|
||||
/**
|
||||
* Get a string representation of this object
|
||||
* @return A reference to the name of this object
|
||||
*/
|
||||
virtual const String& toString() const;
|
||||
|
||||
/**
|
||||
* Value assignment operator
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue