~dpm/+junk/cam-preview-tests

« back to all changes in this revision

Viewing changes to zxing/qrcode/QRErrorCorrectionLevel.cpp

  • Committer: David Planella
  • Date: 2013-06-03 07:55:58 UTC
  • Revision ID: david.planella@ubuntu.com-20130603075558-mpdlkczwnljai3im
Initial commit. This is experimental, playground code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
22
#include <zxing/qrcode/ErrorCorrectionLevel.h>
 
23
 
 
24
using std::string;
 
25
 
 
26
namespace zxing {
 
27
namespace qrcode {
 
28
 
 
29
ErrorCorrectionLevel::ErrorCorrectionLevel(int inOrdinal,
 
30
                                           int bits,
 
31
                                           char const* name) :
 
32
  ordinal_(inOrdinal), bits_(bits), name_(name) {}
 
33
 
 
34
int ErrorCorrectionLevel::ordinal() const {
 
35
  return ordinal_;
 
36
}
 
37
 
 
38
int ErrorCorrectionLevel::bits() const {
 
39
  return bits_;
 
40
}
 
41
 
 
42
string const& ErrorCorrectionLevel::name() const {
 
43
  return name_;
 
44
}
 
45
 
 
46
ErrorCorrectionLevel::operator string const& () const {
 
47
  return name_;
 
48
}
 
49
 
 
50
ErrorCorrectionLevel& ErrorCorrectionLevel::forBits(int bits) {
 
51
  if (bits < 0 || bits >= N_LEVELS) {
 
52
    throw ReaderException("Ellegal error correction level bits");
 
53
  }
 
54
  return *FOR_BITS[bits];
 
55
}
 
56
 
 
57
  ErrorCorrectionLevel ErrorCorrectionLevel::L(0, 0x01, "L");
 
58
  ErrorCorrectionLevel ErrorCorrectionLevel::M(1, 0x00, "M");
 
59
  ErrorCorrectionLevel ErrorCorrectionLevel::Q(2, 0x03, "Q");
 
60
  ErrorCorrectionLevel ErrorCorrectionLevel::H(3, 0x02, "H");
 
61
ErrorCorrectionLevel *ErrorCorrectionLevel::FOR_BITS[] = { &M, &L, &H, &Q };
 
62
int ErrorCorrectionLevel::N_LEVELS = 4;
 
63
 
 
64
}
 
65
}