template<typename C>
struct CompoundTypeDef
{
- virtual ~CompoundTypeDef() { }
+ virtual ~CompoundTypeDef() = default;
virtual std::string describe() const = 0;
virtual char *serialize(const C &, char *, char *) const = 0;
protected:
unsigned id;
- static unsigned next_class_id;
-
PacketDefBase(unsigned);
public:
- virtual ~PacketDefBase() { }
+ virtual ~PacketDefBase() = default;
+
virtual unsigned get_class_id() const = 0;
unsigned get_id() const { return id; }
virtual std::string describe() const = 0;
private:
CompoundTypeDef<P> *compound;
- static unsigned class_id;
-
public:
PacketTypeDef(unsigned);
~PacketTypeDef();
- static unsigned get_static_class_id() { return class_id; }
- virtual unsigned get_class_id() const { return class_id; }
+ virtual unsigned get_class_id() const { return get_packet_class_id<P>(); }
template<typename S>
void set_serializer(const S &);
~Protocol();
private:
+ static unsigned get_next_packet_class_id();
+
+ template<typename P>
+ static unsigned get_packet_class_id();
+
void add_packet(PacketDefBase *);
protected:
};
+template<typename P>
+unsigned Protocol::get_packet_class_id()
+{
+ static unsigned id = get_next_packet_class_id();
+ return id;
+}
+
template<typename P>
Protocol::PacketDefBuilder<P, Protocol::NullSerializer<P> > Protocol::add(unsigned id)
{
template<typename P>
const Protocol::PacketTypeDef<P> &Protocol::get_packet_by_class() const
{
- const PacketDefBase &pdef = get_packet_by_class_id(PacketTypeDef<P>::get_static_class_id());
+ const PacketDefBase &pdef = get_packet_by_class_id(get_packet_class_id<P>());
return static_cast<const PacketTypeDef<P> &>(pdef);
}
Protocol::PacketTypeDef<P>::PacketTypeDef(unsigned i):
PacketDefBase(i),
compound(new CompoundDef<P, NullSerializer<P> >(NullSerializer<P>()))
-{
- if(!class_id)
- class_id = next_class_id++;
-}
+{ }
template<typename P>
Protocol::PacketTypeDef<P>::~PacketTypeDef()