首  页 | 资讯中心 | 网络学院 | 天新汽车 | 天新手机 | 天新游戏 | 软件开发 | 考试认证
品 牌 机 | 笔 记 本 | 服 务 器 | 天新数码 - DC - DV - MP3 - MP4 - GPS - TV | 数字家庭
硬件 DIY - 主板 - CPU - 内 存 - 硬 盘 - 显示器 - 显卡 - 光驱 - 机箱 - 键鼠 - 网络设备
办公设备 | 打 印 机 | 扫 描 仪 | 投 影 仪 | 一 体 机 | 传 真 机 | 路 由 器 | 交 换 机
软件下载 | 驱动下载 | 游戏下载 | 源码下载 | 教程下载 | 站长在线 | 产品中心 | 报价中心
开发首页 | 开发语言 | .Net开发 | Java开发 | Web开发 | 数据库开发 | 移动开发 | 游戏开发 | 企业开发 | 操作系统 | 软件工程
VB VC Delphi PB BCB C++ - ASP.net C# VB.net - J2EE J2SE J2ME EJB - ASP PHP JSP CGI - MSSQL Oracle DB2 MySQL - CodingLife
  您现在的位置:天新网 > 软件开发 > 游戏开发
Nebula2探秘05-RTTI
http://dev.21tx.com 2007年05月07日 happykevins

每日文章精萃
.Net:向SQL Server数据库添加图片和文字 Java:MySQL入门学习(1)
ASP:一个不太让人讨厌的自动弹出窗口 PHP:简单的页面缓冲技术(三)
JSP:JSP由浅入深(4-1) CGI:用Perl制作留言本实例之三
VB:在图像上建立光源(有点类似于在图像 VC:Win32环境下dll编程原理

Nebula2探秘05-RTTI

happykevins文 

       Nebula2的RTTI支持都是在nObject这一层实现的,每个继承自nObject的类都有IsA()和IsInstanceof()两个方法,前者用于判断继承关系,后者则用于判断一个对象是否为指定类的实例,下面的代码说明了他们的用法。

 

Word-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
/****************************************************************************/
/*    Nebula2 - Tutorial 05                                                    */
/*  Nebula2 RTTI                                                            */
/*  author: happykevins                                                        */
/****************************************************************************/

///----------------------------------------------------------------------------
/// +必要头文件
#include "kernel/nkernelserver.h"
#include 
"kernel/ntimeserver.h"
#include 
"kernel/nfileserver2.h"
/// -必要头文件
///----------------------------------------------------------------------------

///----------------------------------------------------------------------------
/// +链接库
#pragma comment(lib, "wsock32.lib")
#pragma comment(lib, "d_nkernel.lib")
/// -链接库
///----------------------------------------------------------------------------

///----------------------------------------------------------------------------
/// +Application
int main(int argc, const char** argv)
{
    
/// 创建KernelServer
    nKernelServer* ks = n_new(nKernelServer);

    
///----------------------------------------------------------------------------
    
/// +Nebula2 RTTI Test
    
/// @note:
    
///        Nebula2 RTTI implement mostly depends on nClass && nObject

    
/// firstly: we got some instance (all inherited from nObject)
    nRoot* nroot = (nRoot*)ks->New("nroot");
    nObject
* nobject = (nObject*)ks->New("nobject");
    nTimeServer
* ntimeserver = (nTimeServer*)ks->Lookup("/sys/servers/time");
    nFileServer2
* nfileserver2 = (nFileServer2*)ks->Lookup("/sys/servers/file2");

    
/// secondly: Test RTTI Info.
    
/// use 'IsA' & 'IsInstanceOf' methods

    
// 1. nroot is a nroot?
    n_printf("[%s] is %s [%s] "
        nroot
->GetClass()->GetName(), 
        nroot
->IsA("nroot"? "\b" : "not"
        
"nroot");
    
// 2. nroot is a nobject?
    n_printf("[%s] is %s [%s] "
        nroot
->GetClass()->GetName(), 
        nroot
->IsA(ks->FindClass("nobject")) ? "\b" : "not"
        
"nobject");
    
// 3. nobject is a nroot?
    n_printf("[%s] is %s [%s] "
        nobject
->GetClass()->GetName(), 
        nobject
->IsA("nroot"? "\b" : "not"
        
"nroot");
    
// 4. ntimerserver is a nroot?
    n_printf("[%s] is %s [%s] "
        ntimeserver
->GetClass()->GetName(), 
        ntimeserver
->IsA("nroot"? "\b" : "not"
        
"nroot");
    
// 5. nroot is instance of nroot?
    n_printf("[%s] is %s instance of [%s] "
        nroot
->GetClass()->GetName(), 
        nroot
->IsInstanceOf(ks->FindClass("nroot")) ? "\b" : "not"
        
"nroot");
    
// 6. nroot is instance of nobject?
    n_printf("[%s] is %s instance of [%s] "
        nroot
->GetClass()->GetName(), 
        nroot
->IsInstanceOf(ks->FindClass("nobject")) ? "\b" : "not"
        
"nobject");
    
// 7. nfileserver2 is a nobject?
    n_printf("[%s] is %s [%s] "
        nfileserver2
->GetClass()->GetName(), 
        nfileserver2
->IsA("nobject"? "\b" : "not"
        
"nobject");
    
// 8. nfileserver2 is a ntimeserver?
    n_printf("[%s] is %s [%s] "
        nfileserver2
->GetClass()->GetName(), 
        nfileserver2
->IsA("ntimeserver"? "\b" : "not"
        
"ntimeserver");
    
    
/// +Nebula2 RTTI Test
    
///----------------------------------------------------------------------------
    

    
/// 销毁KernelServer
    n_delete(ks);

    getchar();
    
return 0;
}
/// -Application
///----------------------------------------------------------------------------

上一篇: Nebula2探秘10-Signal System
下一篇: Nebula2探秘11-Simple Window

编辑推荐
相关内容
·基于Nokia手机的移动游戏开发步步通(五)
·模拟布料运算之后的心得介绍。
·游戏引擎剖析(十一)
·泛型粒子系统的设计6
·泛型粒子系统的设计5
·《Windows游戏编程大师技巧》(第二版)前
·《Windows游戏编程大师技巧》(第二版)第1
·《Windows游戏编程大师技巧》(第二版)第1
·《Windows游戏编程大师技巧》(第二版)第2
·GBA程序开发入门2
·向量几何在游戏编程中的使用1
·玩家狂想曲《红警与上帝》
·DirectX 下面的多窗口
·[分形几何,AS2]L系统编程的实现
·flash网游开发日志
·[计算机模拟]元胞自动机[CA]初探---“生命
·OpenGL中的矩阵存储方式
·如何投影一个纹理
·从数据结构“图”,到游戏地图寻径,从《星
·GBA程序开发入门3
最近更新
人气最热
·Nebula2探秘10-Signal System
·Nebula2探秘11-Simple Window
·解析XML的利器-TinyXML
·Nebula2探秘13-输入管理器nInputServer
·Nebula2探秘12-基于Windows命令行的Nebula
·向量几何在游戏编程中的使用6
·3D角色动画
·3D 中的方位 (读书笔记)
·做QQ桌球游戏外挂——求游戏中的彩球圆心坐
·GLSL基础教程(一)
·PhysX SDK物理引擎开发包使用教程
·游戏策划全接触之游戏剧本篇-----原创
·基于LOD的大规模真实感室外场景实时渲染技
·GBA程序开发入门3
·The Art of Computer Game Design--ACKNOWL
·图形学-降噪技术-2维中值滤波
·模拟布料运算之后的心得介绍。
·游戏中输入的处理
·Java 2游戏编程读书笔记(3)
·DXUT 框架入门 1

 
·[硬件]省钱又省电 LG节能王液晶显示器绝杀139
·[数码]别出心裁 联想推出全新提包型彩屛MP3
·[汽车]奥迪车手艾士唐荣膺瑞典皇家“金奖”
·[开发]如何成为一名JAVA初级程序员
·[资讯]图:日本推出可储存DVD数字视频的摄像
·[游戏][新天地]开启“妹儿”惊喜等着你
·[本本]不降反升 3999元宏碁AS3053上市涨200
·[办公]HP Laser Jet 8100定影组件分解
·[手机]2011年全球近4分之1手机售价将低于20美
·[考试]2005年下半年网络工程师下午试题及答案
·[学院]轻松操作 Windows XP系统中文输入法技
·[娱乐]乒乓对决
 

关于我们 | 联系我们 | 广告服务 | 工作机会 | 版权声明 | 欢迎投稿 | 网站地图
Copyright © 2000-2008 , www.21tx.com , All Rights Reserved .
© 晨新科技 版权所有 Created by TXSite.net