/* Copyright (c) 20011 Hovanes Egiyan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "BaseIUMessage.hh" int BaseIUMessage::bmsDebFlag = 0; const uint8_t BaseIUMessage::bmsByteMask = 0xff; //! Constructor from a pointer to a buffer and the number of bytes BaseIUMessage::BaseIUMessage( const unsigned char* buffer, int bufLength ) { if( buffer == 0 || bufLength == 0 ) return; for( int iChar = 0; iChar < bufLength; iChar++ ) { this->push_back( static_cast( buffer[iChar] ) ) ; } } //BaseIUMessage::BaseIUMessage(const unsigned long longWord) { // for(unsigned iChar = 0; iChar < sizeof(unsigned long); iChar++) { // this->push_back(static_cast(buffer[iChar])); // } // // } //! Assignment operator BaseIUMessage& BaseIUMessage::operator=( const BaseIUMessage& msg ) { if( this == &msg ) return *this; ByteArray::operator=( msg ); return *this; } //! Lowest bytes are taken from this, while //! the higher bytes are taken from msg. BaseIUMessage& BaseIUMessage::operator<<( const BaseIUMessage& msg ) { if( bmsDebFlag > 1 ) { cout << "BaseIUMessage::operator<<() : Will append <" << msg << "> to existing message<" << *this << ">" << endl; } BaseIUMessage& newMsg = *this; for( unsigned iByte = 0; iByte < msg.size(); iByte++ ) { newMsg.push_back( msg[iByte] ); } if( bmsDebFlag > 1 ) { cout << "Current message is: <" << newMsg << ">" << endl; } return newMsg; } //! This method sends out the content of the message into the ostream void BaseIUMessage::print( ostream& os ) const { os << "|| " ; for( unsigned idx = 0; idx < this->size(); idx++ ) { os << hex << showbase << "Byte#" << idx << "=" << "<" << static_cast( (*this)[idx] ) << ">, "; } os << "||" ; return; } //! Non-member function to print BaseIUMessage class through ostream class ostream& operator<<( ostream& os, const BaseIUMessage& msg ) { msg.print( os ); return os; }