Debian Codegraph @

src/vecteurs.h

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /***************************************************************************
2 vecteurs.h - Librairie d'objets permettant
3 de manipuler des vecteurs
4 -------------------
5 begin : ven aug 14 10:25:55 CEST 2000
6 copyright : (C) 2000 by Olivier Langella CNRS UPR9034
7 email : [email protected]
8 ***************************************************************************/
9
10 /***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19 // Objets permettant de manipuler des vecteurs
20 // Olivier Langella le 12/5/99
21 // [email protected]
22
23 #ifndef VECTEUR_H
24 #define VECTEUR_H
25
26 //#define __ENABLE_WSTRING
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <iostream>
31 #include <vector>
32 #include <string>
33 #include <iomanip>
34
35 using namespace std;
36
37 namespace biolib {
38 namespace vecteurs {
39
40 class VecteurLD: public vector<long double> {
41 };
42
43 template<class T> class Vecteur: public vector<T> {
44 public:
45
46 unsigned long getNbOccurence(const T& element) const {
47 unsigned long i;
48 unsigned long res(0);
49
50 for (i = 0; i < vector<T>::size(); i++) {
51 if (vector<T>::operator[](i) == element)
52 res++;
53 // if (this->operator[](i) == element) res++;
54 }
55
56 return (res);
57 }
58
59 bool Existe(const T& element) const {
60 unsigned long i;
61 bool res(false);
62
63 for (i = 0; i < vector<T>::size(); i++) {
64 if (vector<T>::operator[](i) == element) {
65 res = true;
66 break;
67 }
68 }
69
70 return (res);
71 }
72
73 signed long Position(const T& element) const {
74 unsigned long i;
75 signed long res(-1);
76
77 // long taille(vector<T>::size());
78
79 for (i = 0; i < vector<T>::size(); i++) {
80 if (vector<T>::operator[](i) == element) {
81 res = i;
82 break;
83 }
84 }
85 return (res);
86 }
87
88 void Suppr(unsigned long pos) {
89 erase(vector<T>::begin() + pos);
90 }
91
92 };
93
94 class ChaineCar: public string {
95 public:
96 ChaineCar() {
97 assign("");
98 }
99
100 ChaineCar(long i) {
101 AjEntier(i);
102 }
103
104 ChaineCar(const char * tag) {
105 assign(tag);
106 }
107
108 ChaineCar(const string& chaine) {
109 assign(chaine);
110 }
111
112 ~ChaineCar() {
113 }
114
115 void assigner(const string& chaine, signed long deb, signed long fin);
116
117 operator double() const {
118 return (atof(c_str()));
119 }
120
121 operator int() const {
122 return (atoi(c_str()));
123 }
124
125 operator unsigned int() const {
126 return (atoi(c_str()));
127 }
128
129 void GetLigneFlot(istream& entree);
130
131 long GetNbMots() const; //retourne le nombre de mots contenus
132 void GetMot(unsigned int numero, string &mot) const;
133 // dans la chaine (s�parateur= ' ' ou '/t')
134 unsigned long GetNbMots(const string & separateur) const; //retourne le nombre de mots contenus
135 void
136 GetMot(unsigned int numero, string &mot, const string & separateur) const;
137
138 const char * GetStr() {
139 return (c_str());
140 }
141 ;
142
143 ChaineCar& AjEntier(long i); //conversion automatique en base 10 et concat�nation
144 // ChaineCar& operator+= (char car) {return (string::operator+=(car));};
145 bool EstUnChiffre() const;
146
147 void fmajus();
148 void fsupprchiffres();
149 void fsupprgauche();
150 void fsupprdroite();
151 void fnettoie(const string &);
152 /** remplacer les occurences de "couper" par "coller" */
153 void Remplacer(const string & couper, const string & coller);
154 int Position(const string & motif) const;
155
156 // const ChaineCar& operator= (const string &rval) {*this = (ChaineCar) rval; return (*this);};
157
158 // const ChaineCar& operator= (const char * chaine) ;
159 };
160
161 class Titre: public vector<ChaineCar*> {
162
163 public:
164 ~Titre();
165 Titre() {
166 }
167
168 // Titre(const Titre& rval);
169 Titre(char ** commandes, int nbcommandes);
170
171 //d�pr�ci�:
172 const ChaineCar& get_titre(long i) const {
173 return (*(vector<ChaineCar*>::operator[](i)));
174 }
175
176 ChaineCar& GetTitre(long i) const;
177 void GetArguments(const string &);
178 ChaineCar& operator[](unsigned long i) const {
179 if (i >= size())
180 throw Anomalie(1);
181 return (GetTitre(i));
182 }
183
184 ChaineCar& back() {
185 return (*(vector<ChaineCar*>::back()));
186 }
187
188 long Position(const ChaineCar& chaine) const;
189
190 void push_back(const char * pcar) {
191 vector<ChaineCar*>::push_back(new ChaineCar(pcar));
192 }
193 ;
194 void push_back(const string & chaine) {
195 vector<ChaineCar*>::push_back(new ChaineCar(chaine.c_str()));
196 }
197
198 void pop_back() {
199 delete vector<ChaineCar*>::back();
200 vector<ChaineCar*>::pop_back();
201 }
202
203 void resize(long nouvtaille);
204
205 // void Suppr (unsigned long pos) {if (pos >= size()) throw Anomalie(1); delete (operator[](pos)); erase(begin()+pos);};
206 void Suppr(unsigned long pos);
207
208 const Titre& operator=(const Titre &rval);
209 bool operator==(const Titre &rval);
210 Titre operator+(const Titre &rval) const;
211
212 //string & affiche() const;
213
214 public:
215
216 struct Anomalie {
217 Anomalie(int i) :
218 le_pb(i) {
219 }
220
221 // 1-> titre inexistant
222 int le_pb;
223 };
224 };
225
226 void GetLigneFlot(istream& entree, string & ligne);
227
228 } //namespace biolib {
229 } //namespace vecteurs {
230
231 #endif
232