/[pearpc]/src/tools/atom.cc
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /src/tools/atom.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Wed Sep 5 17:11:21 2007 UTC (11 years, 10 months ago) by dpavlin
File size: 1633 byte(s)
import upstream CVS
1 /*
2 * HT Editor
3 * atom.cc
4 *
5 * Copyright (C) 1999-2002 Stefan Weyergraf
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "atom.h"
22 #include "data.h"
23
24 #include <cstring>
25
26 //static
27 AVLTree atoms(true);
28
29 class Atom: public Object {
30 public:
31 uint id;
32 void *value;
33
34 Atom(uint i, void *v)
35 {
36 id = i;
37 value = v;
38 }
39
40 int compareTo(const Object *obj) const
41 {
42 Atom *a = (Atom*)obj;
43 return id - a->id;
44 }
45 };
46
47 void *getAtomValue(uint id)
48 {
49 if (id != invalid_atom_id) {
50 Atom a(id, NULL);
51 Atom *f = (Atom*)atoms.get(atoms.find(&a));
52 if (f) return f->value;
53 }
54 return NULL;
55 }
56
57 uint getAtomId(void *value)
58 {
59 if (value) {
60 foreach(Atom, a, atoms,
61 if (a->value == value) return a->id;
62 );
63 }
64 return invalid_atom_id;
65 }
66
67 #include "debug.h"
68 bool registerAtom(uint id, void *value)
69 {
70 ASSERT(value);
71 atoms.insert(new Atom(id, value));
72 return true;
73 }
74
75 bool unregisterAtom(uint id)
76 {
77 Atom a(id, NULL);
78 atoms.delObj(&a);
79 return true;
80 }
81
82 /*
83 * Module Init/Done
84 */
85
86 bool initAtom()
87 {
88 return true;
89 }
90
91 void doneAtom()
92 {
93 }

  ViewVC Help
Powered by ViewVC 1.1.26