WvStreams
Public Types | Public Member Functions | Protected Member Functions | List of all members
UniFastRegetGen Class Referenceabstract

A lightwight but slightly dangerous variant of UniCacheGen. More...

#include <unifastregetgen.h>

Inheritance diagram for UniFastRegetGen:
Inheritance graph
[legend]

Public Types

typedef ::UniListIter ListIter
 An iterator over a constant list of keys (see below)
 

Public Member Functions

 UniFastRegetGen (IUniConfGen *_inner)
 
virtual WvString get (const UniConfKey &key)
 Fetches a string value for a key from the registry. More...
 
virtual bool exists (const UniConfKey &key)
 Without fetching its value, returns true if a key exists. More...
 
virtual bool haschildren (const UniConfKey &key)
 Returns true if a key has children. More...
 
IUniConfGeninner () const
 Returns the inner generator.
 
virtual bool keymap (const UniConfKey &unmapped_key, UniConfKey &mapped_key)
 A mapping function for filters that remap one keyspace onto another. More...
 
virtual bool reversekeymap (const UniConfKey &mapped_key, UniConfKey &unmapped_key)
 A mapping function for filters that unmap a keyspace. More...
 
virtual void commit ()
 Commits any changes. More...
 
virtual bool refresh ()
 Refreshes information about a key recursively. More...
 
virtual void flush_buffers ()
 Flushes any commitment/notification buffers . More...
 
virtual void prefetch (const UniConfKey &key, bool recursive)
 Indicate that we will eventually be interested in doing get(), haschildren(), or other "get-like" operations on a particular key or tree of keys. More...
 
virtual void set (const UniConfKey &key, WvStringParm value)
 Stores a string value for a key into the registry. More...
 
virtual void setv (const UniConfPairList &pairs)
 Stores multiple key-value pairs into the registry. More...
 
virtual bool isok ()
 Determines if the generator is usable and working properly. More...
 
virtual Iteriterator (const UniConfKey &key)
 Returns an iterator over the children of the specified key. More...
 
virtual Iterrecursiveiterator (const UniConfKey &key)
 Like iterator(), but the returned iterator is recursive, that is, it will return children of the immediate children, not just the immediate children themselves. More...
 
virtual void add_callback (void *cookie, const UniConfGenCallback &callback)
 Adds a callback for change notification. More...
 
virtual void del_callback (void *cookie)
 Removes a callback for change notification.
 
void dispatch_delta (const UniConfKey &key, WvStringParm value)
 Immediately sends notification that a key has possibly changed. More...
 
void hold_delta ()
 Pauses notifications until matched with a call to unhold_delta(). More...
 
void unhold_delta ()
 Resumes notifications when each hold_delta() has been matched. More...
 
void clear_delta ()
 Clears the list of pending notifications without sending them. More...
 
void flush_delta ()
 Flushes the list of pending notifications by sending them. More...
 
void delta (const UniConfKey &key, WvStringParm value)
 Call this when a key's value or children have possibly changed. More...
 
virtual int str2int (WvStringParm s, int defvalue) const
 Converts a string to an integer. More...
 
virtual unsigned int addRef ()=0
 Indicate you are using this object. More...
 
virtual unsigned int release ()=0
 Indicate that you are finished using this object. More...
 
virtual IObjectgetInterface (const UUID &)=0
 Returns the requested XPLC interface. More...
 
virtual IWeakRefgetWeakRef ()=0
 Return a weak reference to this object. More...
 

Protected Member Functions

virtual void gencallback (const UniConfKey &key, WvStringParm value)
 Called by inner generator when a key changes. More...
 
void setinner (IUniConfGen *inner)
 Rebinds the inner generator and prepares its callback. More...
 
void setv_naive (const UniConfPairList &pairs)
 

Detailed Description

A lightwight but slightly dangerous variant of UniCacheGen.

UniCacheGen tries to make all operations asynchronous, by storing a local cache of absolutely everything in the entire UniConf subtree that it wraps. UniFastRegetGen, on the other hand, tries to be helpful without actually wasting too much memory, but leaves many operations still synchronous.

This is useful for programs that may need to access a variety of different UniConf keys, don't need to worry too much about blocking occasionally while waiting for UniConf, but would like most get() operations to be fast.

UniFastRegetGen makes subsequent get() operations on a key, after the first one, be guaranteed asynchronous. It caches keys which you've previously done get() on, and accepts notifications for those keys (so the value is always up to date, but you'll never have to wait for it again). It makes no attempt to optimize any other operations, including set(), refresh/commit, or iterate. It ignores notifications for any keys you haven't explicitly done get() on in the past.

Definition at line 33 of file unifastregetgen.h.

Member Function Documentation

◆ get()

WvString UniFastRegetGen::get ( const UniConfKey key)
virtual

Fetches a string value for a key from the registry.

If the key doesn't exist, the return value has .isnull() == true.

Reimplemented from UniFilterGen.

Definition at line 53 of file unifastregetgen.cc.

References UniConfTree< Sub >::find(), UniFilterGen::get(), UniConfKey::hastrailingslash(), WvFastString::isnull(), UniConfKey::last(), UniConfKey::removelast(), and UniConfValueTree::value().

Referenced by exists().

◆ exists()

bool UniFastRegetGen::exists ( const UniConfKey key)
virtual

Without fetching its value, returns true if a key exists.

This is provided because it is often more efficient to test existance than to actually retrieve the value.

The default implementation returns !get(key).isnull().

Reimplemented from UniFilterGen.

Definition at line 84 of file unifastregetgen.cc.

References get(), and WvFastString::isnull().

◆ haschildren()

bool UniFastRegetGen::haschildren ( const UniConfKey key)
virtual

Returns true if a key has children.

This is provided because it is often more efficient to test existance than to actually retrieve the keys.

The default implementation uses the iterator returned by iterator() to test whether the child has any keys. Subclasses are strongly encouraged to provide a better implementation.

Reimplemented from UniFilterGen.

Definition at line 92 of file unifastregetgen.cc.

References UniConfTree< Sub >::find(), UniFilterGen::haschildren(), WvFastString::isnull(), and UniConfValueTree::value().

◆ gencallback()

void UniFastRegetGen::gencallback ( const UniConfKey key,
WvStringParm  value 
)
protectedvirtual

Called by inner generator when a key changes.

The default implementation calls delta(key).

Reimplemented from UniFilterGen.

Definition at line 41 of file unifastregetgen.cc.

References UniConfTree< Sub >::find(), UniFilterGen::gencallback(), and UniConfValueTree::setvalue().

◆ setinner()

void UniFilterGen::setinner ( IUniConfGen inner)
protectedinherited

Rebinds the inner generator and prepares its callback.

The previous generator is NOT destroyed.

Definition at line 26 of file unifiltergen.cc.

References IUniConfGen::add_callback(), IUniConfGen::del_callback(), UniFilterGen::gencallback(), and UniFilterGen::inner().

◆ keymap()

bool UniFilterGen::keymap ( const UniConfKey unmapped_key,
UniConfKey mapped_key 
)
virtualinherited

A mapping function for filters that remap one keyspace onto another.

The default implementation of the various functions (get, set, exists, etc) run their keys through this function before forwarding the requests on to the inner generator.

The default implementation of this function doesn't change the key.

Returns true if the key can be mapped, else false.

Reimplemented in UniDefGen, UniSubtreeGen, and UniAutoMountGen.

Definition at line 37 of file unifiltergen.cc.

Referenced by UniFilterGen::exists(), UniFilterGen::get(), UniFilterGen::haschildren(), UniFilterGen::iterator(), UniAutoMountGen::keymap(), UniFilterGen::prefetch(), UniFilterGen::recursiveiterator(), and UniFilterGen::set().

◆ reversekeymap()

bool UniFilterGen::reversekeymap ( const UniConfKey mapped_key,
UniConfKey unmapped_key 
)
virtualinherited

A mapping function for filters that unmap a keyspace.

The default implementation of this function doesn't change the key.

Returns true if the key can be reverse-mapped, else false.

Reimplemented in UniSubtreeGen.

Definition at line 44 of file unifiltergen.cc.

Referenced by UniFilterGen::gencallback().

◆ commit()

void UniFilterGen::commit ( )
virtualinherited

Commits any changes.

The default implementation does nothing.

Reimplemented from UniConfGen.

Reimplemented in UniRetryGen, UniSecureGen, UniSlowGen, and UniBachelorGen.

Definition at line 52 of file unifiltergen.cc.

References IUniConfGen::commit().

Referenced by UniSlowGen::commit(), UniSecureGen::commit(), and UniRetryGen::commit().

◆ refresh()

bool UniFilterGen::refresh ( )
virtualinherited

Refreshes information about a key recursively.

May discard uncommitted data.

The default implementation always returns true.

Reimplemented from UniConfGen.

Reimplemented in UniRetryGen, UniSecureGen, UniSlowGen, and UniBachelorGen.

Definition at line 59 of file unifiltergen.cc.

References IUniConfGen::refresh().

Referenced by UniSlowGen::refresh(), UniSecureGen::refresh(), and UniRetryGen::refresh().

◆ flush_buffers()

void UniFilterGen::flush_buffers ( )
virtualinherited

Flushes any commitment/notification buffers .

The default implementation always returns true. NOTE: This method should be 'protected'

Implements UniConfGen.

Reimplemented in UniPermGen, UniRetryGen, UniDefGen, UniSecureGen, UniSlowGen, and UniReadOnlyGen.

Definition at line 86 of file unifiltergen.cc.

References IUniConfGen::flush_buffers().

◆ prefetch()

void UniFilterGen::prefetch ( const UniConfKey key,
bool  recursive 
)
virtualinherited

Indicate that we will eventually be interested in doing get(), haschildren(), or other "get-like" operations on a particular key or tree of keys.

The generator may be able to speed up these operations by, say, caching them in advance.

This function is not allowed to do blocking operations. It is allowed to do nothing at all, however, and then get() might block later.

Reimplemented from UniConfGen.

Reimplemented in UniRetryGen.

Definition at line 68 of file unifiltergen.cc.

References UniFilterGen::keymap(), and IUniConfGen::prefetch().

Referenced by UniRetryGen::prefetch().

◆ set()

void UniFilterGen::set ( const UniConfKey key,
WvStringParm  value 
)
virtualinherited

Stores a string value for a key into the registry.

If the value is WvString::null, the key is deleted.

Implements UniConfGen.

Reimplemented in UniRetryGen, UniDefGen, UniSecureGen, and UniReadOnlyGen.

Definition at line 93 of file unifiltergen.cc.

References UniFilterGen::keymap(), and IUniConfGen::set().

Referenced by UniSecureGen::set(), and UniRetryGen::set().

◆ setv()

void UniFilterGen::setv ( const UniConfPairList &  pairs)
virtualinherited

Stores multiple key-value pairs into the registry.

If the value is WvString::null, the key is deleted.

Implements UniConfGen.

Definition at line 101 of file unifiltergen.cc.

References IUniConfGen::setv().

◆ isok()

bool UniFilterGen::isok ( )
virtualinherited

Determines if the generator is usable and working properly.

The default implementation always returns true.

Reimplemented from UniConfGen.

Reimplemented in UniRetryGen.

Definition at line 128 of file unifiltergen.cc.

References IUniConfGen::isok().

Referenced by UniRetryGen::commit(), UniRetryGen::exists(), UniRetryGen::get(), UniRetryGen::haschildren(), UniRetryGen::isok(), UniRetryGen::iterator(), UniRetryGen::prefetch(), UniRetryGen::refresh(), and UniRetryGen::set().

◆ iterator()

UniConfGen::Iter * UniFilterGen::iterator ( const UniConfKey key)
virtualinherited

Returns an iterator over the children of the specified key.

May return NULL or an empty iterator if the key has no children.

The caller takes ownership of the returned iterator and is responsible for deleting it when finished.

Implements UniConfGen.

Reimplemented in UniRetryGen, UniSecureGen, and UniSlowGen.

Definition at line 137 of file unifiltergen.cc.

References IUniConfGen::iterator(), and UniFilterGen::keymap().

Referenced by UniSlowGen::iterator(), UniSecureGen::iterator(), and UniRetryGen::iterator().

◆ recursiveiterator()

UniConfGen::Iter * UniFilterGen::recursiveiterator ( const UniConfKey key)
virtualinherited

Like iterator(), but the returned iterator is recursive, that is, it will return children of the immediate children, not just the immediate children themselves.

May return NULL if the key has no immediate children (since that means there are also no indirect children).

Note that UniConfGen::recursiveiterator() is a default implementation that just calls iterator() recursively, so it'll work in any derived class without you overriding this function. However, you might want to do it anyway if it would be more efficient in your particular case.

Reimplemented from UniConfGen.

Reimplemented in UniRetryGen, UniAutoMountGen, UniSecureGen, and UniSlowGen.

Definition at line 147 of file unifiltergen.cc.

References UniFilterGen::keymap(), and IUniConfGen::recursiveiterator().

Referenced by UniSlowGen::recursiveiterator(), and UniRetryGen::recursiveiterator().

◆ add_callback()

void UniConfGen::add_callback ( void *  cookie,
const UniConfGenCallback &  callback 
)
virtualinherited

Adds a callback for change notification.

Must not be reimplemented by subclasses of UniConfGen.

Implements IUniConfGen.

Definition at line 158 of file uniconfgen.cc.

Referenced by UniConfRoot::UniConfRoot().

◆ dispatch_delta()

void UniConfGen::dispatch_delta ( const UniConfKey key,
WvStringParm  value 
)
inherited

Immediately sends notification that a key has possibly changed.

Takes care of the details of invoking the callback.

Note: You probably want to be using delta() instead.

Definition at line 71 of file uniconfgen.cc.

Referenced by UniConfGen::delta(), and UniConfGen::flush_delta().

◆ hold_delta()

void UniConfGen::hold_delta ( )
inherited

Pauses notifications until matched with a call to unhold_delta().

While paused, notification events are placed into a pending list. Redundant notifications may be discarded.

Use this to safeguard non-reentrant code.

Definition at line 32 of file uniconfgen.cc.

Referenced by UniTransactionGen::commit(), UniMountGen::commit(), UniConfGen::delta(), UniConfGen::haschildren(), UniMountGen::mountgen(), UniTransactionGen::refresh(), UniMountGen::refresh(), UniTempGen::set(), UniClientGen::set(), UniTransactionGen::set(), UniClientGen::setv(), UniTransactionGen::setv(), and UniMountGen::unmount().

◆ unhold_delta()

void UniConfGen::unhold_delta ( )
inherited

Resumes notifications when each hold_delta() has been matched.

On resumption, dispatches all pending notifications except those that were destined to watches that were removed.

Use this to safeguard non-reentrant code.

Definition at line 38 of file uniconfgen.cc.

References UniConfGen::flush_delta().

Referenced by UniTransactionGen::commit(), UniMountGen::commit(), UniConfGen::delta(), UniConfGen::haschildren(), UniMountGen::mountgen(), UniTransactionGen::refresh(), UniMountGen::refresh(), UniTempGen::set(), UniClientGen::set(), UniTransactionGen::set(), UniClientGen::setv(), UniTransactionGen::setv(), and UniMountGen::unmount().

◆ clear_delta()

void UniConfGen::clear_delta ( )
inherited

Clears the list of pending notifications without sending them.

Does not affect the hold nesting count.

Definition at line 47 of file uniconfgen.cc.

◆ flush_delta()

void UniConfGen::flush_delta ( )
inherited

Flushes the list of pending notifications by sending them.

Does not affect the hold nesting count.

Definition at line 53 of file uniconfgen.cc.

References UniConfGen::dispatch_delta().

Referenced by UniConfGen::unhold_delta().

◆ delta()

void UniConfGen::delta ( const UniConfKey key,
WvStringParm  value 
)
inherited

◆ str2int()

int UniConfGen::str2int ( WvStringParm  s,
int  defvalue 
) const
virtualinherited

Converts a string to an integer.

If the string is null or not recognized, return defvalue.

This is here to support the common str2int(get(key)).

The default implementation recognizes the booleans 'true', 'yes', 'on' and 'enabled' as 1, and 'false', 'no', 'off' and 'disabled' as 0.

Implements IUniConfGen.

Definition at line 126 of file uniconfgen.cc.

◆ addRef()

virtual unsigned int IObject::addRef ( )
pure virtualinherited

Indicate you are using this object.

This increases the reference count of the object by one. Usually, when the reference count reaches zero, the object is freed automatically.

This called a "strong reference", because they will prevent the object from being destroyed. They should thus be used carefully, as they control the lifetime of the object. For example, you do not need to call addRef() on object passed as parameters, unless you intend on keeping them.

addRef() is often called automatically for you in XPLC, but you'll have to call release() by hand sometimes unless you use xplc_ptr.

Referenced by WvIStreamList::execute(), IObjectImplInternal::getInterface(), StaticServiceHandler::getObject(), WeakRef::getObject(), WvIStreamList::post_select(), WvQtStreamClone::WvQtStreamClone(), and WvSSLStream::WvSSLStream().

◆ release()

virtual unsigned int IObject::release ( )
pure virtualinherited

Indicate that you are finished using this object.

This decreases the reference count of the object by one. Usually, when the reference count reaches zero, the object is freed automatically.

You will usually need to manually release() any object given to you by any other XPLC function, unless you give the object to someone else who will call release.

If you use xplc_ptr, it will do this for you.

Referenced by WvIStreamList::execute(), mutate(), NewMoniker::resolve(), and MonikerService::resolve().

◆ getInterface()

virtual IObject* IObject::getInterface ( const UUID )
pure virtualinherited

Returns the requested XPLC interface.

Will return NULL if the interface is not supported. The returned interface has been addRef()ed, so you will need to release() it when done. Note that the interface returned may be a pointer to the same object or a different one - that's none of your business. Asking for the IObject interface should always return the same pointer for a given logical object, so this can be used for comparison by identity.

You should probably use the convenient mutate() and get() functions instead of this, or use an xplc_ptr, which mutates the object for you.

Referenced by get(), and mutate().

◆ getWeakRef()

virtual IWeakRef* IObject::getWeakRef ( )
pure virtualinherited

Return a weak reference to this object.

A weak reference points at the object, but does not control the lifetime of the object. An object can thus still be deleted while someone holds a weak reference. You will still need to release() the weak reference when you are done with it.

See also
IWeakRef

The documentation for this class was generated from the following files: