Top > C++ > apcl > util

Data Edit

Version:revision 6

fileData.hpp
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 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
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 
 
 
 
 
 
 
-
-
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
|
!
!
/** @file @brief 可変長データを示すクラスを記述する。 */
#pragma once
 
//-----------------------------------------------------------
#include <apcl/util/Types.hpp>
 
//-----------------------------------------------------------
namespace apcl { namespace util
{
    using ::apcl::util::byte;
    using ::apcl::util::u32;
 
    /**
	 * 可変長データを示すクラス
	 * <pre>
	 * データを作成した際,領域を新たに確保した際,値は0がセットされる。
	 * </pre>
	 */
    class Data
    {
    public:
        Data(void);
        explicit Data( const Data& );
        Data( const void* aBytes , u32 aLength ); ///< コピー元のデータを指定して作成する。
        virtual ~Data();
 
        /// 引数のデータと長さで初期化する。
        void init( const void* aBytes , u32 aLength ); 
 
        /// データの長さを変える。元のサイズ部分の内容は保持される。
        void resize( u32 aSize ); 
 
        /// データを末端に追加する。
        void push( const Data& );
 
        /// 指定の長さのデータを終端から除去する。
        void pop( u32 aLength );
 
        /// データの内容が等しいかどうかを取得する。
        bool equals( const Data& )const;
 
        /// 指定のインデックスの値を取得する。
        byte& at( u32 aIndex );
        byte at( u32 aIndex )const;
 
        /// バイトポインタを取得する。
        byte* bytes(void);
        const byte*    bytes(void)const;
 
        /// 長さを取得する。
        u32 length(void)const;
 
        const Data&    operator +=( const Data& ); ///< push()
        byte&    operator []( u32 aIndex ); ///< at()
        byte    operator []( u32 aIndex )const; ///< at()
        bool operator ==( const Data& )const; ///< equals()
        const Data& operator =( const Data& ); ///< init()
 
    private:
        byte*    bytes_;
        u32  length_;
 
        void _releaseBytes();
    };
 
} // end of namespace util 
} // end of namespace apcl
fileData.cpp
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 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
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
 
 
-
|
!
 
 
 
 
 
-
|
!
 
 
 
-
|
!
 
 
 
-
|
|
|
|
!
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
-
|
|
!
|
-
|
!
!
|
|
-
|
!
|
|
|
|
!
 
 
 
-
|
|
|
!
 
 
 
-
|
|
|
!
 
 
 
-
|
|
|
!
 
 
 
-
|
|
!
 
 
 
-
|
|
!
 
 
 
-
|
!
 
 
 
-
|
!
 
 
 
-
|
!
 
 
 
-
|
|
!
 
 
 
-
|
!
 
 
 
-
|
!
 
 
 
-
|
!
 
 
 
-
|
|
!
 
 
 
 
-
|
-
|
|
|
!
!
 
/** @file @brief Data.hppの実装を記述する。 */
#include <apcl/util/Data.hpp>
 
//-----------------------------------------------------------
#include <cassert>
#include <cstring>
 
//-----------------------------------------------------------
using namespace ::apcl::util;
using namespace ::std;
 
//-----------------------------------------------------------
Data::Data(void):
bytes_(0),
length_(0)
{
}
 
//-----------------------------------------------------------
Data::Data( const Data& aData ):
bytes_(0),
length_(0)
{
    init( aData.bytes() , aData.length() );
}
 
//-----------------------------------------------------------
Data::Data( const void* const aBytes , const u32 aLength ):
bytes_(0),
length_(0)
{
  init( aBytes , aLength );
}
 
//-----------------------------------------------------------
Data::~Data()
{
    _releaseBytes();
}
 
//-----------------------------------------------------------
void Data::init( const void* const aBytes , const u32 aLength )
{
    _releaseBytes();
  bytes_ = new byte[aLength];
    length_ = aLength;
    memcpy( bytes_ , aBytes , aLength );
}
 
//-----------------------------------------------------------
void Data::resize( const u32 aSize )
{
    // メモ
    byte* preBytes = bytes_;
    u32 preLength = length_;
 
    // 新領域確保
    if ( aSize > 0 )
        bytes_ = new byte[aSize];
    else
        bytes_ = 0;
    length_ = aSize;
 
    // コピー or 0セット
    if ( length_ > 0 ) 
    {
        if ( preLength > 0 )
        {// 前の内容をコピー
            const u32 size = preLength < length_ ? preLength : length_;
            memcpy( bytes_ , preBytes, size );
        }
        else 
        {// 0をセット
            memset( bytes_ , 0 , length_ );
        }
    }
 
    if ( length_ > preLength )
    {// 前の長さより長ければ,追加分を0で埋める。
        memset( &bytes_[preLength] , 0 , length_ - preLength );
    }
 
    // 前領域解放
    delete[] preBytes;
 
}
 
//-----------------------------------------------------------
void Data::push( const Data& aData )
{
    assert( aData.length() > 0 );
    resize( length_ + aData.length() );
    memcpy( &bytes_[length_] , aData.bytes() , aData.length() );
}
 
//-----------------------------------------------------------
void Data::pop( const u32 aLength )
{
    assert( aLength > 0 );
    assert( aLength <= length_ );
    resize( length_ - aLength );
}
 
//-----------------------------------------------------------
bool Data::equals( const Data& aData )const
{
    if ( length_ == aData.length() )
        return ( memcmp( bytes_ , aData.bytes() , length_ ) == 0 );
    return false;
}
 
//-----------------------------------------------------------
byte& Data::at( const u32 aIndex )
{
    assert( aIndex > 0 && aIndex <= length_ );
    return bytes_[aIndex];
}
 
//-----------------------------------------------------------
byte Data::at( const u32 aIndex )const
{
    assert( aIndex > 0 && aIndex <= length_ );
    return bytes_[aIndex];
}
 
//-----------------------------------------------------------
byte* Data::bytes()
{
    return bytes_;
}
 
//-----------------------------------------------------------
const byte* Data::bytes()const
{
    return bytes_;
}
 
//-----------------------------------------------------------
u32 Data::length()const
{
    return length_;
}
 
//-----------------------------------------------------------
const Data& Data::operator +=( const Data& aData )
{
    push( aData );
    return *this;
}
 
//-----------------------------------------------------------
byte& Data::operator []( const u32 aIndex )
{
    return at( aIndex );
}
 
//-----------------------------------------------------------
byte Data::operator []( const u32 aIndex )const
{
    return at( aIndex );
}
 
//-----------------------------------------------------------
bool Data::operator ==( const Data& aData )const
{
    return equals( aData );
}
 
//-----------------------------------------------------------
const Data& Data::operator =( const Data& aData )
{
    init( aData.bytes() , aData.length() );
    return *this;
}
 
 
//-----------------------------------------------------------
void Data::_releaseBytes()
{
    if ( bytes_ )
    {
        delete[] bytes_;
        bytes_ = 0;
        length_ = 0;
    }
}

Types Edit

Version:revision 5

fileTypes.hpp
すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 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
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 
 
 
 
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
!
/** @file @brief 型の略称を定義する。*/
#pragma once
 
//-----------------------------------------------------------
namespace apcl { namespace util 
{
    typedef unsigned char           uint8;
    typedef unsigned short int      uint16;
    typedef unsigned int            uint32;
    typedef unsigned long long int  uint64;
 
    typedef signed char             int8;
    typedef signed short int        int16;
    typedef signed int              int32;
    typedef signed long long int    int64;
 
    typedef float                   float32;
    typedef double                  float64;
 
    typedef volatile uint8          vuint8;
    typedef volatile uint16         vuint16;
    typedef volatile uint32         vuint32;
    typedef volatile uint64         vuint64;
 
    typedef volatile int8           vint8;
    typedef volatile int16          vint16;
    typedef volatile int32          vint32;
    typedef volatile int64          vint64;
 
    typedef volatile float32        vfloat32;
    typedef volatile float64        vfloat64;
 
    typedef uint8                   byte;
 
    typedef int32                   fixed;
    typedef int64                   dfixed;
 
    typedef volatile int32          vfixed;
 
 
    typedef unsigned char           u8;
    typedef unsigned short int      u16;
    typedef unsigned int            u32;
    typedef unsigned long long int  u64;
 
    typedef signed char             s8;
    typedef signed short int        s16;
    typedef signed int              s32;
    typedef signed long long int    s64;
 
    typedef float                   f32;
    typedef double                  f64;
 
    typedef volatile u8          vu8;
    typedef volatile u16         vu16;
    typedef volatile u32         vu32;
    typedef volatile u64         vu64;
 
    typedef volatile s8           vs8;
    typedef volatile s16          vs16;
    typedef volatile s32          vs32;
    typedef volatile s64          vs64;
 
    typedef volatile f32            vf32;
    typedef volatile f64            vf64;
 
}
}
fileTypes.cpp
すべてを展開すべてを収束
  1
  2
 
 
/** @file @brief Types.hppの実装を記述する。 */
#include <apcl/util/Types.hpp>

添付ファイル: fileData.cpp 711件 [詳細] fileData.hpp 692件 [詳細] fileTypes.cpp 620件 [詳細] fileTypes.hpp 597件 [詳細]

リロード   新規 下位ページ作成 編集 凍結 差分 添付 コピー 名前変更   ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: Wed, 12 Jul 2006 00:58:55 JST (6498d)