代码改变世界

Gac代码库分析(1)

2012-12-09 20:27  Clingingboy  阅读(461)  评论(0编辑  收藏  举报

 

基础类:Basic.h

重在学习思想,难得的开源库

简单介绍,猜测意图

一.基本类型

1.NotCopyable

意图:阻止继承子类被拷贝

.h

class NotCopyable
{
private:
    NotCopyable(const NotCopyable&);
    NotCopyable& operator=(const NotCopyable&);
public:
    NotCopyable();
};

.cpp

NotCopyable::NotCopyable()
{
}

NotCopyable::NotCopyable(const NotCopyable&)
{
}

NotCopyable& NotCopyable::operator=(const NotCopyable&)
{
    return *this;
}

2.Error

意图:用于抛错

class Error
{
private:
    wchar_t*            description;
public:
    Error(wchar_t* _description);

    wchar_t*            Description()const;
};

3.Object

意图:学习.net和java等语言,提供一个空的基类

class Object
{
public:
    virtual ~Object();
};

4.ObjectBox

意图:提供一份对象的拷贝

template<typename T>
class ObjectBox : public Object
{
private:
    T                    object;
public:
    ObjectBox(const T& _object)
    {
        object=_object;
    }

    const T& Unbox()
    {
        return object;
    }
};

5.BinaryRetriver

意图:提供一个联合体,minSize为默认最小大小,t一般不会超过其大小

template<typename T, size_t minSize>
union BinaryRetriver
{
    T t;
    char binary[sizeof(T)>minSize?sizeof(T):minSize];
};

demo示例:

const int BinarySize = sizeof(void*)*8;
BinaryRetriver<int*, BinarySize> retriver;
memset(retriver.binary, 0, BinarySize);

6.KeyType

7.POD

8.DateTime

意图:提供时间类的封装

9.Interface

class Interface : private NotCopyable
{
public:
    virtual ~Interface();
};

意图:提供接口基类