9a89e851d2
- aggiunto l'operatore == alla struttura SelData (per consentire confronti con funzioni STL direttamente sui contenitori).
72 lines
2.7 KiB
C++
72 lines
2.7 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : EGkSelection.h Data : 11.06.15 Versione : 1.6f2
|
|
// Contenuto : Strutture e raccolte per indici di selezione,
|
|
// con funzioni di conversione da e verso stringhe.
|
|
//
|
|
//
|
|
// Modifiche : 11.06.15 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
#include "/EgtDev/Include/EGkGdbConst.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
#include <vector>
|
|
#include <list>
|
|
|
|
//----------------------------------------------------------------------------
|
|
// costante per indicare che è selezionato tutto l'oggetto (le parti hanno indice 0-based)
|
|
const int SEL_SUB_ALL = - 1 ;
|
|
// Struttura per selezione di oggetto o di sua parte
|
|
struct SelData {
|
|
union {
|
|
struct {
|
|
int nId ;
|
|
int nSub ;
|
|
} ;
|
|
int v[2] ;
|
|
} ;
|
|
SelData( void)
|
|
: nId( GDB_ID_NULL), nSub( SEL_SUB_ALL) {}
|
|
SelData( int nI)
|
|
: nId( nI), nSub( SEL_SUB_ALL) {}
|
|
SelData( int nI, int nS)
|
|
: nId( nI), nSub( nS) {}
|
|
bool operator == ( const SelData& other) const
|
|
{ return ( nId == other.nId && nSub == other.nSub) ; }
|
|
} ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Raccolte di SelData
|
|
typedef std::vector<SelData> SELVECTOR ; // vettore di SelData
|
|
typedef std::list<SelData> SELLIST ; // lista di SelData
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Conversione di SelData da e verso stringhe
|
|
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
|
|
inline bool FromString( const std::string& sVal, SELVECTOR& vVal)
|
|
{ INTVECTOR vI ;
|
|
if ( ! FromString( sVal, vI) || ( vI.size() % 2) != 0)
|
|
return false ;
|
|
vVal.reserve( vI.size() / 2) ;
|
|
for ( size_t i = 0 ; i < vI.size() ; i += 2)
|
|
vVal.emplace_back( vI[i], vI[i+1]) ;
|
|
return true ; }
|
|
inline const std::string ToString( const SELVECTOR& vVal, int nPrec = 1)
|
|
{ std::string sDest ; sDest.reserve( 2 * 8 * vVal.size()) ;
|
|
for ( const auto& Val : vVal)
|
|
sDest += ToString( Val.nId, nPrec) + "," + ToString( Val.nSub, nPrec) + "," ;
|
|
if ( ! sDest.empty())
|
|
sDest.pop_back() ;
|
|
return sDest ; }
|