xc
PStream.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. PĂ©rez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //PStream.h
22 
23 #ifndef PSTREAM_H
24 #define PSTREAM_H
25 
26 #include <iostream.h>
27 #include <map.h>
28 #include <String.h>
29 
30 template <class T>
31 class PStream : public _IO_istream_withassign
32  {
33  public:
34  typedef map<String,T *,less<String> > mapa_claves;
35  private:
36  mapa_claves mapa;
37  public:
38  PStream(void) : _IO_istream_withassign() {}
39  PStream &operator=(istream &is)
40  {
41  _IO_istream_withassign::operator=(is);
42  return *this;
43  }
44  void Registra(const String &str,const T *p)
45  { mapa[str]= p->getCopy(); }
46  T *ClaseDato(void)
47  {
48  String str;
49  (_IO_istream_withassign &)(*this) >> str;
50  mapa_claves::const_iterator i= mapa.find(str);
51  if(i == mapa.end())
52  {
53  cerr << "La clase " << str << " no est'a registrada." << endl;
54  return NULL;
55  }
56  return (*i).second;
57  }
58  void Save(ostream &os) const
59  {
60  mapa_claves::const_iterator i;
61  for(i= mapa.begin();i!=mapa.end();i++)
62  os << ' ' << (*i).first;
63  }
64  };
65 
66 #endif
67 
Definition: PStream.h:31