⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 databasepointer.h

📁 MUD游戏编程光盘代码
💻 H
字号:
// MUD Programming
// Ron Penton
// (C)2003
// DatabasePointer.h - A "smart" pointer class that looks up items in a database
// 
// 

#ifndef SIMPLEMUDDATABASEPOINTER_H
#define SIMPLEMUDDATABASEPOINTER_H

#include <iostream>
#include "Entity.h"

using std::ostream;
using std::istream;


// ======================================================
// This is the DATABASEPOINTER macro, which defines a 
// database pointer proxy class. Why macros? Because
// I've learned that templates + circular dependencies
// are a VERY BAD combination when dealing with simple
// one pass compilers, like C++.
// ======================================================
#define DATABASEPOINTER( pt, t )                        \
class t;                                                \
class pt                                                \
{                                                       \
public:                                                 \
    pt( entityid p_id = 0 )                             \
        : m_id( p_id ) {}                               \
                                                        \
    pt& operator=( entityid p_id )                      \
    {                                                   \
        m_id = p_id;                                    \
        return *this;                                   \
    }                                                   \
                                                        \
    operator entityid()                                 \
    {                                                   \
        return m_id;                                    \
    }                                                   \
                                                        \
    t& operator*();                                     \
    t* operator->();                                    \
    operator t*();                                      \
                                                        \
    entityid m_id;                                      \
};                                                      \
                                                        \
inline ostream& operator<<( ostream& s, const pt& p )   \
{                                                       \
    s << p.m_id;                                        \
    return s;                                           \
}                                                       \
                                                        \
inline istream& operator>>( istream& s, pt& p )         \
{                                                       \
    s >> p.m_id;                                        \
    return s;                                           \
}




namespace SimpleMUD
{

DATABASEPOINTER( player, Player )
DATABASEPOINTER( item, Item )
DATABASEPOINTER( room, Room )

} // end namespace SimpleMUD

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -