Взялся за кресты. Для разминки решил сваять сабж.
Собственно код:
#include <cstddef>
#include <cstdint>
template<typename T>
class Hash
{
public:
    virtual Hash& update(const char*, std::size_t) = 0;
    virtual void reset() = 0;
    virtual T chksum() const = 0;
};
typedef std::size_t size_t;
typedef std::uint_fast8_t  crc8_t;
typedef std::uint_fast16_t crc16_t;
typedef std::uint_fast32_t crc32_t;
template<typename T>
Hash<T> * make_hash();
class Crc8: public Hash<crc8_t>
{
    typedef crc8_t       value_type;
    typedef Hash<crc8_t> parent_type;
public:
    parent_type& update(const char* d, size_t l){
        while(l--) {
            hash_ ^= *d++;
            for (unsigned int i = 0; i < 8; i++)
                hash_ = hash_ & 0x80 ? (hash_ << 1) ^ 0x31 : hash_ << 1;
        }
        return *this;
    };
    void reset() { hash_ = 0xff; };
    value_type chksum() const { return hash_; };
    Crc8(): hash_(0xff) {};
    ~Crc8(){};
private:
    value_type hash_;
};
template<>
Hash<crc8_t> * make_hash<crc8_t>() { return new Crc8(); }
Остальные классы определяются аналогичным образом. И, собственно, вопросы:
- Чем такой код плох?
- Чего в коде не хватает?
- Стоит ли мне его шыфтделет и выйти в окно?




