ruoju's profileRuoju's PRESENTPhotosBlogListsMore Tools Help

Ruoju's PRESENT

Live, as though it was your last day; love, as though you had never loved.

ruoju liu

No list items have been added yet.
May 12

回忆昨天,展望明天

晕,已经12点过了啊
就当现在是周一深夜吧
 
昨天和老乡mm去可口可乐
为我在Atlanta的生活画上圆满的句号:)
只可惜相机照了十张相片就没电了。。。。
不过从仅有的几张pp中就能看出他的风格
色彩绚烂+历史悠久+时尚现代
宣扬happiness和share
 
最有意思的是品尝5大洲的可口可乐产品
发现自己超喜欢欧洲版的peach tea,还有非洲的几种口味:)
反而不喜欢亚洲和美洲的了
喝完一圈后再喝classic和diet已经变味了!
 
还有很多好玩的
大白熊和我拍照时把我脸捂住,超可耐
看4D电影寻找secret recipe
回顾各个时期各个地域的coke commercial
每人都可以得到生产线展示室里刚下线的瓶装coke
 
赶紧进入展望明天,困了。。。
明天的任务就是在relocation工作人员的帮助下租好apartment
在Plantation正式落户:)
May 01

mentor的蛋糕

刚才收到mentor送的蛋糕
上面写着“Good job  Ruoju”
好惊喜啊!
 
明天是我在Motorola实习的ending date
明天晚上参加Georgia Tech毕业典礼
 
从明晚开始,我将是Georgia Tech Alumna
从5月18日起,我将是Motorola Full-time Employee
热烈庆祝!

bless perl [zz]


  • bless有两个参数:对象的引用、类的名称。
  • 类的名称是一个字符串,代表了类的类型信息,这是理解bless的关键。
  • 所谓bless就是把 类型信息 赋予 实例变量。


程序包括5个文件:
person.pm :实现了person类
dog.pm :实现了dog类
bless.pl : 正确的使用bless
bless.wrong.pl : 错误的使用bless
bless.cc : 使用C++语言实现了与bless.pl相同功能的代码


person.pm


#!/usr/bin/perl -w
package person;
use strict;

sub sleep() {
        my ($self) = @_;
        my $name = $self->{"name"};

        print("$name is person, he is sleeping\n");
}

sub study() {
        my ($self) = @_;
        my $name = $self->{"name"};

        print("$name is person, he is studying\n");
}
return 1;


dog.pm


#!/usr/bin/perl -w
package dog;
use strict;

sub sleep() {
        my ($self) = @_;
        my $name = $self->{"name"};

        print("$name is dog, he is sleeping\n");
}

sub bark() {
        my ($self) = @_;
        my $name = $self->{"name"};

        print("$name is dog, he is barking\n");
}

return 1;


bless.pl


#!/usr/bin/perl =w
use strict;
use person;
use dog;

sub main()
{
        my $object = {"name" => "tom"};

        # 先把"tom"变为人
        bless($object, "person");
        $object->sleep();
        $object->study();

        # 再把"tom"变为狗
        bless($object, "dog");
        $object->sleep();
        $object->bark();

        # 最后,再把"tom"变回人
        bless($object, "person");
        $object->sleep();
        $object->study();
}

&main();

# 程序运行时输出:
# tom is person, he is sleeping
# tom is person, he is studying
# tom is dog, he is sleeping
# tom is dog, he is barking
# tom is person, he is sleeping
# tom is person, he is studying


bless.wrong.pl


#!/usr/bin/perl =w
use strict;
use person;
use dog;

sub main()
{
        my $object = {"name" => "tom"};

        # 没有把类型信息和$object绑定,因此无法获知$object有sleep方法
        $object->sleep();
        $object->study();
}

&main();

# 程序运行输出为:
# Can't call method "sleep" on unblessed reference at bless.wrong.pl line 10.


使用c++实现bless的功能

c中的代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct object {
        char name[16];
};

struct person {
        char name[16];

        void sleep() { printf("%s is person, he is sleeping\n", this->name); }
        void study() { printf("%s is person, he is studying\n", this->name); }
};

struct dog {
        char name[16];

        void sleep() { printf("%s is dog, he is sleeping\n", this->name); }
        void bark() { printf("%s is dog, he is barking\n", this->name); }
};

#define bless(object, type) ((type*) object)

int main()
{
        struct object * o = (struct object *) malloc(sizeof(struct object));
        strcpy(o->name, "tom");

        // 先把"tom"变为人
        bless(o, person)->sleep();
        bless(o, person)->study();

        // 再把"tom"变为狗
        bless(o, dog)->sleep();
        bless(o, dog)->bark();

        // 最后,再把"tom"变回人
        bless(o, person)->sleep();
        bless(o, person)->study();
        return 0;
}

// 程序运行时输出:
// tom is person, he is sleeping
// tom is person, he is studying
// tom is dog, he is sleeping
// tom is dog, he is barking
// tom is person, he is sleeping
// tom is person, he is studying

关键的地方就是把对象o的类型转变为person类型和dog类型
April 29

考得也太差了吧!!!

  faint!
刚考完一门final
感觉是本小姐学生生涯以来考得最差的一次
该好好面壁思过
都怪自己完全不care,昨晚才开始复习。。。。
 
讽刺的是本小姐即将结束学生生涯
幸亏明天那门final才是真正的final中的final
啥都不说了
赶紧复习
那门还是相对有谱些的
之前quiz2,3都得了满分
sigh,不能这样想啊。。。
quiz4就是因为极度自大不复习
搞了个刚过平均分。。。
啥都不说了
赶紧复习
 
 
April 22

ANSI 和 UNICODE 的函数对应表【转】

ANSI        UNICODE           通用
(char.h)    (wchar.h)        (tchar.h)

char         wchar_t          TCHAR
char *       wchar_t *        PTCHAR (PTSTR,LPWSTR,PWSTR,WCHAR)

printf       wprintf         _tprintf
scanf       wscanf           _tscanf

atoi         _wtoi           _ttoi
atol         _wtol           _ttol
itoa         _itow           _itot
ltoa         _ltow           _ltot

atof         _wtof           _tstof

strlen       wcslen          _tcslen
strcat       wcscat          _tcscat
strcpy      wcscpy           _tcscpy
strcmp     wcscmp            _tcscmp

补充:

宽字符 和 字符 转换
char to  wchar:
mbstowcs(
   wchar_t* wcstr,
   const char* mbstr,
   size_t count
);
wchar to char:
size_t wcstombs( char *mbstr, const wchar_t *wcstr, size_t count );

第一个就是宽字符到多字节字符转换函数,函数原型如下:
int WideCharToMultiByte(
UINT CodePage,
DWORD dwFlags,
LPCWSTR lpWideCharStr,
int cchWideChar,
LPSTR lpMultiByteStr,
int cbMultiByte,
LPCSTR lpDefaultChar,
LPBOOL lpUsedDefaultChar
);

此函数把宽字符串转换成指定的新的字符串,如ANSI,UTF8等,新字符串不必是多字节字符集。参数:
CodePage: 指定要转换成的字符集代码页,它可以是任何已经安装的或系统自带的字符集,你也可以使用如下所示代码页之一。
CP_ACP 当前系统ANSI代码页
CP_MACCP 当前系统Macintosh代码页
CP_OEMCP 当前系统OEM代码页,一种原始设备制造商硬件扫描码
CP_SYMBOL Symbol代码页,用于Windows 2000及以后版本,我不明白是什么
CP_THREAD_ACP 当前线程ANSI代码页,用于Windows 2000及以后版本,我不明白是什么
CP_UTF7 UTF-7,设置此值时lpDefaultChar和lpUsedDefaultChar都必须为NULL
CP_UTF8 UTF-8,设置此值时lpDefaultChar和lpUsedDefaultChar都必须为NULL
我想最常用的应该是CP_ACP和CP_UTF8了,前者将宽字符转换为ANSI,后者转换为UTF8。
dwFlags: 指定如何处理没有转换的字符, 但不设此参数函数会运行的更快一些,我都是把它设为0。 可设的值如下表所示:
WC_NO_BEST_FIT_CHARS 把不能直接转换成相应多字节字符的Unicode字符转换成lpDefaultChar指定的默认字符。也就是说,如果把Unicode转换成多字节字符,然后再转换回来,你并不一定得到相同的Unicode字符,因为这期间可能使用了默认字符。此选项可以单独使用,也可以和其他选项一起使用。
WC_COMPOSITECHECK 把合成字符转换成预制的字符。它可以与后三个选项中的任何一个组合使用,如果没有与他们中的任何一个组合,则与选项WC_SEPCHARS相同。
WC_ERR_INVALID_CHARS 此选项会致使函数遇到无效字符时失败返回,并且GetLastError会返回错误码ERROR_NO_UNICODE_TRANSLATION。否则函数会自动丢弃非法字符。此选项只能用于UTF8。
WC_DISCARDNS 转换时丢弃不占空间的字符,与WC_COMPOSITECHECK一起使用
WC_SEPCHARS 转换时产生单独的字符,此是默认转换选项,与WC_COMPOSITECHECK一起使用
WC_DEFAULTCHAR 转换时使用默认字符代替例外的字符,(最常见的如'?'),与WC_COMPOSITECHECK一起使用。
当指定WC_COMPOSITECHECK时,函数会将合成字符转换成预制字符。合成字符由一个基字符和一个不占空间的字符(如欧洲国家及汉语拼音的音标)组成,每一个都有不同的字符值。预制字符有一个用于表示基字符和不占空间字符的合成体的单一的字符值。
当指定WC_COMPOSITECHECK选项时,也可以使用上表列出的最后3个选项来定制预制字符的转换规则。这些选项决定了函数在遇到宽字符串的合成字符没有对应的预制字符时的行为,他们与WC_COMPOSITECHECK一起使用,如果都没有指定,函数默认WC_SEPCHARS。
对于下列代码页,dwFlags必须为0,否则函数返回错误码ERROR_INVALID_FLAGS。
50220 50221 50222 50225 50227 50229 52936 54936 57002到57011 65000(UTF7) 42(Symbol)
对于UTF8,dwFlags必须为0或WC_ERR_INVALID_CHARS,否则函数都将失败返回并设置错误码ERROR_INVALID_FLAGS,你可以调用GetLastError获得。

lpWideCharStr: 待转换的宽字符串。
cchWideChar: 待转换宽字符串的长度,-1表示转换到字符串结尾。
lpMultiByteStr: 接收转换后输出新串的缓冲区。
cbMultiByte: 输出缓冲区大小,如果为0,lpMultiByteStr将被忽略,函数将返回所需缓冲区大小而不使用lpMultiByteStr。
lpDefaultChar: 指向字符的指针, 在指定编码里找不到相应字符时使用此字符作为默认字符代替。 如果为NULL则使用系统默认字符。对于要求此参数为NULL的dwFlags而使用此参数,函数将失败返回并设置错误码ERROR_INVALID_PARAMETER。
lpUsedDefaultChar:开关变量的指针,用以表明是否使用过默认字符。对于要求此参数为NULL的dwFlags而使用此参数,函数将失败返回并设置错误码ERROR_INVALID_PARAMETER。lpDefaultChar和lpUsedDefaultChar都设为NULL,函数会更快一些。
返回值: 如果函数成功,且cbMultiByte非0,返回写入lpMultiByteStr的字节数(包括字符串结尾的null);cbMultiByte为0,则返回转换所需字节数。函数失败,返回0。
注意:函数WideCharToMultiByte使用不当,会给影响程序的安全。调用此函数会很容易导致内存泄漏,因为lpWideCharStr指向的输入缓冲区大小是宽字符数,而lpMultiByteStr指向的输出缓冲区大小是字节数。为了避免内存泄漏,应确保为输出缓冲区指定合适的大小。我的方法是先使cbMultiByte为0调用WideCharToMultiByte一次以获得所需缓冲区大小,为缓冲区分配空间,然后再次调用WideCharToMultiByte填充缓冲区,详见下面的代码。另外,从Unicode UTF16向非Unicode字符集转换可能会导致数据丢失,因为该字符集可能无法找到表示特定Unicode数据的字符。

wchar_t* pwszUnicode = "Holle, word! 你好,中国! ";
int iSize;
char* pszMultiByte;

iSize = WideCharToMultiByte(CP_ACP, 0, pwszUnicode, -1, NULL, 0, NULL, NULL);
pszMultiByte = (char*)malloc((iSize+1)/**sizeof(char)*/);
WideCharToMultiByte(CP_ACP, 0, pwszUnicode, -1, pszMultiByte, iSize, NULL, NULL);

第二个是多字节字符到宽字符转换函数,函数原型如下:
int MultiByteToWideChar(
UINT CodePage,
DWORD dwFlags,
LPCSTR lpMultiByteStr,
int cbMultiByte,
LPWSTR lpWideCharStr,
int cchWideChar
);

此函数把多字节字符串转换成宽字符串(Unicode),待转换的字符串并不一定是多字节的。
此函数的参数,返回值及注意事项参见上面函数WideCharToMultiByte的说明,这里只对dwFlags做简单解释。
dwFlags: 指定是否转换成预制字符或合成的宽字符,对控制字符是否使用像形文字,以及怎样处理无效字符。
MB_PRECOMPOSED 总是使用预制字符,即有单个预制字符时,就不会使用分解的基字符和不占空间字符。此为函数的默认选项,不能和MB_COMPOSITE合用 MB_COMPOSITE 总是使用分解字符,即总是使用基字符+不占空间字符的方式
MB_ERR_INVALID_CHARS 设置此选项,函数遇到非法字符就失败并返回错误码ERROR_NO_UNICODE_TRANSLATION,否则丢弃非法字符
MB_USEGLYPHCHARS 使用像形字符代替控制字符
对于下列代码页,dwFlags必须为0,否则函数返回错误码ERROR_INVALID_FLAGS。
50220 50221 50222 50225 50227 50229 52936 54936 57002到57011 65000(UTF7) 42(Symbol)
对于UTF8,dwFlags必须为0或MB_ERR_INVALID_CHARS,否则函数都将失败并返回错误码ERROR_INVALID_FLAGS。
以下函数我没用过,只简要说明之。
int GetTextCharset( HDC hdc );
此函数获取当前选进的设备描述表的字符集,等同于GetTextCharsetInfo(hdc, NULL, 0)。
返回值: 成功返回字符集标识,失败返回DEFAULT_CHARSET。

 
Miami  
Photo 1 of 12
感谢访问!
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.
有意今天来这里,留下祝福:菊姐生日快乐!盼早日相见!
Nov. 14
vivianwrote:
我也想你了:)
Aug. 24
wrote:
juju,想你了呢!!!!!~~~~
 
July 23
就要离开学校了,以后可能不能常来你的space咯,将来有机会的话,好好聚聚吧!
June 26
姐姐我到法国了 粉粉想念你呢
June 16
No list items have been added yet.