1 /*
2 ** autosegs.h
3 ** Arrays built at link-time
4 **
5 **---------------------------------------------------------------------------
6 ** Copyright 1998-2006 Randy Heit
7 ** All rights reserved.
8 **
9 ** Redistribution and use in source and binary forms, with or without
10 ** modification, are permitted provided that the following conditions
11 ** are met:
12 **
13 ** 1. Redistributions of source code must retain the above copyright
14 **    notice, this list of conditions and the following disclaimer.
15 ** 2. Redistributions in binary form must reproduce the above copyright
16 **    notice, this list of conditions and the following disclaimer in the
17 **    documentation and/or other materials provided with the distribution.
18 ** 3. The name of the author may not be used to endorse or promote products
19 **    derived from this software without specific prior written permission.
20 **
21 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 **---------------------------------------------------------------------------
32 **
33 */
34 
35 #ifndef AUTOSEGS_H
36 #define AUTOSEGS_H
37 
38 #include "doomtype.h"
39 
40 #define REGMARKER(x) (x)
41 typedef void *REGINFO;
42 
43 // List of Action functons
44 extern REGINFO ARegHead;
45 extern REGINFO ARegTail;
46 
47 // List of TypeInfos
48 extern REGINFO CRegHead;
49 extern REGINFO CRegTail;
50 
51 // List of properties
52 extern REGINFO GRegHead;
53 extern REGINFO GRegTail;
54 
55 // List of variables
56 extern REGINFO MRegHead;
57 extern REGINFO MRegTail;
58 
59 // List of MAPINFO map options
60 extern REGINFO YRegHead;
61 extern REGINFO YRegTail;
62 
63 class FAutoSegIterator
64 {
65 	public:
FAutoSegIterator(REGINFO & head,REGINFO & tail)66 		FAutoSegIterator(REGINFO &head, REGINFO &tail)
67 		{
68 			// Weirdness. Mingw's linker puts these together backwards.
69 			if (&head <= &tail)
70 			{
71 				Head = &head;
72 				Tail = &tail;
73 			}
74 			else
75 			{
76 				Head = &tail;
77 				Tail = &head;
78 			}
79 			Probe = Head;
80 		}
81 		REGINFO operator*() const NO_SANITIZE
82 		{
83 			return *Probe;
84 		}
85 		FAutoSegIterator &operator++() NO_SANITIZE
86 		{
87 			do
88 			{
89 				++Probe;
90 			} while (*Probe == 0 && Probe < Tail);
91 			return *this;
92 		}
Reset()93 		void Reset()
94 		{
95 			Probe = Head;
96 		}
97 
98 	protected:
99 		REGINFO *Probe;
100 		REGINFO *Head;
101 		REGINFO *Tail;
102 };
103 
104 #endif
105