fe::IStringSource Class Reference
[Ferry Core library]

An abstraction of a series of fe::String-s. More...

Inheritance diagram for fe::IStringSource:

fe::SingleItemStringSource

List of all members.

Public Member Functions

String next ()

Protected Member Functions

virtual void UC_DLL_CALL nextImpl (String &res)=0


Detailed Description

An abstraction of a series of fe::String-s.

Successive calls to the next() method return successive elements of the series.

Note:
This class is declared with UC_DLL_INTERFACE_DECLARE
Sample implementation:
#include <string>
#include <vector>
#include "fe/ferry.h"


class SampleStringSource : public fe::IStringSource
{
UC_DLL_INTERFACE_IMPL(IStringSource)
public:
    typedef std::vector<std::string> strings_type;
private:
    unsigned       idx_;
    strings_type   strings_;
public:
    SampleStringSource(const strings_type& strings)
    {
        idx_        = 0;
        strings_    = strings;
    }

    virtual ~SampleStringSource()
    {
    }

// fe::IStringSource implementation
protected:
    virtual void UC_DLL_CALL
    nextImpl(fe::String& res)
    {
        fe::String tmp;
        tmp.ptr = 0;
        tmp.len = 0;
        if(idx_ < strings_.size())
        {
            tmp.ptr = strings_[idx_].c_str();
            tmp.len = strings_[idx_].size();
            idx_++;
        }
        res = tmp;
    }
};

Sample usage:

#include <string>
#include <stdio.h>
#include "fe/ferry.h"


void
printStrings(fe::IStringSource& ss)
{
    fe::String s;
    while((s = ss.next()).ptr)
    {
        if(!*(s.ptr + s.len))
        {
            printf("str=%s\n", s.ptr);
        }
        else
        {
            std::string buf = std::string(s.ptr, s.len);
            printf("str=%s\n", buf.c_str());
        }
    }
}

Member Function Documentation

virtual void UC_DLL_CALL fe::IStringSource::nextImpl ( String res  )  [protected, pure virtual]

Implemented in fe::SingleItemStringSource.

String fe::IStringSource::next (  )  [inline]

Returns fe::String with the next string extracted from a series.

If there is no string available, the fe::String::ptr field of the returned value must be set to 0 and the fe::String::len field of the returned value must not be equal to (unsigned)-1.

To indicate error the fe::String::ptr field of the returned value must be set to 0 and the fe::String::len field of the returned value must be set to (unsigned)-1.


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

Generated on Tue Nov 18 21:08:23 2008 for Ferry by doxygen 1.5.7.1
http://sourceforge.net