bin.cpp

来自「ECAN OOP implementation for TMS320 280x 」· C++ 代码 · 共 71 行

CPP
71
字号
#include <c280xpcl\include\bin.h>

//
// class binarizer
//
binarizer::binarizer(value_type* origin, size_type offset /*= 0*/)
  : origin(origin)
  , offset(offset)
{
}

binarizer::value_type binarizer::operator *() const
{ value_type word = *(origin + (offset >> 1));
  return (offset & 1) ? (word >> 8) : (word & 0xFF);
}

binarizer::self_type& binarizer::operator=(value_type value)
{ value_type& word = *(origin + (offset >> 1));
  word = (offset & 1)
    ? ((word & 0x00FF) | (value << 8))
    : ((word & 0xFF00) | (value & 0x00FF));
  return (*this);
}

binarizer::self_type& binarizer::operator++()
{ offset++;
  return (*this);
}

binarizer::self_type  binarizer::operator++(int)
{ self_type rslt(*this);
  ++(*this);
  return (rslt);
}

binarizer::self_type& binarizer::operator--()
{ if(offset > 0)
    offset--;
  return (*this);
}

binarizer::self_type  binarizer::operator--(int)
{ self_type rslt(*this);
  --(*this);
  return (rslt);
}

binarizer::self_type  binarizer::operator +(size_type n) const
{ self_type rslt(*this);
  rslt += n;
  return (rslt);
}

binarizer::self_type& binarizer::operator+=(size_type n)
{ offset += n;
  return (*this);
}

binarizer::self_type  binarizer::operator -(size_type n) const
{ self_type rslt(*this);
  rslt -= n;
  return (rslt);
}

binarizer::self_type& binarizer::operator-=(size_type n)
{ if(n > offset)
    n = offset;
  offset -= n;
  return (*this);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?