万星星@豌豆荚 欢迎加入我们
一个吃软饭的男人!!!!!我只想写程序####
微博:http://weibo.com/wanlianwen
posts - 172,  comments - 1253,  trackbacks - 0

ACDK基于C++的模型(基本类型、接口、对象类,数组,异常,枚举和命名空间)组织了自己的类型模型。

1、基本模型
      基本类型         Object对象封装            位数(bit)
      bool                  Boolean                           8
      char                  Character                        8
      uc2char            UnicodeCharacter            16
      uc4char            UnicodeCharacter            23
      byte                  Byte                                8
      short                 Short                              16
      int                     Integer                            32  
      jlong                 Long                               64
      float                  Float                               32
      double              Double                            64


2、Enum类型
      使用C++的enum,假如需要考虑ACDK的元编译,需要使用宏:ACDK_DECL_ENUM,用来提供元信息。动态库需要导出类型的时候,使用ACDK_DEF_LIB_ENUM。不牵扯到元信息的Enum类型可以在定义的时候使用foreign关键字。

3、对象类型
      必须直接或者间接从Object派生
// declare the R-type RLegalAcdkClass
// and the Array type LegalAcdkClassArray and RLegalAcdkClassArray
ACDK_DECL_CLASS(LegalAcdkClass);
// The class itself:
class LegalAcdkClass : extends acdk::lang::Object    // extend the Object class
{
    ACDK_WITH_METAINFO(LegalAcdkClass);        
// optional, for class information see Metainfo
private:
    RString message;
public:
    
// constructor
    LegalAcdkClass() : Object() , message("")
    
{
    }

    
// a method
    RString getMessage()
    
{
        
return message;
    }

}
;

      不能多继承类,但是可以提供一种更好的办法就是多继承接口。

// declare the R-type RLegalAcdkClass
// and the Array type LegalAcdkClassArray and RLegalAcdkClassArray
ACDK_DECL_CLASS(LegalAcdkClass);
// The class itself:
class LegalAcdkClass : extends acdk::lang::Object // extend the Object class
implements acdk::lang::Comparable // implements the interface
{
    ACDK_WITH_METAINFO(LegalAcdkClass) 
// optional, for class information see Metainfo
private:
    RString message;
public:
    
// implement the Comparable interface method
    int compareTo(IN(RObject) other)
    
{
        
return getMessage()->compareTo(RLegalAcdkClass(other)->getMessage());
    }

    RString getMessage() 
return message; }
}
;

     Class信息

RStringBuffer sb1 = new StringBuffer("ACDK");
        RStringBuffer sb2 
= new StringBuffer("JAVA");
        RClass cls1 
= sb1->getClass();
        RClass cls2 
= sb2->getClass();
        
assert(cls1 == cls2); // always true

    你可以定义不符合acdk规范的类型已经结构等,但是会失去acdk提供的一些特性。


ACDK的异常捕获需要注意:
void foo()
{
try {
}
 catch (acdk::io::RIOException ex) {
// handle here type of IOException.
}
 catch (RThrowable ex) {
// handle all other ACDK exceptions
}

/* DONT DO THAT
otherwise Nullpointer exception will not handled properly
} catch () {
// this are not ACDK exception
// for example std::exception, if you use STL
}
*/

}


方法参数缺省传递方式是:
a、基本类型(int,float,char,etc)按值传递
b、enum按值
c、类和接口按引用传递
d、数组按引用传递

参数的in,out,inout
void foo(IN(RStringBuffer) buffer, int len)
{
    
//buffer = new StringBuffer(); // caller not be effected, RStringBuffer isn't changed
    buffer->append("asdf"); // caller be effected.
    len = 42// caller not be effected
}


// is equivalent to
//void foo(RStringBuffer buffer, int len);
void use_foo()
{
    RStringBuffer sb 
= new StringBuffer("");
    RStringBuffer sbs 
= sb;
    
int value = 1000;
    foo(sb, value);
    
//value == 1000 && sb == sbs
    
// sb->toString() == "ACDK"
}
in参数确保对象引用不会变化;可以传递栈对象

void foo(OUT(RStringBuffer) buffer, OUT(int) len)
{
    
// buffer is unitialized here
    buffer = new StringBuffer(1024);
    
// buffer is now initialed;
    buffer->append("ACDK");
    len 
= buffer->length();
}

RString use_foo()
{
    RStringBuffer sb;
    
int len;
    foo(sb, len);
    System::out
->println("Buffer is [" + sb->toString() + "] len = " + len);
    
return sb->toString();
}
使用out参数,按照引用传参,可以修改传入参数,但是对于进程间不可以传递栈对象。

posted on 2007-12-25 12:24 万连文 阅读(890) 评论(0)  编辑 收藏 引用 所属分类: ACDK

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


简历下载
联系我

<2006年3月>
2627281234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(66)

随笔分类

随笔档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜