]> git.lyx.org Git - lyx.git/blob - src/xtl/graphio.h
fix typo that put too many include paths for most people
[lyx.git] / src / xtl / graphio.h
1 /*
2  * Automatic object graph externalization for XTL
3  *
4  * Copyright (C) 1998-2000 Jose' Orlando Pereira, jop@di.uminho.pt
5  */
6 /* XTL - eXternalization Template Library - http://gsd.di.uminho.pt/~jop/xtl
7  * Copyright (C) 1998-2000 Jose' Orlando Pereira, Universidade do Minho
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  * 
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the Free
21  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22  * MA 02111-1307, USA
23  *
24  * Id: graphio.h 1.8 Fri, 05 May 2000 18:57:58 +0100 jop 
25  */
26
27 #ifndef __XTL_GRAPHIO
28 #define __XTL_GRAPHIO
29
30 #include <map>
31
32 class graph_refs {
33  private:
34         int label;
35
36         typedef std::map<void*,int> trans_type;
37         trans_type trans;
38
39  public:
40         graph_refs(): label(1) {}
41
42         template <class Format, class Refs, class T>
43         void reference(obj_input<Format, Refs>& stream, T*& ptr) {
44                 int x;
45                 stream.simple(x);
46                 if (x==0) {
47                         ptr=new T;
48                         trans.insert(pair<void*,int>(label, (void*)ptr));
49                         label++;
50                         stream.content(*ptr);
51                 } else 
52                         ptr=(T*)trans[x];
53         }
54
55         template <class Format, class Refs, class T>
56         void reference(obj_output<Format, Refs>& stream, T const* ptr) {
57                 trans_type::iterator i=trans.find((void*)ptr);
58                 if (i!=trans.end())
59                         stream.simple((*i).second);
60                 else {
61                         stream.simple(0);
62                         trans.insert(std::pair<void*,int>((void*)ptr, label));
63                         int tmp=label;
64                         label++;
65                         stream.content(*ptr);
66                 }
67         }
68 };
69
70 #endif
71