Public Member Functions | |
String | next () |
Protected Member Functions | |
virtual void UC_DLL_CALL | nextImpl (String &res)=0 |
Successive calls to the next() method return successive elements of the series.
#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()); } } }
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
.