Rev 1987 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1596 | runge | 1 | /* |
| 2 | * |
||
| 3 | * Copyright (C) 2010 Mattias Runge |
||
| 4 | * |
||
| 5 | * This program is free software; you can redistribute it and/or modify |
||
| 6 | * it under the terms of the GNU General Public License as published by |
||
| 7 | * the Free Software Foundation; either version 2 of the License, or |
||
| 8 | * (at your option) any later version. |
||
| 9 | * |
||
| 10 | * This program is distributed in the hope that it will be useful, |
||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | * GNU General Public License for more details. |
||
| 14 | * |
||
| 15 | * You should have received a copy of the GNU General Public License along |
||
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
||
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
| 18 | * |
||
| 19 | */ |
||
| 20 | |||
| 21 | #ifndef TYPE_COMMON_H |
||
| 22 | #define TYPE_COMMON_H |
||
| 23 | |||
| 24 | #include <iostream> |
||
| 25 | #include <string> |
||
| 26 | #include <vector> |
||
| 1602 | runge | 27 | #include <map> |
| 1642 | runge | 28 | #include <stdexcept> |
| 1596 | runge | 29 | |
| 1598 | runge | 30 | #include <stdio.h> |
| 31 | |||
| 1596 | runge | 32 | #include <boost/shared_ptr.hpp> |
| 1642 | runge | 33 | #include <boost/lexical_cast.hpp> |
| 1596 | runge | 34 | |
| 35 | namespace atom { |
||
| 1642 | runge | 36 | namespace common { |
| 1596 | runge | 37 | |
| 38 | typedef boost::shared_ptr<unsigned char> BytePointer; |
||
| 39 | typedef std::vector<std::string> StringList; |
||
| 1602 | runge | 40 | typedef std::map<std::string, std::string> StringMap; |
| 1642 | runge | 41 | |
| 1914 | linlun | 42 | #define SWAP_BYTE_ORDER_16(x) ((((x) << 8) | ((x) >> 8)) & 0xFFFF) |
| 43 | #define GET_HIGH_BYTE_16(x) (((x) >> 8) & 0xFF); |
||
| 44 | #define GET_LOW_BYTE_16(x) ((x) & 0xFF) |
||
| 1642 | runge | 45 | |
| 1989 | runge | 46 | #define ELEMENTS_OF(type) (sizeof(type) / sizeof(type[0])) |
| 47 | |||
| 1642 | runge | 48 | template <typename ElemT> |
| 49 | struct HexTo { |
||
| 50 | ElemT value; |
||
| 51 | operator ElemT() const {return value;} |
||
| 52 | friend std::istream& operator>>(std::istream& in, HexTo& out) { |
||
| 53 | in >> std::hex >> out.value; |
||
| 54 | return in; |
||
| 55 | } |
||
| 56 | }; |
||
| 57 | |||
| 1647 | runge | 58 | std::string PadNumber(unsigned int number, unsigned int length); |
| 59 | unsigned int FromHex(std::string hex_chars); |
||
| 60 | std::string ToHex(unsigned int value); |
||
| 1914 | linlun | 61 | std::string ToHex8bit(unsigned int value); |
| 62 | std::string ToHex4bit(unsigned int value); |
||
| 1939 | runge | 63 | std::string ToHexIfNumber(std::string data); |
| 1987 | runge | 64 | std::string ToHex(std::string data); |
| 65 | |||
| 1596 | runge | 66 | }; // namespace type |
| 67 | }; // namespace atom |
||
| 68 | |||
| 1675 | arune | 69 | #endif // TYPE_COMMON_H |
| 70 |