Top > C++ > apcl > util

Data Edit

Version:revision 6

fileData.hpp
Everything is expanded.Everything is shortened.
  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 •ϒf[^NXLqB */
#pragma once
 
//-----------------------------------------------------------
#include <apcl/util/Types.hpp>
 
//-----------------------------------------------------------
namespace apcl { namespace util
{
    using ::apcl::util::byte;
    using ::apcl::util::u32;
 
    /**
	 * •ϒf[^NX
	 * <pre>
	 * f[^쐬ہC̈VɊmۂہCl0ZbgB
	 * </pre>
	 */
    class Data
    {
    public:
        Data(void);
        explicit Data( const Data& );
        Data( const void* aBytes , u32 aLength ); ///< Rs[̃f[^w肵č쐬B
        virtual ~Data();
 
        /// ̃f[^ƒŏB
        void init( const void* aBytes , u32 aLength ); 
 
        /// f[^̒ςB̃TCY̓e͕ێB
        void resize( u32 aSize ); 
 
        /// f[^𖖒[ɒljB
        void push( const Data& );
 
        /// w̒̃f[^I[珜B
        void pop( u32 aLength );
 
        /// f[^̓eǂ擾B
        bool equals( const Data& )const;
 
        /// w̃CfbNX̒l擾B
        byte& at( u32 aIndex );
        byte at( u32 aIndex )const;
 
        /// oCg|C^擾B
        byte* bytes(void);
        const byte*    bytes(void)const;
 
        /// 擾B
        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
Everything is expanded.Everything is shortened.
  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̎LqB */
#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_;
 
    // V̈m
    if ( aSize > 0 )
        bytes_ = new byte[aSize];
    else
        bytes_ = 0;
    length_ = aSize;
 
    // Rs[ or 0Zbg
    if ( length_ > 0 ) 
    {
        if ( preLength > 0 )
        {// O̓eRs[
            const u32 size = preLength < length_ ? preLength : length_;
            memcpy( bytes_ , preBytes, size );
        }
        else 
        {// 0Zbg
            memset( bytes_ , 0 , length_ );
        }
    }
 
    if ( length_ > preLength )
    {// O̒蒷΁Clj0Ŗ߂B
        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
Everything is expanded.Everything is shortened.
  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 ^̗̂`B*/
#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
Everything is expanded.Everything is shortened.
  1
  2
 
 
/** @file @brief Types.hpp̎LqB */
#include <apcl/util/Types.hpp>

Attach file: fileData.cpp 587 download [Information] fileData.hpp 545 download [Information] fileTypes.cpp 500 download [Information] fileTypes.hpp 467 download [Information]

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup Referer   Help   RSS of recent changes
Last-modified: (5883d)