Subversion Repositories HomeAutomation

Rev

Rev 1597 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  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. {
  39.     this->max_size_ = set.max_size_;
  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.  
  65. unsigned char& Byteset::operator[](unsigned int index)
  66. {
  67.     return this->bytes_[index];
  68. }
  69.  
  70. unsigned int Byteset::GetMaxSize() const
  71. {
  72.     return this->max_size_;
  73. }
  74.  
  75. unsigned int Byteset::GetSize() const
  76. {
  77.     return this->size_;
  78. }
  79.  
  80. void Byteset::SetSize(unsigned int size)
  81. {
  82.     this->size_ = size;
  83. }
  84.  
  85. void Byteset::Append(unsigned char byte)
  86. {
  87.     this->bytes_[this->size_] = byte;
  88.     this->size_++;
  89. }
  90.  
  91. void Byteset::Clear()
  92. {
  93.     memset(this->bytes_, 0, this->max_size_);
  94.     this->size_ = 0;
  95. }
  96.    
  97. }; // namespace type
  98. }; // namespace atom
  99.