Subversion Repositories HomeAutomation

Rev

Rev 1597 | Rev 1608 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1597 Rev 1598
Line 19... Line 19...
19
 */
19
 */
20
 
20
 
21
#include "Byteset.h"
21
#include "Byteset.h"
22
 
22
 
23
#include "string.h"
23
#include "string.h"
-
 
24
 
-
 
25
#include <boost/lexical_cast.hpp>
24
 
26
 
25
namespace atom {
27
namespace atom {
26
namespace type {
28
namespace type {
27
 
29
 
28
Byteset::Byteset(unsigned int max_size)
30
Byteset::Byteset(unsigned int max_size)
29
{
31
{
30
    this->max_size_ = max_size;
32
    this->max_size_ = max_size;
31
    this->size_ = this->max_size_;
-
 
32
    this->bytes_ = new unsigned char[this->max_size_];
33
    this->bytes_ = new unsigned char[this->max_size_];
33
   
34
   
34
    this->Clear();
35
    this->Clear();
35
}
36
}
36
 
37
 
37
Byteset::Byteset(const Byteset& set)
38
Byteset::Byteset(const Byteset& set)
38
{
39
{
39
    this->max_size_ = set.size_;
40
    this->max_size_ = set.size_;
40
    this->size_ = this->max_size_;
41
    this->size_ = this->max_size_;
41
    this->bytes_ = new unsigned char[this->max_size_];
42
    this->bytes_ = new unsigned char[this->max_size_];
42
 
43
 
43
    memcpy(this->bytes_, set.bytes_, this->max_size_);
44
    memcpy(this->bytes_, set.bytes_, this->max_size_);
44
}
45
}
45
 
46
 
46
Byteset::Byteset(std::string str)
47
Byteset::Byteset(std::string str)
47
{
48
{
48
    this->max_size_ = str.length() + 1;
49
    this->max_size_ = str.length() + 1;
49
    this->size_ = this->max_size_;
50
    this->size_ = this->max_size_;
50
    this->bytes_ = new unsigned char[this->max_size_];
51
    this->bytes_ = new unsigned char[this->max_size_];
51
   
52
   
52
    memcpy(this->bytes_, str.data(), this->max_size_);
53
    memcpy(this->bytes_, str.data(), this->max_size_);
53
}
54
}
54
 
55
 
55
Byteset::~Byteset()
56
Byteset::~Byteset()
56
{
57
{
Line 63... Line 64...
63
}
64
}
64
 
65
 
65
std::string Byteset::ToCharString()
66
std::string Byteset::ToCharString()
66
{
67
{
67
    return std::string((char*)this->bytes_, this->size_);
68
    return std::string((char*)this->bytes_, this->size_);
-
 
69
}
-
 
70
 
-
 
71
std::string Byteset::ToDebugString()
-
 
72
{
-
 
73
    std::string debug_string;
-
 
74
   
-
 
75
    for (unsigned int n = 0; n < this->size_; n++)
-
 
76
    {
-
 
77
        debug_string += boost::lexical_cast<std::string>((unsigned int)this->bytes_[n]) + ",";
-
 
78
    }
-
 
79
   
-
 
80
    return debug_string;
68
}
81
}
69
 
82
 
70
unsigned char& Byteset::operator[](unsigned int index)
83
unsigned char& Byteset::operator[](unsigned int index)
71
{
84
{
72
    return this->bytes_[index];
85
    return this->bytes_[index];