Subversion Repositories HomeAutomation

Rev

Rev 1596 | Rev 1598 | Go to most recent revision | 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
#include "Byteset.h"
22
 
23
#include "string.h"
24
 
25
namespace atom {
26
namespace type {
27
 
28
Byteset::Byteset(unsigned int max_size)
29
{
30
    this->max_size_ = max_size;
31
    this->size_ = this->max_size_;
32
    this->bytes_ = new unsigned char[this->max_size_];
33
 
34
    this->Clear();
35
}
36
 
37
Byteset::Byteset(const Byteset& set)
38
{
1597 runge 39
    this->max_size_ = set.size_;
1596 runge 40
    this->size_ = this->max_size_;
41
    this->bytes_ = new unsigned char[this->max_size_];
42
 
43
    memcpy(this->bytes_, set.bytes_, this->max_size_);
44
}
45
 
46
Byteset::Byteset(std::string str)
47
{
48
    this->max_size_ = str.length() + 1;
49
    this->size_ = this->max_size_;
50
    this->bytes_ = new unsigned char[this->max_size_];
51
 
52
    memcpy(this->bytes_, str.data(), this->max_size_);
53
}
54
 
55
Byteset::~Byteset()
56
{
57
    delete [] this->bytes_;
58
}
59
 
60
unsigned char* Byteset::Get() const
61
{
62
    return this->bytes_;
63
}
64
 
1597 runge 65
std::string Byteset::ToCharString()
66
{
67
    return std::string((char*)this->bytes_, this->size_);
68
}
69
 
1596 runge 70
unsigned char& Byteset::operator[](unsigned int index)
71
{
72
    return this->bytes_[index];
73
}
74
 
75
unsigned int Byteset::GetMaxSize() const
76
{
77
    return this->max_size_;
78
}
79
 
80
unsigned int Byteset::GetSize() const
81
{
82
    return this->size_;
83
}
84
 
85
void Byteset::SetSize(unsigned int size)
86
{
87
    this->size_ = size;
88
}
89
 
90
void Byteset::Append(unsigned char byte)
91
{
92
    this->bytes_[this->size_] = byte;
93
    this->size_++;
94
}
95
 
96
void Byteset::Clear()
97
{
98
    memset(this->bytes_, 0, this->max_size_);
99
    this->size_ = 0;
100
}
101
 
102
}; // namespace type
103
}; // namespace atom