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

📄 databasepointer.cpp

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

#include "DatabasePointer.h"
#include "ItemDatabase.h"
#include "PlayerDatabase.h"
#include "RoomDatabase.h"
#include "EnemyDatabase.h"



// ======================================================
// This is the DATABASEPOINTERIMPL 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 DATABASEPOINTERIMPL( pt, t, db )                \
t& pt::operator*()                                      \
{                                                       \
    return db::get( m_id );                             \
}                                                       \
                                                        \
t* pt::operator->()                                     \
{                                                       \
    return &( db::get( m_id ) );                        \
}                                                       \
                                                        \
pt::operator t*()                                       \
{                                                       \
    if( m_id == 0 )                                     \
        return 0;                                       \
    return &( db::get( m_id ) );                        \
}



namespace SimpleMUD
{

DATABASEPOINTERIMPL( player, Player, PlayerDatabase )
DATABASEPOINTERIMPL( item, Item, ItemDatabase )
DATABASEPOINTERIMPL( room, Room, RoomDatabase )
DATABASEPOINTERIMPL( enemy, Enemy, EnemyDatabase)
DATABASEPOINTERIMPL( enemytemplate, EnemyTemplate, EnemyTemplateDatabase )

} // end namespace SimpleMUD

⌨️ 快捷键说明

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