00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00037 template<u8 N> class pgMsg
00038 {
00039 public:
00040 pgDefineException(ExceptionInvalidArgument);
00041 pgDefineException(ExceptionInvalidCall);
00042 pgDefineException(ExceptionInvalidType);
00043
00047 pgMsg()
00048 {
00049 for (s32 i = 0; i < N; i++)
00050 {
00051 m_param_size[i] = 0;
00052 }
00053 }
00054
00061 template<class T> T getParam(u8 index)
00062 {
00063 if (index >= N)
00064 {
00065 pgThrow(ExceptionInvalidArgument);
00066 }
00067
00068 if (m_param_size[index] == 0)
00069 {
00070 pgThrow(ExceptionInvalidCall);
00071 }
00072
00073 if (sizeof(T) != m_param_size[index])
00074 {
00075 pgThrow(ExceptionInvalidType);
00076 }
00077
00078 return *reinterpret_cast<T*>(&m_param[index]);
00079 }
00080
00087 template<class T> void setParam(u8 index, T param)
00088 {
00089 if (index >= N)
00090 {
00091 pgThrow(ExceptionInvalidArgument);
00092 }
00093
00094 if (sizeof(T) > sizeof(MsgParam))
00095 {
00096 pgThrow(ExceptionInvalidType);
00097 }
00098
00099 *reinterpret_cast<T*>(&m_param[index]) = param;
00100 m_param_size[index] = sizeof(T);
00101 }
00102
00103 private:
00104 struct MsgParam
00105 {
00106 u8 data[8];
00107 };
00108
00109 MsgParam m_param[N];
00110 u8 m_param_size[N];
00111 };
00112
00113
00114 template<> class pgMsg<0>
00115 {
00116 private:
00117 pgMsg() {}
00118 };