Subversion Repositories HomeAutomation

Rev

Rev 1326 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * Variable.cpp
  3.  *
  4.  *  Created on: Jul 21, 2009
  5.  *      Author: Mattias Runge
  6.  */
  7.  
  8. #include "Variable.h"
  9.  
  10. namespace atom {
  11. namespace message {
  12.  
  13. Variable::Variable(xml::Node xmlNode)
  14. {
  15.     this->myName = xmlNode["name"];
  16.     this->myRequired = convert::string2bool(xmlNode["required"]);
  17.     this->myUnit = xmlNode["unit"];
  18.  
  19.     this->myDatatype = Datatype::create(xmlNode["datatype"]);
  20. }
  21.  
  22. Variable::Variable()
  23. {
  24.     LOG.setName("Variable");
  25. }
  26.  
  27. Variable::~Variable()
  28. {
  29. }
  30.  
  31. string Variable::getName()
  32. {
  33.     return this->myName;
  34. }
  35.  
  36. Datatype::pointer Variable::getDatatype()
  37. {
  38.     return this->myDatatype;
  39. }
  40.  
  41. string Variable::getUnit()
  42. {
  43.     return this->myUnit;
  44. }
  45.  
  46. bool Variable::isRequired()
  47. {
  48.     return this->myRequired;
  49. }
  50.  
  51. void Variable::readBits(BitBuffer & buffer)
  52. {
  53.     this->myDatatype->readBits(buffer);
  54. }
  55.  
  56. void Variable::writeBits(BitBuffer & buffer)
  57. {
  58.     this->myDatatype->writeBits(buffer);
  59. }
  60.  
  61. string Variable::toString()
  62. {
  63.     string buffer = this->myName + "=" + this->myDatatype->toString();
  64.  
  65.     if (this->myUnit != "")
  66.     {
  67.         buffer += " " + this->myUnit;
  68.     }
  69.  
  70.     return buffer;
  71. }
  72.  
  73. }
  74. }
  75.