35
/*********************
41
* THIS FILE SHOULD BE EDITED EACH TIME A NEW PACKET TYPE IS CREATED!
43
* For each packet type there should be a line of the form:
45
* REGISTER_PACKET(class, type, name)
48
* class = the C++ class representing this packet type;
49
* type = the integer ID of the new packet type;
50
* name = the string (English) name of the new packet type.
52
* The appropriate include files should also be placed with full path
53
* and without full path in the appropriate include sections below.
55
* To use the packet registry, simply #include this file. If you have
56
* not defined __PACKET_REGISTRY_BODY, only the include sections will
57
* be brought in. If you have defined __PACKET_REGISTRY_BODY, the
58
* include sections will be skipped and the REGISTER_PACKET lines
59
* will be brought in instead. By suitably defining the macro
60
* REGISTER_PACKET before including this file, you can have these
61
* lines do whatever you wish.
63
* If you do #include this file, be sure to #undef both
64
* REGISTER_PACKET and __PACKET_REGISTRY_BODY when you are
65
* finished, so that if --enable-final is being used then these
66
* macros are left undefined for the following files.
70
* When selecting an integer ID for your new packet type, the following
71
* guidelines should be adhered to:
73
* 1-999: Reserved for use with the official program distribution.
74
* 1000-9999: Reserved for future use.
78
#ifndef __PACKET_REGISTRY_BODY
79
#include "packet/ncontainer.h"
80
#include "packet/ntext.h"
81
#include "triangulation/ntriangulation.h"
82
#include "surfaces/nnormalsurfacelist.h"
83
#include "packet/nscript.h"
84
#include "surfaces/nsurfacefilter.h"
85
#include "angle/nanglestructurelist.h"
86
#include "packet/npdf.h"
87
#include "dim2/dim2triangulation.h"
89
REGISTER_PACKET(NContainer, 1, "Container")
90
REGISTER_PACKET(NText, 2, "Text")
91
REGISTER_PACKET(NTriangulation, 3, "Triangulation")
92
REGISTER_PACKET(NNormalSurfaceList, 6, "Normal Surface List")
93
REGISTER_PACKET(NScript, 7, "Script")
94
REGISTER_PACKET(NSurfaceFilter, 8, "Surface Filter")
95
REGISTER_PACKET(NAngleStructureList, 9, "Angle Structure List")
96
REGISTER_PACKET(NPDF, 10, "PDF")
97
REGISTER_PACKET(Dim2Triangulation, 15, "2-Manifold Triangulation")
100
35
/*! \file packet/packetregistry.h
101
* \brief Contains a registry of packet types known to the engine.
103
* Each time a new packet type is created, this packet registry should be
104
* updated. Instructions regarding how to do this are included in
105
* <i>packetregistry.h</i>, which also contains instructions regarding
106
* how to actually use the packet registry.
108
* See NPacket for further details.
36
* \brief Provides access to a registry of all packet types known to Regina.
38
* Each time a new packet type is created, the file packetregistry-impl.h
39
* must be updated to include it. Instructions on how to do this are
40
* included in packetregistry-impl.h.
42
* External routines can access the registry by calling one of the
43
* forPacket() template functions defined in packetregistry.h.
45
* \warning You should not include this header unless it is necessary,
46
* since it will automatically import every header for every packet type
50
// The old registry macros will silently compile but do nothing.
51
// This could lead to nasty surprises, so throw an error if it looks like
52
// people are still trying to use them.
53
#ifdef __PACKET_REGISTRY_BODY
54
#error "The old REGISTER_PACKET macros have been removed. Use forPacket() instead."
57
#ifndef __PACKETREGISTRY_H
59
#define __PACKETREGISTRY_H
62
#include "packet/packettype.h"
63
#include "utilities/registryutils.h"
73
* Allows the user to call a template function whose template parameter
74
* matches a given value of PacketType, which is not known
75
* until runtime. In essence, this routine contains a switch/case statement
76
* that runs through all possible packet types known to Regina.
78
* The advantages of this routine are that (i) the user does not need to
79
* repeatedly type such switch/case statements themselves; and (ii) if
80
* a new packet type is added then only a small amount of code
81
* needs to be extended to incorporate it.
83
* In detail: the function object \a func must define a templated
84
* unary bracket operator, so that <tt>func(PacketInfo<t>)</tt> is
85
* defined for any valid PacketType enum value \a t. Then,
86
* when the user calls <tt>forPacket(packetType, func, defaultReturn)</tt>,
87
* this routine will call <tt>func(PacketInfo<packetType>)</tt> and pass
88
* back the corresponding return value. If \a packetType does not denote a
89
* valid packet type, then forPacket() will pass back \a defaultReturn instead.
91
* There is also a two-argument variant of forPacket() that works with
94
* \pre The function object must have a typedef \a ReturnType indicating
95
* the return type of the corresponding templated unary bracket operator.
96
* Inheriting from Returns<...> is a convenient way to ensure this.
98
* \ifacespython Not present.
100
* @param packetType the given packet type.
101
* @param func the function object whose unary bracket operator we will
102
* call with a PacketInfo<packetType> object.
103
* @param defaultReturn the value to return if the given packet type
105
* @return the return value from the corresponding unary bracket
106
* operator of \a func, or \a defaultReturn if the given packet type
109
template <typename FunctionObject>
110
typename FunctionObject::ReturnType forPacket(
111
PacketType packetType, FunctionObject func,
112
typename FunctionObject::ReturnType defaultReturn);
115
* Allows the user to call a template function whose template parameter
116
* matches a given value of PacketType, which is not known
117
* until runtime. In essence, this routine contains a switch/case statement
118
* that runs through all possible packet types known to Regina.
120
* The advantages of this routine are that (i) the user does not need to
121
* repeatedly type such switch/case statements themselves; and (ii) if
122
* a new packet type is added then only a small amount of code
123
* needs to be extended to incorporate it.
125
* In detail: the function object \a func must define a templated
126
* unary bracket operator, so that <tt>func(PacketInfo<t>)</tt> is
127
* defined for any valid PacketType enum value \a t. Then,
128
* when the user calls <tt>forPacket(packetType, func)</tt>,
129
* this routine will call <tt>func(PacketInfo<packetType>)</tt> in turn.
130
* If \a packetType does not denote a valid packet type, then forPacket()
133
* There is also a three-argument variant of forPacket() that works with
134
* functions with return values.
136
* \ifacespython Not present.
138
* @param packetType the given packet type.
139
* @param func the function object whose unary bracket operator we will
140
* call with a PacketInfo<packetType> object.
142
template <typename VoidFunctionObject>
143
void forPacket(PacketType packetType, VoidFunctionObject func);
147
} // namespace regina
149
// Import template implementations:
150
#include "packet/packetregistry-impl.h"