summaryrefslogtreecommitdiff
path: root/cpp/test/Ice/custom/MyByteSeq.cpp
blob: 9f0f9db5346159ac2bf05ed60004e75820eb93b9 (plain)
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
// **********************************************************************
//
// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#include <MyByteSeq.h>

MyByteSeq::MyByteSeq()
    : _size(0),
      _data(0)
{
}

MyByteSeq::MyByteSeq(size_t size)
    : _size(size),
      _data(0)
{
    if(_size != 0)
    {
        _data = new Ice::Byte[_size];
    }
}

MyByteSeq::MyByteSeq(const MyByteSeq& seq)
{
    _size = seq._size;
    if(_size != 0)
    {
        _data = new Ice::Byte[_size];
        memcpy(_data, seq._data, _size);
    }
    else
    {
        _data = 0;
    }
}

MyByteSeq::~MyByteSeq()
{
    delete[] _data;
}

size_t
MyByteSeq::size() const
{
    return _size;
}

void 
MyByteSeq::swap(MyByteSeq& seq)
{
    size_t tmpSize = seq._size;
    Ice::Byte* tmpData = seq._data;
    seq._size = _size;
    seq._data = _data;
    _size = tmpSize;
    _data = tmpData;
}

MyByteSeq::const_iterator
MyByteSeq::begin() const
{
    return _data;
}

MyByteSeq::const_iterator
MyByteSeq::end() const
{
    return _data + _size;
}

void
MyByteSeq::operator=(const MyByteSeq& rhs)
{
    delete[] _data;
    _data = 0;

    _size = rhs._size;
    if(_size != 0)
    {
        _data = new Ice::Byte[_size];
        memcpy(_data, rhs._data, _size);
    }
}

bool
MyByteSeq::operator==(const MyByteSeq& rhs) const
{
    if(_size != rhs._size)
    {
        return _size == rhs._size;
    }
    return memcmp(_data, rhs._data, _size) == 0;
}