MKCommModel
MKLib.h
00001 #ifndef MKLIB_H
00002 #define MKLIB_H
00003 
00004 /* Library for MeshKit */
00005 
00006 #include <cstdlib>
00007 #include <cstring>
00008 #include <iostream>
00009 
00010 #include "include/commmodel.hpp"
00011 
00012 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
00013 
00015 #define MAC_ADDR_BYTES 6
00016 
00018 typedef unsigned long long ip6_t;
00019 
00021 struct MacAddr {
00022 
00024         mac_t addr;
00025 
00026         MacAddr();
00027         MacAddr(mac_t mac) : addr(mac) {}
00028         MacAddr(uint8_t arr[MAC_ADDR_BYTES]);
00029 
00030         bool operator<(const MacAddr &rhs) const;
00031         bool operator==(const MacAddr &rhs) const;
00032         bool operator!=(const MacAddr &rhs) const {
00033                 return !(*this == rhs);
00034         }
00035         
00037         operator mac_t() const {
00038                 return this->addr;
00039         }
00040 };
00041 
00042 class BaseException : public std::exception {
00043 public:
00044         BaseException(const std::string &err) : mErr(err) {}
00045         ~BaseException() throw() {};
00046         const char *what() const throw() {return mErr.c_str();}
00047 
00048 protected:
00049     std::string mErr;
00050 
00051 };
00052 
00053 /*
00054 class FatalException : BaseException {
00055 public:
00056         FatalException(const std::string &err) : BaseException(err) { }
00057 
00058 };
00059 */
00060 
00061 class MKLib {
00062 public:
00063 
00069         static std::string ip2string(ip4_t addr);
00075         static std::string mac2string(mac_t addr);
00082         static ip4_t parseIP4Addr(const char *addr);
00089         static mac_t parseMACAddr(const char *addr);
00090 
00091 private:
00092         enum {
00094                 kIP4MaxLen = 15, 
00096                 kMACMaxLen = 17
00097         };
00098 
00099 };
00100 
00102 class FString : public std::string {
00103 public:
00108         FString(char *fmt, ...);
00109 };
00110 
00111 #endif
00112 
 All Classes Functions Variables