00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef HELPER_H
00011 #define HELPER_H HELPER_H
00012 #include <string>
00013 #include <sstream>
00014 #include <iomanip>
00015 #include <iostream>
00016
00017 template <typename T1, typename T2>
00018 void copy(T1 from, T2 to, int number){
00019 for(int j = 0; j < number; ++j) to[j] = from[j];
00020 }
00021
00022 template <typename T1, typename T2>
00023 bool compare(const T1& from, const T2& to, int number){
00024 for(int j = 0; j < number; ++j) if(to[j] != from[j]) return false;
00025 return true;
00026 }
00027
00028 template <typename T>
00029 string hex(T toHex, int w = 0){
00030 ostringstream s;
00031 s << std::hex << std::setw(w) << std::setfill('0') << toHex;
00032 return s.str();
00033 }
00034
00035 template <typename T>
00036 void hexout(T ray, int len){
00037 for(int j = 0; j < len; ++j){
00038 std::cout << hex<int>(int(ray[j])) << " ";
00039 }
00040 }
00041
00042 template <typename T>
00043 void hexout(std::ostream& o, T ray, int len){
00044 for(int j = 0; j < len; ++j){
00045 o << hex<int>(int(ray[j])) << " ";
00046 }
00047 }
00048
00049 template <typename T>
00050 string stringify(T toStr){
00051 ostringstream s;
00052 s << toStr;
00053 return s.str();
00054 }
00055
00056 template <typename T>
00057 bool checkchar(const T& i, int length, unsigned char tocheck){
00058 for(T j = i; j < i + length; ++j) if(*j != tocheck) return false;
00059 return true;
00060 }
00061
00062 template <typename T>
00063 bool checkZeros(const T& i, int length){ return checkchar(i, length, 0); }
00064 template <typename T>
00065 bool checkSpaces(const T& i, int length){ return checkchar(i, length, 0x20); }
00066
00067
00068 #endif