text: /*******************************************************************************
   * The MIT License (MIT)
   * 
   * Copyright (c) 2020 Jean-David Gadina - www.xs-labs.com
   * 
   * 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.
   ******************************************************************************/
  
  /*!
   * @file        Note.cpp
   * @copyright   (c) 2020, Jean-David Gadina - www.xs-labs.com
   */
  
  #include <MachO/LoadCommands/Note.hpp>
  #include <MachO/ToString.hpp>
  #include <XS.hpp>
  
  namespace MachO
  {
      namespace LoadCommands
      {
          class Note::IMPL
          {
              public:
                  
                  IMPL( uint32_t command, uint32_t size, File::Kind kind, XS::IO::BinaryStream & stream  );
                  IMPL( const IMPL & o );
                  ~IMPL();
                  
                  uint32_t    _command;
                  uint32_t    _size;
                  std::string _dataOwner;
                  uint64_t    _dataOffset;
                  uint64_t    _dataSize;
          };
  
          Note::Note( uint32_t command, uint32_t size, File::Kind kind, XS::IO::BinaryStream & stream ):
              impl( std::make_unique< IMPL >( command, size, kind, stream ) )
          {}
          
          Note::Note( const Note & o ):
              impl( std::make_unique< IMPL >( *( o.impl ) ) )
          {}
  
          Note::Note( Note && o ) noexcept:
              impl( std::move( o.impl ) )
          {}
  
          Note::~Note()
          {}
  
          Note & Note::operator =( Note o )
          {
              swap( *( this ), o );
              
              return *( this );
          }
          
          XS::Info Note::getInfo() const
          {
              XS::Info i( LoadCommand::getInfo() );
              
              i.addChild( { "Data owner",  this->dataOwner() } );
              i.addChild( { "Data offset", XS::ToString::Hex( this->dataOffset() ) } );
              i.addChild( { "Data size",   XS::ToString::Hex( this->dataSize() ) } );
              
              return i;
          }
          
          uint32_t Note::command() const
          {
              return this->impl->_command;
          }
          
          uint32_t Note::size() const
          {
              return this->impl->_size;
          }
          
          std::string Note::dataOwner() const
          {
              return this->impl->_dataOwner;
          }
          
          uint64_t Note::dataOffset() const
          {
              return this->impl->_dataOffset;
          }
          
          uint64_t Note::dataSize() const
          {
              return this->impl->_dataSize;
          }
          
          void swap( Note & o1, Note & o2 )
          {
              using std::swap;
              
              swap( o1.impl, o2.impl );
          }
          
          Note::IMPL::IMPL( uint32_t command, uint32_t size, File::Kind kind, XS::IO::BinaryStream & stream ):
              _command(    command ),
              _size(       size ),
              _dataOwner(  stream.readString( 16 ) ),
              _dataOffset( stream.readUInt64() ),
              _dataSize(   stream.readUInt64() )
          {
              ( void )kind;
          }
          
          Note::IMPL::IMPL( const IMPL & o ):
              _command(    o._command ),
              _size(       o._size ),
              _dataOwner(  o._dataOwner ),
              _dataOffset( o._dataOffset ),
              _dataSize(   o._dataSize )
          {}
  
          Note::IMPL::~IMPL()
          {}
      }
  }
  