summaryrefslogtreecommitdiffstats
path: root/src/devices/base/generic_memory.h
blob: f7127b568d0ad67383f2de8529fdce24b4c4b0c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/***************************************************************************
 *   Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#ifndef GENERIC_MEMORY_H
#define GENERIC_MEMORY_H

#include "devices/base/generic_device.h"
#include "devices/base/hex_buffer.h"

namespace Device
{

class Memory
{
public:
  const Data &device() const { return _device; }
  virtual ~Memory() {}
  virtual void fill(BitValue value) = 0;
  virtual void clear() { fill(BitValue()); }
  virtual void copyFrom(const Memory &memory) = 0;
  virtual BitValue checksum() const = 0;

  virtual HexBuffer toHexBuffer() const = 0;
  bool save(TQTextStream &stream, HexBuffer::Format format) const;
  enum WarningType { NoWarning = 0, ValueTooLarge = 1, ValueOutsideRange = 2 };
  TQ_DECLARE_FLAGS(WarningTypes, WarningType)
  WarningTypes fromHexBuffer(const HexBuffer &hb, TQStringList &warnings);
  bool load(TQTextStream &stream, TQStringList &errors, WarningTypes &warningTypes, TQStringList &warnings);

protected:
  const Data &_device;

  Memory(const Data &device) : _device(device) {}
  virtual void fromHexBuffer(const HexBuffer &hb, WarningTypes &warningTypes,
                             TQStringList &warnings, TQMap<uint, bool> &inRange) = 0;
  virtual void savePartial(TQTextStream &stream, HexBuffer::Format format) const = 0;
};
TQ_DECLARE_OPERATORS_FOR_FLAGS(Memory::WarningTypes)

} // namespace

#endif