對(duì)于支持C99標(biāo)準(zhǔn)的編譯器來(lái)說(shuō),可以#include <cstdint>
來(lái)使用 int32_t, 但是目前不少的編譯器都做不到這點(diǎn)
所以,自己寫(xiě)了個(gè)IntType.hpp
1 #ifndef INTTYPE_HPP_
2 #define INTTYPE_HPP_
3
4 #include "Platform.hpp"
5
6 namespace Charlie
7 {
8
9 typedef long long int64_t;
10 typedef int int32_t;
11 typedef short int16_t;
12 typedef char int8_t;
13
14 typedef unsigned long long uint64_t;
15 typedef unsigned int uint32_t;
16 typedef unsigned short uint16_t;
17 typedef unsigned char uint8_t;
18
19 }
20
21 #endif // INTTYPE_HPP_
22
2 #define INTTYPE_HPP_
3
4 #include "Platform.hpp"
5
6 namespace Charlie
7 {
8
9 typedef long long int64_t;
10 typedef int int32_t;
11 typedef short int16_t;
12 typedef char int8_t;
13
14 typedef unsigned long long uint64_t;
15 typedef unsigned int uint32_t;
16 typedef unsigned short uint16_t;
17 typedef unsigned char uint8_t;
18
19 }
20
21 #endif // INTTYPE_HPP_
22
然后今天大部分時(shí)間都消耗在了Timer的跨平臺(tái)處理上
這里采用了Bridge Design Pattern
即pImpl方法,實(shí)現(xiàn)了Linux 和 Windows 兩個(gè)平臺(tái)相關(guān)的高精度計(jì)時(shí)器
接口設(shè)計(jì)得很簡(jiǎn)單,只能得到計(jì)時(shí)器定義以來(lái)經(jīng)過(guò)的時(shí)間(單位是毫秒 //雖然精度都高于毫秒)
具體請(qǐng)見(jiàn)一下幾個(gè)文件了
http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/Timer.hpp
http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/TimerImpl.hpp
http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/LinuxTimerImpl.hpp
http://code.google.com/p/charlib/source/browse/trunk/Charlib/includes/Win32TimerImpl.hpp
以及對(duì)應(yīng)的srcs下的.cpp文件
基本上是這樣
Timer {
protected:
TimerImpl* pImpl;
}
class LinuxTimerImpl : public TimerImpl {}
class Win32TimerImpl : public TimerImpl {}
還定義了一個(gè)用于多平臺(tái)多編譯器的平臺(tái)辨識(shí)頭文件 - Platform.hpp
目前SVN上也有VC 05的工程 和 Code::Blocks 的工程文件
代碼在Windows下 MINGW 和 MSVC 8 兩個(gè)編譯器上編譯通過(guò)
在Ubuntu下使用Code::Blocks + GCC 編譯器上通過(guò)
// fibonacci數(shù)列的模板元編程版本因?yàn)樵赨buntu下GCC編譯未通過(guò),所以注釋掉了,但是在MSVC 8和Code::Blocks的MINGW下編譯通過(guò)
SVN地址: http://charlib.googlecode.com/svn/trunk/
其他雜項(xiàng):
HugeInt added 預(yù)計(jì)在有空的時(shí)候會(huì)完成,用于高精度整形的運(yùn)算 = =~!