ErrorCorrectionLevel.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
  2. /*
  3. * ErrorCorrectionLevel.cpp
  4. * zxing
  5. *
  6. * Created by Christian Brunschen on 15/05/2008.
  7. * Copyright 2008-2011 ZXing authors All rights reserved.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. #include <zxing/qrcode/ErrorCorrectionLevel.h>
  22. using std::string;
  23. namespace zxing {
  24. namespace qrcode {
  25. ErrorCorrectionLevel::ErrorCorrectionLevel(int inOrdinal,
  26. int bits,
  27. char const* name) :
  28. ordinal_(inOrdinal), bits_(bits), name_(name) {}
  29. int ErrorCorrectionLevel::ordinal() const {
  30. return ordinal_;
  31. }
  32. int ErrorCorrectionLevel::bits() const {
  33. return bits_;
  34. }
  35. string const& ErrorCorrectionLevel::name() const {
  36. return name_;
  37. }
  38. ErrorCorrectionLevel::operator string const& () const {
  39. return name_;
  40. }
  41. ErrorCorrectionLevel& ErrorCorrectionLevel::forBits(int bits) {
  42. if (bits < 0 || bits >= N_LEVELS) {
  43. throw ReaderException("Ellegal error correction level bits");
  44. }
  45. return *FOR_BITS[bits];
  46. }
  47. ErrorCorrectionLevel ErrorCorrectionLevel::L(0, 0x01, "L");
  48. ErrorCorrectionLevel ErrorCorrectionLevel::M(1, 0x00, "M");
  49. ErrorCorrectionLevel ErrorCorrectionLevel::Q(2, 0x03, "Q");
  50. ErrorCorrectionLevel ErrorCorrectionLevel::H(3, 0x02, "H");
  51. ErrorCorrectionLevel *ErrorCorrectionLevel::FOR_BITS[] = { &M, &L, &H, &Q };
  52. int ErrorCorrectionLevel::N_LEVELS = 4;
  53. }
  54. }