diff --git a/EGkSelection.h b/EGkSelection.h index a537518..da744f1 100644 --- a/EGkSelection.h +++ b/EGkSelection.h @@ -46,14 +46,28 @@ typedef std::vector SELVECTOR ; // vettore di SelData typedef std::list SELLIST ; // lista di SelData //---------------------------------------------------------------------------- -// Conversione di SelData da e verso stringhe +// Conversione di SelData da e verso stringhe (Id,Sub) inline bool FromString( const std::string& sVal, SelData& Val) { return FromString( sVal, Val.v) ; } inline const std::string ToString( const SelData& Val, int nPrec = 1) { return ToString( Val.v, nPrec) ; } //---------------------------------------------------------------------------- -// Conversione di vettori di SelData da e verso stringhe +// Conversione di SelData da e verso stringhe utente (Id:Sub oppure Id) +inline bool FromUiString( const std::string& sVal, SelData& Val) + { std::string sId , sSub ; + SplitFirst( sVal, ":", sId, sSub) ; + Val = { GDB_ID_NULL, SEL_SUB_ALL} ; + FromString( sSub, Val.nSub) ; + return FromString( sId, Val.nId) ; } +inline const std::string ToUiString( const SelData& Val, int nPrec = 1) + { if ( Val.nSub != SEL_SUB_ALL) + return ToString( Val.nId, nPrec) + ":" + ToString( Val.nSub, nPrec) ; + else + return ToString( Val.nId, nPrec) ; } + +//---------------------------------------------------------------------------- +// Conversione di vettori di SelData da e verso stringhe (Id1,Sub1,Id2,Sub2,...) inline bool FromString( const std::string& sVal, SELVECTOR& vVal) { INTVECTOR vI ; if ( ! FromString( sVal, vI) || ( vI.size() % 2) != 0) @@ -69,3 +83,23 @@ inline const std::string ToString( const SELVECTOR& vVal, int nPrec = 1) if ( ! sDest.empty()) sDest.pop_back() ; return sDest ; } + +//---------------------------------------------------------------------------- +// Conversione di vettori di SelData da e verso stringhe utente (Id1:Sub1,Id2,...) +inline bool FromUiString( const std::string& sVal, SELVECTOR& vVal) + { STRVECTOR vsTokens ; + Tokenize( sVal, ",", vsTokens) ; + vVal.reserve( vsTokens.size()) ; + for ( const auto& sToken : vsTokens) { + SelData Val ; + if ( FromUiString( sToken, Val)) + vVal.emplace_back( Val) ; + } + return true ; } +inline const std::string ToUiString( const SELVECTOR& vVal, int nPrec = 1) + { std::string sDest ; sDest.reserve( 2 * 8 * vVal.size()) ; + for ( const auto& Val : vVal) + sDest += ToUiString( Val, nPrec) + "," ; + if ( ! sDest.empty()) + sDest.pop_back() ; + return sDest ; }