1 /*
2  *	patchdir.h
3  *	Patch_dir class
4  *	AYM 1999-11-25
5  */
6 
7 
8 /*
9 This file is part of Yadex.
10 
11 Yadex incorporates code from DEU 5.21 that was put in the public domain in
12 1994 by Rapha�l Quinet and Brendon Wyber.
13 
14 The rest of Yadex is Copyright � 1997-2003 Andr� Majorel and others.
15 
16 This program is free software; you can redistribute it and/or modify it under
17 the terms of the GNU General Public License as published by the Free Software
18 Foundation; either version 2 of the License, or (at your option) any later
19 version.
20 
21 This program is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License along with
26 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
27 Place, Suite 330, Boston, MA 02111-1307, USA.
28 */
29 
30 
31 #ifndef YH_PATCHDIR
32 #define YH_PATCHDIR
33 
34 
35 #include <map>
36 
37 
38 /*
39  *	Patch_dir
40  *
41  *	The purpose of this class is to hide the details of how
42  *	patches are stored in the wads from Yadex. It provides
43  *	two basic services :
44  *
45  *	- refresh()	Must be called every time the directory
46  *			changes in any way.
47  *
48  *	- loc_by_name()	Return the lump location (WadPtr,
49  *			offset, length) of a patch by name. Used
50  *			by the patch browser. If the patch does
51  *			not exist, returns a NULL WadPtr.
52  *
53  *	- loc_by_num()	Return the lump location (WadPtr,
54  *			offset, length) of a patch by number (as
55  *			in TEXTURE[12]). Used by the texture
56  *			browser. If the patch does not exist,
57  *			returns a NULL WadPtr.
58  *
59  *	- list()	Return a Patch_list object that provides
60  *			what InputNameFromListWithFunc() needs
61  *			to browse the patches. I suggest that
62  *			this object be created immediately
63  *			before it's needed and destroyed
64  *			immediately after because it is not
65  *			intended to remain valid across calls to
66  *			refresh(). Ignoring this advice will
67  *			cause some interesting crashes.
68  *
69  *	The lifetime of this class is about the same as the
70  *	lifetime of Yadex itself. It is instantiated only once.
71  *	After construction, it is "empty". You must call
72  *	refresh() to really initialize it (and call it again
73  *	every time the directory changes in any way or you'll
74  *	get strange results--or worse).
75  */
76 
77 struct Pllik
78 {
79   Pllik (const char *name);
80   wad_pic_name_t _name;
81 };
82 
83 struct Pllik_less
84 {
85   bool operator() (const Pllik& p1, const Pllik& p2) const;
86 };
87 
88 typedef std::map<Pllik, Lump_loc, Pllik_less> Patch_lumps_map;
89 
90 class Patch_list
91 {
92   public :
93     Patch_list ();
94     ~Patch_list ();
95     const char **data ();
96     size_t size ();
97     void set (Patch_lumps_map& patch_lumps);
98     void clear ();
99 
100   private :
101     char **array;
102     size_t nelements;
103 };
104 
105 class Patch_dir
106 {
107   public :
108     Patch_dir ();
109     ~Patch_dir ();
110     void refresh (MDirPtr master_dir);
111     void loc_by_name (const char *name, Lump_loc& loc);
112     void loc_by_num (i16 num, Lump_loc& loc);
113     wad_pic_name_t *name_for_num (i16 num);
114     void list (Patch_list& pl);
115 
116   private :
117     char *pnames;			// The contents of PNAMES
118     					// (block of npnames x 8 chars)
119     size_t npnames;			// Number of entries in PNAMES
120     Patch_lumps_map patch_lumps;	// List of patch lumps, sorted
121     					// by name (no duplicates), with
122 					// their location.
123 };
124 
125 
126 extern Patch_dir patch_dir;		// Only one instance and it's global
127 
128 
129 #endif  /* DO NOT ADD ANYTHING AFTER THIS LINE */
130