~ubuntu-branches/ubuntu/vivid/regina-normal/vivid

« back to all changes in this revision

Viewing changes to engine/packet/packetregistry.h

  • Committer: Package Import Robot
  • Author(s): Ben Burton
  • Date: 2013-11-02 11:44:32 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20131102114432-acgci6b1pb2hjl8q
Tags: 4.95-1
* New upstream release.
* The python module is now installed in a standard location beneath
  /usr/lib/python2.7/dist-packages.
* Switched python packaging from python-support to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
/* end stub */
34
34
 
35
 
/*********************
36
 
 *
37
 
 *  Packet Registry
38
 
 *  ---------------
39
 
 *
40
 
 *
41
 
 *    THIS FILE SHOULD BE EDITED EACH TIME A NEW PACKET TYPE IS CREATED!
42
 
 *
43
 
 *    For each packet type there should be a line of the form:
44
 
 *
45
 
 *        REGISTER_PACKET(class, type, name)
46
 
 *
47
 
 *    where:
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.
51
 
 *
52
 
 *    The appropriate include files should also be placed with full path
53
 
 *        and without full path in the appropriate include sections below.
54
 
 *
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.
62
 
 *
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.
67
 
 *
68
 
 *    Packet Types:
69
 
 *    ------------
70
 
 *    When selecting an integer ID for your new packet type, the following
71
 
 *        guidelines should be adhered to:
72
 
 *
73
 
 *    1-999:      Reserved for use with the official program distribution.
74
 
 *    1000-9999:  Reserved for future use.
75
 
 *    10000-:     Unreserved.
76
 
 */
77
 
 
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"
88
 
#else
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")
98
 
#endif
99
 
 
100
35
/*! \file packet/packetregistry.h
101
 
 *  \brief Contains a registry of packet types known to the engine.
102
 
 *
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.
107
 
 *
108
 
 *  See NPacket for further details.
109
 
 */
 
36
 *  \brief Provides access to a registry of all packet types known to Regina.
 
37
 *
 
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.
 
41
 *
 
42
 *  External routines can access the registry by calling one of the
 
43
 *  forPacket() template functions defined in packetregistry.h.
 
44
 *
 
45
 *  \warning You should not include this header unless it is necessary,
 
46
 *  since it will automatically import every header for every packet type
 
47
 *  in the registry.
 
48
 */
 
49
 
 
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."
 
55
#endif
 
56
 
 
57
#ifndef __PACKETREGISTRY_H
 
58
#ifndef __DOXYGEN
 
59
#define __PACKETREGISTRY_H
 
60
#endif
 
61
 
 
62
#include "packet/packettype.h"
 
63
#include "utilities/registryutils.h"
 
64
 
 
65
namespace regina {
 
66
 
 
67
/**
 
68
 * \weakgroup packet
 
69
 * @{
 
70
 */
 
71
 
 
72
/**
 
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.
 
77
 *
 
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.
 
82
 *
 
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.
 
90
 *
 
91
 * There is also a two-argument variant of forPacket() that works with
 
92
 * void functions.
 
93
 *
 
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.
 
97
 *
 
98
 * \ifacespython Not present.
 
99
 *
 
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
 
104
 * is not valid.
 
105
 * @return the return value from the corresponding unary bracket
 
106
 * operator of \a func, or \a defaultReturn if the given packet type
 
107
 * is not valid.
 
108
 */
 
109
template <typename FunctionObject>
 
110
typename FunctionObject::ReturnType forPacket(
 
111
        PacketType packetType, FunctionObject func,
 
112
        typename FunctionObject::ReturnType defaultReturn);
 
113
 
 
114
/**
 
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.
 
119
 *
 
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.
 
124
 *
 
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()
 
131
 * will do nothing.
 
132
 *
 
133
 * There is also a three-argument variant of forPacket() that works with
 
134
 * functions with return values.
 
135
 *
 
136
 * \ifacespython Not present.
 
137
 *
 
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.
 
141
 */
 
142
template <typename VoidFunctionObject>
 
143
void forPacket(PacketType packetType, VoidFunctionObject func);
 
144
 
 
145
/*@}*/
 
146
 
 
147
} // namespace regina
 
148
 
 
149
// Import template implementations:
 
150
#include "packet/packetregistry-impl.h"
 
151
 
 
152
#endif
110
153