CStringPairs< TContainer > Class Template Reference
[String Manipulations]

Search Toolkit Book for CStringPairs

#include <ncbistr.hpp>

Collaboration diagram for CStringPairs< TContainer >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class TContainer>
class CStringPairs< TContainer >

Template for parsing string into pairs of name and value or merging them back into a single string.

The container class must hold pairs of strings (pair<string, string>).

Definition at line 2781 of file ncbistr.hpp.

Public Types

typedef TContainer TStrPairs
typedef TContainer::value_type TStrPair
 The container's value type must be pair<string, string> or a compatible type.

Public Member Functions

 CStringPairs (IStringDecoder *decoder=NULL, EOwnership own_decoder=eTakeOwnership, IStringEncoder *encoder=NULL, EOwnership own_encoder=eTakeOwnership)
 Create parser with the specified decoder/encoder and default separators.
 CStringPairs (const string &arg_sep, const string &val_sep, IStringDecoder *decoder=NULL, EOwnership own_decoder=eTakeOwnership, IStringEncoder *encoder=NULL, EOwnership own_encoder=eTakeOwnership)
 Create parser with the specified parameters.
 CStringPairs (NStr::EUrlDecode decode_flag, NStr::EUrlEncode encode_flag)
 Create parser with the selected URL-encoding/decoding options and default separators.
virtual ~CStringPairs (void)
void SetDecoder (IStringDecoder *decoder, EOwnership own=eTakeOwnership)
 Set string decoder.
IStringDecoderGetDecoder (void)
 Get decoder or NULL. Does not affect decoder ownership.
void SetEncoder (IStringEncoder *encoder, EOwnership own=eTakeOwnership)
 Set string encoder.
IStringDecoderGetEncoder (void)
 Get encoder or NULL. Does not affect encoder ownership.
void Parse (const CTempString &str, NStr::EMergeDelims merge_argsep=NStr::eMergeDelims)
 Parse the string.
string Merge (void) const
 Merge name-value pairs into a single string using the currently set separators and the provided encoder if any.
const TStrPairsGetPairs (void) const
 Read data.
TStrPairsGetPairs (void)
 Get non-const data.

Static Public Member Functions

static void Parse (TStrPairs &pairs, const CTempString &str, const string &arg_sep, const string &val_sep, IStringDecoder *decoder=NULL, EOwnership own=eTakeOwnership, NStr::EMergeDelims merge_argsep=NStr::eMergeDelims)
 Parse the string using the provided decoder, put data into the container.
static string Merge (const TStrPairs &pairs, const string &arg_sep, const string &val_sep, IStringEncoder *encoder=NULL, EOwnership own=eTakeOwnership)
 Merge name-value pairs from the provided container, separators and encoder.

Private Attributes

string m_ArgSep
string m_ValSep
AutoPtr< IStringDecoderm_Decoder
AutoPtr< IStringEncoderm_Encoder
TStrPairs m_Data


Member Typedef Documentation

template<class TContainer>
typedef TContainer::value_type CStringPairs< TContainer >::TStrPair
 

The container's value type must be pair<string, string> or a compatible type.

Definition at line 2787 of file ncbistr.hpp.

template<class TContainer>
typedef TContainer CStringPairs< TContainer >::TStrPairs
 

Definition at line 2784 of file ncbistr.hpp.


Constructor & Destructor Documentation

template<class TContainer>
CStringPairs< TContainer >::CStringPairs IStringDecoder decoder = NULL,
EOwnership  own_decoder = eTakeOwnership,
IStringEncoder encoder = NULL,
EOwnership  own_encoder = eTakeOwnership
[inline]
 

Create parser with the specified decoder/encoder and default separators.

Parameters:
decoder String decoder (Url, Xml etc.)
own_decoder Decoder ownership flag
decoder String encoder (Url, Xml etc.), optional
own_encoder Encoder ownership flag, optional

Definition at line 2799 of file ncbistr.hpp.

template<class TContainer>
CStringPairs< TContainer >::CStringPairs const string &  arg_sep,
const string &  val_sep,
IStringDecoder decoder = NULL,
EOwnership  own_decoder = eTakeOwnership,
IStringEncoder encoder = NULL,
EOwnership  own_encoder = eTakeOwnership
[inline]
 

Create parser with the specified parameters.

Parameters:
arg_sep Separator between name+value pairs
val_sep Separator between name and value
decoder String decoder (Url, Xml etc.)
own_decoder Decoder ownership flag
encoder String encoder (Url, Xml etc.)
own_encoder Encoder ownership flag

Definition at line 2824 of file ncbistr.hpp.

template<class TContainer>
CStringPairs< TContainer >::CStringPairs NStr::EUrlDecode  decode_flag,
NStr::EUrlEncode  encode_flag
[inline]
 

Create parser with the selected URL-encoding/decoding options and default separators.

Parameters:
decode_flag URL-decoding flag
encode_flag URL-encoding flag

Definition at line 2844 of file ncbistr.hpp.

template<class TContainer>
virtual CStringPairs< TContainer >::~CStringPairs void   )  [inline, virtual]
 

Definition at line 2853 of file ncbistr.hpp.


Member Function Documentation

template<class TContainer>
IStringDecoder* CStringPairs< TContainer >::GetDecoder void   )  [inline]
 

Get decoder or NULL. Does not affect decoder ownership.

Definition at line 2864 of file ncbistr.hpp.

template<class TContainer>
IStringDecoder* CStringPairs< TContainer >::GetEncoder void   )  [inline]
 

Get encoder or NULL. Does not affect encoder ownership.

Definition at line 2875 of file ncbistr.hpp.

template<class TContainer>
TStrPairs& CStringPairs< TContainer >::GetPairs void   )  [inline]
 

Get non-const data.

Definition at line 2987 of file ncbistr.hpp.

template<class TContainer>
const TStrPairs& CStringPairs< TContainer >::GetPairs void   )  const [inline]
 

Read data.

Definition at line 2985 of file ncbistr.hpp.

template<class TContainer>
static string CStringPairs< TContainer >::Merge const TStrPairs pairs,
const string &  arg_sep,
const string &  val_sep,
IStringEncoder encoder = NULL,
EOwnership  own = eTakeOwnership
[inline, static]
 

Merge name-value pairs from the provided container, separators and encoder.

Delete the encoder if the ownership flag allows.

Parameters:
pairs Container with the name/value pairs to be merged.
arg_sep Separator to be inserted bewteen pairs.
val_sep Separator to be inserted bewteen name and value.
encoder String encoder (Url, Xml etc.)
own Flag indicating if the encoder must be deleted by the function.

Definition at line 2960 of file ncbistr.hpp.

References IStringEncoder::eName, IStringEncoder::eValue, and ITERATE.

template<class TContainer>
string CStringPairs< TContainer >::Merge void   )  const [inline]
 

Merge name-value pairs into a single string using the currently set separators and the provided encoder if any.

Definition at line 2941 of file ncbistr.hpp.

References eNoOwnership, and Merge().

Referenced by SDiagMessage::FormatExtraMessage(), and CNcbiResourceInfo::x_GetEncoded().

template<class TContainer>
static void CStringPairs< TContainer >::Parse TStrPairs pairs,
const CTempString str,
const string &  arg_sep,
const string &  val_sep,
IStringDecoder decoder = NULL,
EOwnership  own = eTakeOwnership,
NStr::EMergeDelims  merge_argsep = NStr::eMergeDelims
[inline, static]
 

Parse the string using the provided decoder, put data into the container.

Parameters:
pairs Container to be filled with the parsed name/value pairs
str String to parse. The parser assumes the string is formatted like "name1<valsep>value1<argsep>name2<valsep>value2...". Each name and value is passed to the decoder (if not NULL) before storing the pair.
decoder String decoder (Url, Xml etc.)
own Flag indicating if the decoder must be deleted by the function.
merge_argsep Flag for merging separators between pairs. By default the separators are merged to prevent pairs where both name and value are empty.

Definition at line 2909 of file ncbistr.hpp.

References IStringDecoder::eName, IStringDecoder::eValue, ITERATE, NStr::Split(), and NStr::SplitInTwo().

template<class TContainer>
void CStringPairs< TContainer >::Parse const CTempString str,
NStr::EMergeDelims  merge_argsep = NStr::eMergeDelims
[inline]
 

Parse the string.

Parameters:
str String to parse. The parser assumes the string is formatted like "name1<valsep>value1<argsep>name2<valsep>value2...". Each name and value is passed to the decoder (if not NULL) before storing the pair.
merge_argsep Flag for merging separators between pairs. By default the separators are merged to prevent pairs where both name and value are empty.

Definition at line 2886 of file ncbistr.hpp.

References eNoOwnership.

template<class TContainer>
void CStringPairs< TContainer >::SetDecoder IStringDecoder decoder,
EOwnership  own = eTakeOwnership
[inline]
 

Set string decoder.

Parameters:
decoder String decoder (Url, Xml etc.)
own Decoder ownership flag

Definition at line 2861 of file ncbistr.hpp.

Referenced by CNcbiResourceInfo::CNcbiResourceInfo().

template<class TContainer>
void CStringPairs< TContainer >::SetEncoder IStringEncoder encoder,
EOwnership  own = eTakeOwnership
[inline]
 

Set string encoder.

Parameters:
encoder String encoder (Url, Xml etc.)
own Encoder ownership flag

Definition at line 2872 of file ncbistr.hpp.

Referenced by CNcbiResourceInfo::CNcbiResourceInfo().


Member Data Documentation

template<class TContainer>
string CStringPairs< TContainer >::m_ArgSep [private]
 

Definition at line 2990 of file ncbistr.hpp.

template<class TContainer>
TStrPairs CStringPairs< TContainer >::m_Data [private]
 

Definition at line 2994 of file ncbistr.hpp.

template<class TContainer>
AutoPtr<IStringDecoder> CStringPairs< TContainer >::m_Decoder [private]
 

Definition at line 2992 of file ncbistr.hpp.

template<class TContainer>
AutoPtr<IStringEncoder> CStringPairs< TContainer >::m_Encoder [private]
 

Definition at line 2993 of file ncbistr.hpp.

template<class TContainer>
string CStringPairs< TContainer >::m_ValSep [private]
 

Definition at line 2991 of file ncbistr.hpp.


The documentation for this class was generated from the following file:
Generated on Mon Dec 7 14:47:50 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:24:11 2009 by modify_doxy.py rev. 173732