|
| 1 | +//============================================================================== |
| 2 | +/** |
| 3 | +*/ |
| 4 | +class CRCDataUnit final |
| 5 | +{ |
| 6 | +public: |
| 7 | + CRCDataUnit() = default; |
| 8 | + ~CRCDataUnit() = default; |
| 9 | + |
| 10 | + void configure (int numBits, uint64 poly, uint64 xorIn, |
| 11 | + uint64 xorOut, bool refIn, bool refOut) |
| 12 | + { |
| 13 | + } |
| 14 | + |
| 15 | + uint8 getNumBits() const |
| 16 | + { |
| 17 | + if (crc8 != nullptr) return 8; |
| 18 | + else if (crc16 != nullptr) return 16; |
| 19 | + else if (crc32 != nullptr) return 32; |
| 20 | + else if (crc64 != nullptr) return 64; |
| 21 | + |
| 22 | + return 0; // Not configured... yet? |
| 23 | + } |
| 24 | + |
| 25 | + uint8 getNumBytes() const |
| 26 | + { |
| 27 | + if (const auto numBits = getNumBits(); numBits > 0) |
| 28 | + return numBits / 8; |
| 29 | + |
| 30 | + return 0; // Not configured... yet? |
| 31 | + } |
| 32 | + |
| 33 | + uint64 getCheckValue() const { return {}; } |
| 34 | + String getCheckString() const { return {}; } |
| 35 | + uint64 getFinalValue() const { return {}; } |
| 36 | + String getFinalValueAsDecString() const { return {}; } |
| 37 | + String getFinalValueAsHexString() const { return {}; } |
| 38 | + String getFinalValueAsOctString() const { return {}; } |
| 39 | + |
| 40 | +private: |
| 41 | + //============================================================================== |
| 42 | + struct CRCAtom |
| 43 | + { |
| 44 | + CRCAtom() = default; |
| 45 | + virtual ~CRCAtom() = default; |
| 46 | + |
| 47 | + virtual void configure (uint64 poly, uint64 xorIn, uint64 xorOut, bool refIn, bool refOut) = 0; |
| 48 | + |
| 49 | + virtual uint8 getNumBits() const = 0; |
| 50 | + virtual uint64 getCheckValue() const = 0; |
| 51 | + virtual String getCheckString() const = 0; |
| 52 | + virtual uint64 getFinalValue() const = 0; |
| 53 | + virtual String getFinalValueAsDecString() const = 0; |
| 54 | + virtual String getFinalValueAsHexString() const = 0; |
| 55 | + virtual String getFinalValueAsOctString() const = 0; |
| 56 | + |
| 57 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CRCAtom) |
| 58 | + }; |
| 59 | + |
| 60 | + struct CRC8Atom final : public CRCAtom |
| 61 | + { |
| 62 | + CRC8Atom() = default; |
| 63 | + |
| 64 | + void configure (uint64 poly, uint64 xorIn, uint64 xorOut, bool refIn, bool refOut) override |
| 65 | + { |
| 66 | + crc = std::make_unique<CRCType> ((Type) poly, (Type) xorIn, (Type) xorOut, refIn, refOut); |
| 67 | + } |
| 68 | + |
| 69 | + uint8 getNumBits() const override { return 8; } |
| 70 | + uint64 getCheckValue() const override { return {}; } |
| 71 | + String getCheckString() const override { return {}; } |
| 72 | + uint64 getFinalValue() const override { return {}; } |
| 73 | + String getFinalValueAsDecString() const override { return {}; } |
| 74 | + String getFinalValueAsHexString() const override { return {}; } |
| 75 | + String getFinalValueAsOctString() const override { return {}; } |
| 76 | + |
| 77 | + using Type = uint8; |
| 78 | + using CRCType = CRC<Type>; |
| 79 | + std::unique_ptr<CRCType> crc; |
| 80 | + |
| 81 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CRC8Atom) |
| 82 | + }; |
| 83 | + |
| 84 | + struct CRC16Atom final : public CRCAtom |
| 85 | + { |
| 86 | + CRC16Atom() = default; |
| 87 | + |
| 88 | + void configure (uint64 poly, uint64 xorIn, uint64 xorOut, bool refIn, bool refOut) override |
| 89 | + { |
| 90 | + crc = std::make_unique<CRCType> ((Type) poly, (Type) xorIn, (Type) xorOut, refIn, refOut); |
| 91 | + } |
| 92 | + |
| 93 | + uint8 getNumBits() const override { return 16; } |
| 94 | + uint64 getCheckValue() const override { return {}; } |
| 95 | + String getCheckString() const override { return {}; } |
| 96 | + uint64 getFinalValue() const override { return {}; } |
| 97 | + String getFinalValueAsDecString() const override { return {}; } |
| 98 | + String getFinalValueAsHexString() const override { return {}; } |
| 99 | + String getFinalValueAsOctString() const override { return {}; } |
| 100 | + |
| 101 | + using Type = uint16; |
| 102 | + using CRCType = CRC<Type>; |
| 103 | + std::unique_ptr<CRCType> crc; |
| 104 | + |
| 105 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CRC16Atom) |
| 106 | + }; |
| 107 | + |
| 108 | + struct CRC32Atom final : public CRCAtom |
| 109 | + { |
| 110 | + CRC32Atom() = default; |
| 111 | + |
| 112 | + void configure (uint64 poly, uint64 xorIn, uint64 xorOut, bool refIn, bool refOut) override |
| 113 | + { |
| 114 | + crc = std::make_unique<CRCType> ((Type) poly, (Type) xorIn, (Type) xorOut, refIn, refOut); |
| 115 | + } |
| 116 | + |
| 117 | + uint8 getNumBits() const override { return 32; } |
| 118 | + uint64 getCheckValue() const override { return {}; } |
| 119 | + String getCheckString() const override { return {}; } |
| 120 | + uint64 getFinalValue() const override { return {}; } |
| 121 | + String getFinalValueAsDecString() const override { return {}; } |
| 122 | + String getFinalValueAsHexString() const override { return {}; } |
| 123 | + String getFinalValueAsOctString() const override { return {}; } |
| 124 | + |
| 125 | + using Type = uint32; |
| 126 | + using CRCType = CRC<Type>; |
| 127 | + std::unique_ptr<CRCType> crc; |
| 128 | + |
| 129 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CRC32Atom) |
| 130 | + }; |
| 131 | + |
| 132 | + struct CRC64Atom final : public CRCAtom |
| 133 | + { |
| 134 | + CRC64Atom() = default; |
| 135 | + |
| 136 | + void configure (uint64 poly, uint64 xorIn, uint64 xorOut, bool refIn, bool refOut) override |
| 137 | + { |
| 138 | + crc = std::make_unique<CRCType> ((Type) poly, (Type) xorIn, (Type) xorOut, refIn, refOut); |
| 139 | + } |
| 140 | + |
| 141 | + uint8 getNumBits() const override { return 64; } |
| 142 | + uint64 getCheckValue() const override { return {}; } |
| 143 | + String getCheckString() const override { return {}; } |
| 144 | + uint64 getFinalValue() const override { return {}; } |
| 145 | + String getFinalValueAsDecString() const override { return {}; } |
| 146 | + String getFinalValueAsHexString() const override { return {}; } |
| 147 | + String getFinalValueAsOctString() const override { return {}; } |
| 148 | + |
| 149 | + using Type = uint64; |
| 150 | + using CRCType = CRC<Type>; |
| 151 | + std::unique_ptr<CRCType> crc; |
| 152 | + |
| 153 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CRC64Atom) |
| 154 | + }; |
| 155 | + |
| 156 | + std::unique_ptr<CRC8Atom> crc8; |
| 157 | + std::unique_ptr<CRC16Atom> crc16; |
| 158 | + std::unique_ptr<CRC32Atom> crc32; |
| 159 | + std::unique_ptr<CRC64Atom> crc64; |
| 160 | + |
| 161 | + //============================================================================== |
| 162 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CRCDataUnit) |
| 163 | +}; |
| 164 | + |
| 165 | +//============================================================================== |
| 166 | +/** |
| 167 | +*/ |
| 168 | +class CRCTableHeaderComponent final : public TableHeaderComponent |
| 169 | +{ |
| 170 | +public: |
| 171 | + CRCTableHeaderComponent() |
| 172 | + { |
| 173 | + } |
| 174 | + |
| 175 | +private: |
| 176 | + //============================================================================== |
| 177 | + |
| 178 | + |
| 179 | + //============================================================================== |
| 180 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CRCTableHeaderComponent) |
| 181 | +}; |
| 182 | + |
| 183 | +//============================================================================== |
| 184 | +/** |
| 185 | +*/ |
| 186 | +class CRCTableListBoxModel final : public TableListBoxModel |
| 187 | +{ |
| 188 | +public: |
| 189 | + CRCTableListBoxModel() |
| 190 | + { |
| 191 | + } |
| 192 | + |
| 193 | + //============================================================================== |
| 194 | + int getNumRows() override |
| 195 | + { |
| 196 | + return dataUnits.size(); |
| 197 | + } |
| 198 | + |
| 199 | + void paintRowBackground (Graphics& g, int rowNumber, int width, int height, bool rowIsSelected) override |
| 200 | + { |
| 201 | + } |
| 202 | + |
| 203 | + void paintCell (Graphics& g, int rowNumber, int columnId, int width, int height, bool rowIsSelected) override |
| 204 | + { |
| 205 | + } |
| 206 | + |
| 207 | +private: |
| 208 | + //============================================================================== |
| 209 | + OwnedArray<CRCDataUnit> dataUnits; |
| 210 | + |
| 211 | + //============================================================================== |
| 212 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CRCTableListBoxModel) |
| 213 | +}; |
| 214 | + |
| 215 | +//============================================================================== |
| 216 | +/** |
| 217 | +*/ |
| 218 | +class CRCDemo final : public DemoBase |
| 219 | +{ |
| 220 | +public: |
| 221 | + CRCDemo (SharedObjects& sharedObjs) : |
| 222 | + DemoBase (sharedObjs, NEEDS_TRANS ("CRC")) |
| 223 | + { |
| 224 | + { |
| 225 | + CRC<uint8> crcTest (0x07); |
| 226 | + const auto r = (uint8) crcTest.processByte (0x61).get(); |
| 227 | + // jassert (r == 0x36); |
| 228 | + } |
| 229 | + |
| 230 | + tableListBox.setModel (&crcTableListBoxModel); |
| 231 | + tableListBox.setHeader (std::make_unique<CRCTableHeaderComponent>()); |
| 232 | + addAndMakeVisible (tableListBox); |
| 233 | + |
| 234 | + updateWithNewTranslations(); |
| 235 | + } |
| 236 | + |
| 237 | + ~CRCDemo() override |
| 238 | + { |
| 239 | + tableListBox.setModel (nullptr); |
| 240 | + } |
| 241 | + |
| 242 | + //============================================================================== |
| 243 | + void resized() override |
| 244 | + { |
| 245 | + auto b = getLocalBounds(); |
| 246 | + tableListBox.setBounds (b); |
| 247 | + } |
| 248 | + |
| 249 | + void updateWithNewTranslations() override |
| 250 | + { |
| 251 | + SQUAREPINE_CRASH_TRACER |
| 252 | + tableListBox.updateContent(); |
| 253 | + repaint(); |
| 254 | + } |
| 255 | + |
| 256 | + //============================================================================== |
| 257 | + |
| 258 | +private: |
| 259 | + //============================================================================== |
| 260 | + CRCTableListBoxModel crcTableListBoxModel; |
| 261 | + TableListBox tableListBox; |
| 262 | + |
| 263 | + //============================================================================== |
| 264 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CRCDemo) |
| 265 | +}; |
0 commit comments