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

📄 class.h

📁 网络游戏通用架构, 这是基于boost和libevent写的一个程序
💻 H
字号:
#ifndef CLASS_H
#define CLASS_H

#include <stddef.h>
#include <string>

using namespace std;
#include <boost/program_options.hpp>

using namespace boost::program_options;

#include "common.h"


class EXPORT ClassInterface
{
    friend class Factory;
public:
    ClassInterface( const string& __name ) : _name(__name), _type(NULL) {};
    virtual ~ClassInterface() {};
public:
    virtual void* newInstance(void) =0;
    int getType(void) const
    {
        return *_type;
    }
    const string& getName(void) const
    {
        return _name;
    }
protected:
    void register_type( options_description& __opt_desc )
    {
        __opt_desc.add_options()
            ( _name.c_str(), value<int>(_type)->default_value(0), "" )
        ;
    }
    void setType( int __type )
    {
        *_type= __type;
    }
protected:
    int* _type;
    const string _name;
};

template< typename CLASS >
class EXPORT Class : public ClassInterface
{
public:
    Class( const string& __name ) : ClassInterface(__name)
    {
        _type= CLASS::getTypePtr();
    }
    ~Class() {}
public:
    void* newInstance(void)
    {
        CLASS* obj= NULL;
        try{
            obj= new CLASS;
        }catch( exception& e ){
            cerr << "Create object failed: " << _name << "\t(" << e.what() << ")" << endl;
            obj= NULL;
        }catch( ... ){
            cerr << "Create object failed: " << _name << "\t(" << "Unknown exception" << ")" << endl;
            obj= NULL;
        }
        return obj;
    };
};


#endif

⌨️ 快捷键说明

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