Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsString Class Reference

Defines strings as PsType. More...

#include <PsString.h>

Inheritance diagram for PsString:

Inheritance graph
[legend]
Collaboration diagram for PsString:

Collaboration graph
[legend]
List of all members.

member functions to use a PsString as a stream

Warning, using a PsString as a stream and at the same time for classical uses isn't possible.

For example, PsString test("foo"); PsString receiver; toto>>receiver generates a error

typedef PsString &(* separator )(PsString &)
 define the special functions that can be used with PsString (equivalent to endl type for streams )

PsString & operator<< (separator f)
 insertion of a special function in a PsString

PsString & operator<< (const char *f)
 insertion of a C-style string in a PsString

PsString & operator<< (const PsFlowable &f)
 Insertion of a PsFlowable in a PsString.

PsString & operator>> (PsFlowable &f)
 Extraction of a PsFlowable from a PsString.

PsString & sep (PsString &oChaine)
 a particular special function used to separate element inserted in a PsString


Public Methods

virtual void insertInStream (ostream &out=cout) const
 insertion in a stream this insertion inserts the string in the stream

virtual void extract (istream &in=cin)
 Extraction from a stream This extracts a PsString from a stream, but with all the limitations of the extraction of a string This means that all that would be inserted might not be extracted.

virtual void pack (ostream &out) const
 insertion in a stream, with support of arbitrary caracters this insertion inserts the string in the stream

virtual void unpack (istream &in=cin)
 Extraction from a buffer, with size being the first info in the buffer.

virtual void pack (PsOutgoingSynchronisationMessage &out) const
 insertion in a stream this insertion inserts the string in the stream

virtual void unpack (PsIncomingSynchronisationMessage &in)
 Extraction from a buffer.

virtual PsPolatorNTcreatePolator (void)
 creation of an associated Polator to conform to PsType

Constructors and destructors.
 PsString (const string &aString)
 Contruction from a string.

 PsString (const char *CStyleString="")
 default constructor, as well as contruction from C-style strings

 PsString (const PsString &originalString)
 copy constructor

 PsString (const char caracter)
 construction using one caracter

virtual ~PsString ()
 Destructor.

special member functions
PsString operator++ (int)
 intepret the string as a name followed by a numer, and increment that number.

PsString & operator++ (void)
 intepret the string as a name followed by a numer, and increment that number.

PsString & operator-- (void)
 intepret the string as a name followed by a numer, and decrement that number.

search for substring or caracters
int getSubString (const int startAt, const int nbCaracters, PsString &subString) const
 copy a subString into another

int getSubStringIndex (const PsString &subString) const
 getSubStringIndex.

int findCaracter (char Carac) const
 findCaracter.

unary operators
char operator[] (const int i) const
 get a particular caracter

PsString & operator= (const PsString &Source)
 copy content of another string

PsString & operator+ (const PsType &source)
 Append the string representation of any PsType.

PsString & operator+ (const string &source)
 Append a string.

Accessors
int getStringLength () const
 get the string length, aka the number of caracters

const char * getCString () const
 get associated C-style string


Protected Methods

protected member functions
int getCapacity () const
 get number of caracters storable in this PsString isn't considered, even if it's place is allocated

void alloue (const int capacity)
 allocated necessary memory.


Protected Attributes

char * _CString
 the C-style string

int _nbCarac
 number Of Meaning Full caracters

int _tailleMem
 memory fooprint of _CString


Static Protected Attributes

const int LG_MAX_BUFFER = 64
 default buffer size for extraction


Friends

friend operators
bool operator!= (const PsString &source1, const PsString &source2)
 compare two PsString

bool operator== (const PsString &source1, const PsString &source2)
 compare two PsString

bool operator> (const PsString &source1, const PsString &source2)
 compare two PsString

bool operator< (const PsString &source1, const PsString &source2)
 compare two PsString

bool operator>= (const PsString &source1, const PsString &source2)
 compare two PsString

bool operator<= (const PsString &source1, const PsString &source2)
 compare two PsString


Detailed Description

Defines strings as PsType.

rational for not using a string member is (by David Margery) :

Author:
Siames
Version:
2.1

Definition at line 48 of file PsString.h.


Member Typedef Documentation

typedef PsString&(* PsString::separator)(PsString &)
 

define the special functions that can be used with PsString (equivalent to endl type for streams )

Definition at line 209 of file PsString.h.


Constructor & Destructor Documentation

PsString::PsString const string &    aString
 

Contruction from a string.

Definition at line 39 of file PsString.cxx.

References _CString, _nbCarac, and alloue().

Referenced by operator<<().

00040 {
00041    _CString = NULL; // Nettoyage de la mémoire
00042    _nbCarac = strlen( aString.c_str() ) ;
00043    assert (_nbCarac == aString.length ()) ;
00044    alloue( _nbCarac );
00045    // On vérifie que le nombre de caractères est différent de 0
00046    if (_nbCarac != 0)
00047       {
00048        strcpy(_CString, aString.c_str());
00049        assert (_CString [_nbCarac] == '\0') ;
00050     }
00051    else
00052       {
00053          _CString[0] = '\0';
00054       }
00055 }

PsString::PsString const char *    CStyleString = ""
 

default constructor, as well as contruction from C-style strings

Definition at line 58 of file PsString.cxx.

References _CString, _nbCarac, alloue(), and PsController::error().

00059 {     
00060    //cerr<<"PsString : constructeur par recopie d'un char *"<<endl;
00061    if (Chn == NULL)
00062     {
00063       cerr << "PsString::PsString(const char*) : " << endl;
00064       PsController::error("La chaine fournie est un pointeur NULL");
00065     }
00066   _CString = NULL; // Nettoyage de la mémoire
00067   _nbCarac = strlen(Chn);
00068   alloue(_nbCarac);
00069   // On vérifie que le nombre de caractères est différent de 0
00070   if (_nbCarac != 0)
00071     {
00072       // On ne copie que si nbCarac != 0
00073       strcpy(_CString, Chn);
00074     }
00075   else
00076     {
00077       _CString[0] = '\0';
00078     }
00079   //cerr<<_CString<<endl;
00080   //cerr<<"PsString::recopie terminée pour "<<_CString<<endl;
00081 }

PsString::PsString const PsString &    originalString
 

copy constructor

Definition at line 84 of file PsString.cxx.

References _CString, _nbCarac, alloue(), and getStringLength().

00085 {
00086    //cerr<<"PsString::PsString (const PsString &Chn)"<<endl;
00087   _CString = NULL; // Nettoyage de la mémoire
00088   _nbCarac = Chn.getStringLength();
00089   alloue(_nbCarac);
00090   if (_nbCarac != 0)
00091     {
00092       // On ne copie que si nbCarac != 0
00093        strcpy (_CString, Chn._CString);
00094     }
00095   else
00096     {
00097       _CString[0] = '\0';
00098     }
00099   //cerr<<Chn<<endl<<*this<<endl;
00100 }

PsString::PsString const char    caracter
 

construction using one caracter

Definition at line 102 of file PsString.cxx.

References _CString, _nbCarac, and alloue().

00103 {
00104    cerr<<"PsString : construction from a char: "<<Carac<<endl;
00105   _CString = NULL; // Nettoyage de la mémoire
00106   _nbCarac = 1;
00107   alloue(_nbCarac);
00108   // On copie la caractère et la fin de chaîne
00109   _CString[0]= Carac;
00110   _CString[1]= '\0';
00111 }

PsString::~PsString   [virtual]
 

Destructor.

Definition at line 113 of file PsString.cxx.

References _CString.

00114 {
00115    //cerr<<"PsString::~PsString"<<endl;
00116   // Si la chaîne a été allouée, on la désalloue
00117   if (_CString != NULL)
00118     {
00119        delete [] _CString;
00120     }
00121   //cerr<<"PsString::~PsString fini"<<endl;
00122   //gereVarClasse (Delete);
00123 }


Member Function Documentation

void PsString::alloue const int    capacity [protected]
 

allocated necessary memory.

Parameters:
capacity to allocate ( capacity + 1 chars will be allocated )

Definition at line 654 of file PsString.cxx.

References _CString, _tailleMem, PsController::error(), and PsMomeController::whichSharedMemoryManager().

Referenced by extract(), getSubString(), operator=(), PsString(), and unpack().

00655 {
00656    // Make sure length is correct
00657   //   assert (length >= 0 );
00658 
00659    // Si la chaîne était déjà allouée, on libère
00660    if (_CString!=NULL) 
00661       {
00662          delete [] _CString;    
00663          _CString = NULL ;
00664       }
00665    
00666    // On prévoit le caractère de fin de chaîne
00667    _tailleMem = length + 1;
00668    // On alloue la chaîne
00669 #ifdef _MOME
00670    //si la chaine se trouve dans la mémoire partagée, il faut allouer le tampon dans la mémoire partagée
00671   PsnSharedMemoryManager * myMemory = PsMomeController::whichSharedMemoryManager(this);
00672   HeapStackTop newAllocationContext(myMemory) ;
00673 #endif
00674   _CString = new char[_tailleMem];
00675   // Si l'allocation ne s'est pas bien passée
00676   if (!_CString)
00677     {
00678       PsController::error("ERROR : PsString::alloue() : Echec de l'allocation");
00679     }
00680   //cerr<<"Allocation d'une chaine dans la méméoire  à "<<(void *)_CString<<endl;
00681 }

PsPolatorNT * PsString::createPolator void    [virtual]
 

creation of an associated Polator to conform to PsType

Implements PsType.

Definition at line 125 of file PsString.cxx.

00125                                            {
00126   return  (PsPolatorNT *) new PsPolator<PsString>();
00127 }

void PsString::extract istream &    in = cin [virtual]
 

Extraction from a stream This extracts a PsString from a stream, but with all the limitations of the extraction of a string This means that all that would be inserted might not be extracted.

Parameters:
out stream to extract from

Implements PsFlowable.

Definition at line 358 of file PsString.cxx.

References _CString, and alloue().

00359 {
00360    //It is impossible to correctly extract an inserted stream because the inserted stream could have whitespaces
00361    string result ;
00362    in >> result ;
00363    alloue (result.size() + 1 ) ;
00364    strcpy (_CString, const_cast<char *>(result.c_str()) );
00365 }

int PsString::findCaracter char    Carac const
 

findCaracter.

Find the index of the first instance of a caracter in PsString

Parameters:
caracter the caracter looked for
Returns:
index of the caracter in the coresponding C style string in caracter exists, negative value otherwise

Definition at line 213 of file PsString.cxx.

References _CString.

Referenced by openMaskMain().

00214 {
00215   char *ptrDebut = strchr(_CString, Carac);
00216   // A-t-on trouvé la chaîne ?
00217   if (ptrDebut == NULL)
00218     {
00219       // Pas trouvé
00220       return -1;
00221     }
00222   else
00223     {
00224       // On a trouvé
00225       return (ptrDebut - _CString);
00226     }
00227 }

int PsString::getCapacity   const [protected]
 

get number of caracters storable in this PsString isn't considered, even if it's place is allocated

Returns:
current capacity

Definition at line 472 of file PsString.cxx.

References _tailleMem.

Referenced by operator=().

00473 {
00474   //assert ( _nbCarac == _tailleMem - 1) ;
00475    return _tailleMem-1;
00476 }

const char * PsString::getCString   const
 

get associated C-style string

Returns:
the associated C-style string

Definition at line 478 of file PsString.cxx.

References _CString.

Referenced by PsController::computeNextSimulationStep(), PsController::getPointerToDuplicatedObjectNamed(), nomPVM(), openMaskMain(), PsString_hash::operator()(), operator+(), PsBenchController< BenchedController >::PsBenchController(), PsnSvm::serveNameRequestsUntilEnd(), and testSG3().

00479 {
00480   //assert ( _nbCarac == _tailleMem - 1) ;
00481    return _CString;
00482 }

int PsString::getStringLength   const
 

get the string length, aka the number of caracters

Returns:
the string length

Definition at line 466 of file PsString.cxx.

References _nbCarac.

Referenced by PsString().

00467 {
00468    //assert ( _nbCarac == _tailleMem - 1) ;
00469    return _nbCarac;
00470 }

int PsString::getSubString const int    startAt,
const int    nbCaracters,
PsString &    subString
const
 

copy a subString into another

Parameters:
startAt index of the letter at wich to start copying
nbCaracters number of caracters to copy (if nbCaracters < 0, all the string is copied
subString a reference to the PsString receiving the result
Returns:
numberOfCaracters copied

Definition at line 130 of file PsString.cxx.

References _CString, _nbCarac, _tailleMem, and alloue().

00132 {
00133    //assert ( _nbCarac == _tailleMem - 1) ;
00134 
00135    // Nombre de caractères à copier
00136    int nbMin;
00137    
00138    // On vérifie que l'indice de début est bien dans la chaîne
00139    if ( (debut >= _nbCarac) || (debut < 0) )
00140       {
00141       cerr << "WARNING : PsString::getSubString() :" << endl;
00142       cerr << "Indice de début de sous-chaîne (" << debut
00143            << ") sort de la chaîne de taille ("
00144            << _nbCarac << ")" << endl;
00145       // On n'a pas copié de caractères
00146       return 0;
00147     }
00148 
00149   // On regarde s'il veut tout le reste de la chaîne
00150   if (nbCarac <= 0)
00151     {
00152       // On va copier tous les autres caractères
00153       nbMin = _nbCarac-debut;
00154     }
00155   // On détermine le nombre de caractère à fournir en regardant
00156   // la limite de fin de chaîne
00157   else if ( (_nbCarac-debut) < nbCarac)
00158     {
00159       nbMin = _nbCarac-debut;
00160     }
00161   else
00162     {
00163       nbMin = nbCarac;
00164     }
00165   
00166   // On vérifie qu'il y a assez de place dans sousChaine
00167   if (sousChaine._tailleMem <= nbMin)
00168     {
00169       // On alloue la place suffisante nbMin+1
00170       sousChaine.alloue(nbMin);
00171     }
00172 
00173   // On fait la copie (pas de vérification à cet endroit-là)
00174   strncpy(sousChaine._CString, _CString+debut, nbMin);
00175 
00176   // On ajoute la fin de chaîne
00177   sousChaine._CString[nbMin]= '\0';
00178   sousChaine._nbCarac= nbMin;
00179 
00180   // On renvoie le nombre de caractères copîés
00181   return nbMin;
00182 }

int PsString::getSubStringIndex const PsString &    subString const
 

getSubStringIndex.

looks for a substring in the PsString

Parameters:
subString subString to find
Returns:
index of the first caracter of the PsString starting substring if found, negative value otherwise

Definition at line 189 of file PsString.cxx.

References _CString, and _nbCarac.

00190 {
00191   if (cherche._nbCarac == 0)
00192     {
00193       cerr << "WARNING : PsString::getSubStringIndex() :"
00194            << "Taille de la sous-chaîne recherchée nulle" << endl;
00195       return -1;
00196     }
00197 
00198   char *ptrDebut = strstr(_CString, cherche._CString);
00199   // A-t-on trouvé la chaîne ?
00200   if (ptrDebut == NULL)
00201     {
00202       // Pas trouvé
00203       return -1;
00204     }
00205   else
00206     {
00207       // On a trouvé
00208       return (ptrDebut - _CString);
00209     }
00210 }

void PsString::insertInStream ostream &    out = cout const [virtual]
 

insertion in a stream this insertion inserts the string in the stream

Implements PsFlowable.

Definition at line 367 of file PsString.cxx.

References _CString.

00368 {
00369   // insert the string
00370   out << _CString;
00371 }

PsString & PsString::operator+ const string &    source
 

Append a string.

Parameters:
a string
Returns:
a reference to oneself

Definition at line 311 of file PsString.cxx.

References getCString().

00312 {   
00313    //then constructuct a string corresponding to this
00314    string temp( getCString() ) ;
00315    
00316    // append the two stings and copy the result into this
00317    *this = temp + source ;
00318    
00319    //cerr << "PsString::operator + (const PsType &Source) done " << endl;
00320    return *this;
00321 }

PsString & PsString::operator+ const PsType   source
 

Append the string representation of any PsType.

Parameters:
an object of type PsType
Returns:
a reference to oneself

Definition at line 288 of file PsString.cxx.

References getCString().

00289 {
00290    //cerr << "PsString::operator + (const PsType &Source)" << endl;
00291    
00292    //first insert the type in a string
00293 #ifdef _USESSTREAM
00294    ostringstream fluxTmp;
00295    fluxTmp << Source ;
00296 #else
00297    strstream fluxTmp;
00298    fluxTmp << Source <<'\0' ;
00299 #endif
00300    
00301    //then constructuct a string corresponding to this
00302    string temp( getCString() ) ;
00303    
00304    // append the two stings and copy the result into this
00305    *this = temp + fluxTmp.str() ;
00306    
00307    //cerr << "PsString::operator + (const PsType &Source) done " << endl;
00308    return *this;
00309 }

PsString & PsString::operator++ void   
 

intepret the string as a name followed by a numer, and increment that number.

If no number can be found, 0 will be added.

Definition at line 530 of file PsString.cxx.

References _CString, _nbCarac, _tailleMem, and PsController::error().

00530                                   {
00531    char * nouvelleChaine;
00532    char zero('0');
00533    char neuf('9');
00534    if ((_nbCarac==0)||
00535        ((zero>_CString[_nbCarac-1])||(_CString[_nbCarac-1]>=neuf))) {
00536       //on a besoin d'écrire une case plus loin
00537       if(_tailleMem<=_nbCarac+1) {
00538          //on a potentiellement besoin de réallouer de la place 
00539          _tailleMem=_nbCarac+2;
00540          nouvelleChaine=new char[_tailleMem];
00541          if (!nouvelleChaine) {
00542             PsController::error("ERROR : Impossible d'allouer de la mémoire pour ++");
00543          }
00544          strcpy(nouvelleChaine,_CString);
00545          if (_CString!=NULL) {
00546             delete [] _CString;
00547          }
00548          _CString=nouvelleChaine;
00549       }
00550       if(_CString[_nbCarac-1]!=neuf) {
00551          _CString[_nbCarac]=zero;
00552          _CString[_nbCarac+1]='\0';
00553          _nbCarac++;
00554       }
00555       else {//le dernier caractère est 9
00556          int indicePremierPasNeuf=_nbCarac-1; 
00557          do {
00558             _CString[indicePremierPasNeuf]=zero;
00559             indicePremierPasNeuf--;
00560          }
00561          while (_CString[indicePremierPasNeuf]==neuf);
00562          if ( (_CString[indicePremierPasNeuf]>=zero)&&(_CString[indicePremierPasNeuf]<neuf))
00563             {
00564                _CString[indicePremierPasNeuf]++;
00565             }
00566          else {
00567             _CString[indicePremierPasNeuf+1]='1';
00568             _CString[_nbCarac]=zero;
00569             _CString[_nbCarac+1]='\0';
00570             _nbCarac++;
00571          } 
00572       }
00573    }
00574    else {
00575       _CString[_nbCarac-1]=_CString[_nbCarac-1]+1;
00576    }
00577    return *this;
00578 }

PsString PsString::operator++ int   
 

intepret the string as a name followed by a numer, and increment that number.

If no number can be found, 0 will be added. Example : PsString ident("base"); ident++; // -> ident == "base0" ident++; // -> ident == "base1" ... ident++; // -> ident == "base9" ident++; // -> ident == "base10"

Definition at line 524 of file PsString.cxx.

00524                                      {
00525    PsString retour (*this);
00526    ++(*this);
00527    return retour;
00528 }

PsString & PsString::operator-- void   
 

intepret the string as a name followed by a numer, and decrement that number.

If no number can be found, the string won't be modified and a warning will be printed to cerr Example : PsString ident("base10"); ident--; // -> ident == "base9" ... ident--; // -> ident == "base0" ident--; // -> ident == "base" ident--; //

Definition at line 580 of file PsString.cxx.

References _CString, and _nbCarac.

00580                                   {
00581 
00582   char nouvelleChaine[20];
00583   char zero('0');
00584   char neuf('9');
00585   int nbNum ;
00586   int nombreTemps =0 ;
00587   int i,nb ;
00588   int puissance = 1;
00589 
00590   // cas chaine vide
00591   if (_nbCarac==0) 
00592     return *this ;
00593 
00594   // cas ou il n'y as pas de caractere numerique en fin de chaine  
00595   if ((zero>_CString[_nbCarac-1])||(_CString[_nbCarac-1]>neuf))
00596     return *this ;
00597     
00598   // bon cas
00599   if ((zero<_CString[_nbCarac-1])&&(_CString[_nbCarac-1]<=neuf))
00600     {
00601       // cas si un chiffre entre 1 et 9
00602       // +1, meme nombre de caractere
00603       _CString[_nbCarac-1]--;
00604       return *this ;
00605     }
00606   // on est dans le cas zero
00607   // conbien de caractere numerique ?
00608   // on sait que le dernier en est un
00609   nbNum = 1 ;
00610   while ( (zero<=_CString[_nbCarac-1-nbNum])&&(_CString[_nbCarac-1-nbNum]<=neuf) )
00611     nbNum++;
00612   
00613   if ((nbNum==1)&&(_CString[_nbCarac-1]==zero))
00614     {
00615       _nbCarac--;
00616       _CString[_nbCarac]='\0';
00617       return *this ; 
00618     }
00619   
00620   for(i=0;i<nbNum;i++)
00621     {
00622       nombreTemps =  (_CString[_nbCarac-1-i]-zero)*puissance + nombreTemps ;
00623       puissance = puissance *10 ;
00624     }
00625     
00626   nombreTemps--;
00627   nb=0;
00628   while (nombreTemps!=0)
00629     {
00630       // on rentre les chiffres a l'envers dans une chaine temporaire
00631       int val = nombreTemps % 10 ;
00632       nombreTemps = nombreTemps / 10 ;
00633       nouvelleChaine[nb] = zero + val ;
00634       nb++;
00635     }
00636     
00637   for(int j=1;j<=nb;j++)
00638     _CString[_nbCarac-nbNum+j-1] = nouvelleChaine[nb-j] ;
00639   
00640   //cout << "  _nbCarac : " <<  _nbCarac << endl ;
00641   //cout << "nb : " << nb << endl ; 
00642   //cout << "nbNum : " << nbNum << endl ;
00643   _nbCarac = _nbCarac - nbNum + nb ;
00644   _CString[_nbCarac] = '\0' ;
00645   
00646   return *this ;
00647 }

PsString & PsString::operator<< const PsFlowable   f
 

Insertion of a PsFlowable in a PsString.

Definition at line 393 of file PsString.cxx.

References LG_MAX_BUFFER, and PsString().

00393                                                       {
00394 #ifdef _USESSTREAM
00395    ostringstream myos ;
00396    myos << f ;
00397    *this = (*this) +  myos.str() ;
00398 #else
00399    char tampon[LG_MAX_BUFFER];
00400    ostrstream myos(tampon,LG_MAX_BUFFER);
00401    myos<<f;
00402    int i = myos.pcount() ;
00403    PsString * chaineTemp;
00404    if (myos.fail()||(i>=LG_MAX_BUFFER)) {
00405       int tailleTampon=LG_MAX_BUFFER;
00406       char * biggerTampon;
00407       ostrstream * biggeros;
00408       do {
00409          tailleTampon=tailleTampon*2;
00410          biggerTampon=new char[tailleTampon];
00411          biggeros=new ostrstream(biggerTampon,tailleTampon);
00412          *biggeros<<f;
00413          i = biggeros->pcount() ;
00414       } 
00415       while(biggeros->fail()||(i>=tailleTampon));
00416       biggerTampon[i] = '\0' ;
00417       chaineTemp=new PsString(biggerTampon);
00418       delete [] biggerTampon;
00419       delete biggeros;
00420    }
00421    else {
00422      tampon[i]='\0' ;
00423      chaineTemp=new PsString(tampon);
00424    }
00425    *this=*this+*chaineTemp; 
00426    delete chaineTemp;
00427 #endif
00428    return(*this);
00429 }

PsString & PsString::operator<< const char *    f
 

insertion of a C-style string in a PsString

Definition at line 386 of file PsString.cxx.

00386                                                 {
00387    PsString tmp(f);
00388    *this<<tmp;
00389    return (*this);
00390 }

PsString & PsString::operator<< separator    f
 

insertion of a special function in a PsString

Definition at line 374 of file PsString.cxx.

00375 {
00376    PsString espace(" ");
00377    *this=*this+espace;
00378    return *this;
00379 }

PsString & PsString::operator= const PsString &    Source
 

copy content of another string

Parameters:
source source string to copy
Returns:
a reference to oneself

Definition at line 245 of file PsString.cxx.

References _CString, _nbCarac, alloue(), and getCapacity().

00246 {
00247    //cerr<<"PsString::operator = "<<*this<<";"<<Source<<endl;
00248   // On vérifie que ce ne sont pas les mêmes chaînes,
00249   // sinon c'est fini
00250   if (_CString != Source._CString)
00251     {
00252       // Si on n'a pas la capacité de recevoir 
00253       if (getCapacity() < Source._nbCarac)
00254         {
00255           alloue(Source._nbCarac);
00256         }
00257       // On fait la copie
00258       _nbCarac = Source._nbCarac;
00259       strcpy(_CString, Source._CString);
00260     }
00261   // On a terminé, on se renvoie
00262   return *this;
00263 }

PsString & PsString::operator>> PsFlowable   f
 

Extraction of a PsFlowable from a PsString.

Definition at line 431 of file PsString.cxx.

References _CString, _nbCarac, and _tailleMem.

00431                                                 {
00432    char * nouvelleChaine;
00433    int indiceDebutSuite;
00434 #ifdef _USESSTREAM
00435    istringstream myis(_CString);
00436 #else
00437    istrstream myis(_CString,_tailleMem);
00438 #endif
00439    myis>>f;
00440    if(myis.fail()) {
00441 #ifdef _DEBUGPVMMESS
00442       cerr<<"Impossible extraction"
00443           <<endl
00444           <<"The 2 main causes of this error are : you are trying to extract stuff from a string that wasn't inserted, but iether hand constructed in the string or not inserted at all"
00445           <<endl
00446       throw PsUserException ("PsString::operator>>: extraction impossible");
00447 #endif    
00448    }
00449    indiceDebutSuite=myis.tellg();//si il y a une suite, elle va commencer à indiceDebutSuite
00450    //on supprime les séparateurs
00451    while(isspace(_CString[indiceDebutSuite])&&(_CString[indiceDebutSuite]!='\0')) {
00452       indiceDebutSuite++;
00453    };
00454    nouvelleChaine=new char[_tailleMem-indiceDebutSuite];
00455    strcpy(nouvelleChaine,_CString+indiceDebutSuite);
00456    if (_CString != NULL) delete [] _CString;
00457    _CString=nouvelleChaine;
00458    _nbCarac=strlen(_CString);
00459    _tailleMem=_tailleMem-indiceDebutSuite;
00460    return (*this);
00461 }  

char PsString::operator[] const int    i const
 

get a particular caracter

Parameters:
i index of the wanted caracter
Returns:
the wanted caracter

Definition at line 230 of file PsString.cxx.

References _CString, _nbCarac, and PsController::error().

00231 {
00232   if ( (i<0) || (i>=_nbCarac) )
00233     {
00234       cerr << "PsString::operator[]: index (" << i << ") hors limite" << endl;
00235       PsController::error("");
00236       // Pour la compilation
00237       return 0;
00238     }
00239   else
00240     {
00241       return _CString[i];
00242     }
00243 }

void PsString::pack PsOutgoingSynchronisationMessage   out const [virtual]
 

insertion in a stream this insertion inserts the string in the stream

Reimplemented from PsFlowable.

Definition at line 325 of file PsString.cxx.

References _CString, and _nbCarac.

00326 {
00327    out<<_nbCarac<<_CString;
00328 }

void PsString::pack ostream &    out const [virtual]
 

insertion in a stream, with support of arbitrary caracters this insertion inserts the string in the stream

Definition at line 342 of file PsString.cxx.

References _CString, and _nbCarac.

00343 {
00344    out<<_nbCarac<<" "<<_CString<<" ";
00345 }

void PsString::unpack PsIncomingSynchronisationMessage   in [virtual]
 

Extraction from a buffer.

Parameters:
out stream to extract from

Reimplemented from PsFlowable.

Definition at line 330 of file PsString.cxx.

References _CString, _nbCarac, _tailleMem, and alloue().

00331 {
00332    in>> _nbCarac ;
00333    if (_tailleMem <= _nbCarac)
00334       {
00335          // Allocate the necessary memory
00336          alloue(_nbCarac);
00337       }
00338    in>>_CString ;
00339 }

void PsString::unpack istream &    in = cin [virtual]
 

Extraction from a buffer, with size being the first info in the buffer.

Parameters:
out stream to extract from

Definition at line 347 of file PsString.cxx.

References _CString, _nbCarac, _tailleMem, and alloue().

00348 {
00349    in>> _nbCarac ;
00350    if (_tailleMem <= _nbCarac)
00351       {
00352          // Allocate the necessary memory
00353          alloue(_nbCarac);
00354       }
00355    in.get (_CString, _nbCarac +1 ) ;
00356 }


Friends And Related Function Documentation

bool operator!= const PsString &    Source1,
const PsString &    Source2
[friend]
 

compare two PsString

Parameters:
source1 first PsString
source2 second PsString
Returns:
the two PsString are different

Definition at line 508 of file PsString.cxx.

00509 {
00510    //   cout<<"operator != (const PsString , const PsString)"<<endl;
00511    //   cout<<"_"<<Source1._CString<<"_"<<Source2._CString<<endl;
00512   return (strcmp(Source1._CString, Source2._CString));
00513 }

bool operator< const PsString &    Source1,
const PsString &    Source2
[friend]
 

compare two PsString

Parameters:
source1 first PsString
source2 second PsString
Returns:
the first string is stricly smaller in lexicographic order

Definition at line 491 of file PsString.cxx.

00492 {
00493    //      cout<<"operator < (const PsString , const PsString)"<<endl;
00494    //      cout<<"_"<<Source1._CString<<"_"<<Source2._CString<<"_"<<endl;
00495   return (strcmp(Source1._CString, Source2._CString)< 0);
00496 }

bool operator<= const PsString &    Source1,
const PsString &    Source2
[friend]
 

compare two PsString

Parameters:
source1 first PsString
source2 second PsString
Returns:
the first string is smaller in lexicographic order

Definition at line 503 of file PsString.cxx.

00504 {
00505   return (!(Source1 > Source2));
00506 }

bool operator== const PsString &    Source1,
const PsString &    Source2
[friend]
 

compare two PsString

Parameters:
source1 first PsString
source2 second PsString
Returns:
the two PsString are equal in a lexicographic point of view

Definition at line 517 of file PsString.cxx.

00518 {
00519   return (!(Source1 != Source2));
00520 }

bool operator> const PsString &    Source1,
const PsString &    Source2
[friend]
 

compare two PsString

Parameters:
source1 first PsString
source2 second PsString
Returns:
the first string is stricly greater in lexicographic order

Definition at line 486 of file PsString.cxx.

00487 {
00488   return (strcmp(Source1._CString, Source2._CString)> 0);
00489 }

bool operator>= const PsString &    Source1,
const PsString &    Source2
[friend]
 

compare two PsString

Parameters:
source1 first PsString
source2 second PsString
Returns:
the first string is greater in lexicographic order

Definition at line 498 of file PsString.cxx.

00499 {
00500   return (!(Source1 < Source2));
00501 }

PsString& sep PsString &    oChaine [friend]
 

a particular special function used to separate element inserted in a PsString

Definition at line 381 of file PsString.cxx.

00382 {
00383    return (oChaine);
00384 }


Member Data Documentation

char* PsString::_CString [protected]
 

the C-style string

Definition at line 301 of file PsString.h.

Referenced by alloue(), extract(), findCaracter(), getCString(), getSubString(), getSubStringIndex(), insertInStream(), operator!=(), operator++(), operator--(), operator<(), operator=(), operator>(), operator>>(), operator[](), pack(), PsString(), unpack(), and ~PsString().

int PsString::_nbCarac [protected]
 

number Of Meaning Full caracters

Definition at line 304 of file PsString.h.

Referenced by getStringLength(), getSubString(), getSubStringIndex(), operator++(), operator--(), operator=(), operator>>(), operator[](), pack(), PsString(), and unpack().

int PsString::_tailleMem [protected]
 

memory fooprint of _CString

Definition at line 307 of file PsString.h.

Referenced by alloue(), getCapacity(), getSubString(), operator++(), operator>>(), and unpack().

const int PsString::LG_MAX_BUFFER = 64 [static, protected]
 

default buffer size for extraction

Definition at line 298 of file PsString.h.

Referenced by operator<<().


The documentation for this class was generated from the following files:
logo OpenMask

Documentation generated on Mon Nov 25 15:26:30 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001