Pack_stat.hpp 1.55 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10
/*
 * Pack_stat.hpp
 *
 *  Created on: Jul 17, 2015
 *      Author: i-bird
 */

#ifndef SRC_PACK_STAT_HPP_
#define SRC_PACK_STAT_HPP_

incardon's avatar
incardon committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/*! \brief Unpacking status object
 *
 *
 */
class Unpack_stat
{
	size_t cnt;

public:

	inline Unpack_stat()
	:cnt(0)
	{}

	/*! \brief Increment the request pointer
	 *
	 * \param cnt counter
	 *
	 */
	inline void addOffset(size_t off)
	{
		cnt += off;
	}

	/*! \brief Return the actual counter
	 *
	 *
	 */
	inline size_t getOffset()
	{
		return cnt;
	}
};

/*! \brief Packing status object
incardon's avatar
incardon committed
46 47 48 49 50
 *
 *
 */
class Pack_stat
{
incardon's avatar
incardon committed
51 52
	size_t p_mark;
	size_t un_ele;
incardon's avatar
incardon committed
53 54 55

public:

incardon's avatar
incardon committed
56
	inline Pack_stat()
incardon's avatar
incardon committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
	:p_mark(0),un_ele(0)
	{}

	/*! \brief Increment the request pointer
	 *
	 *
	 */
	inline void incReq()
	{
		un_ele++;
	}

	/*! \brief return the actual request for packing
	 *
	 * \return the actual request for packing
	 *
	 */
	inline size_t reqPack()
	{
		return un_ele;
	}

	/*! \brief Mark
	 *
	 *
	 *
	 */
	inline void mark()
	{
		p_mark = un_ele;
	}

	/*! \brief Return the mark
	 *
	 * \return the mark
	 *
	 */
	inline size_t getMark()
	{
		return p_mark;
	}

	/*! \brief Return the memory pointer at the mark place
	 *
	 * \tparam T memory object
	 *
	 * \return memory pointer at mark place
	 *
	 */
	template<typename T> inline void * getMarkPointer(T & mem)
	{
		return mem.getPointer(p_mark);
	}

	/*! \brief Get the memory size from the mark point
	 *
	 * \tparam T memory object
	 *
	 */
	template<typename T> size_t getMarkSize(T & mem)
	{
		return (char *)mem.getPointer(un_ele) - (char *)mem.getPointer(p_mark);
	}

};

#endif /* SRC_PACK_STAT_HPP_ */