1 module qrcode.common.ecblocks;
2 
3 struct EcBlock
4 {
5     int count;
6     int dataCodewords;
7 }
8 
9 class EcBlocks
10 {
11 
12     /**
13 	* Number of EC codewords per block.
14 	*
15 	* @var integer
16 	*/
17     protected int ecCodewordsPerBlock;
18     /**
19 	* List of EC blocks.
20 	*
21 	* @var SplFixedArray
22 	*/
23     protected EcBlock[] ecBlocks;
24     /**
25 	* Creates a new EC blocks instance.
26 	*
27 	* @param integer      $ecCodewordsPerBlock
28 	* @param EcBlock      $ecb1
29 	* @param EcBlock|null $ecb2
30 	*/
31     this(int ecCodewordsPerBlock, EcBlock* ecb1, EcBlock* ecb2)
32     {
33         this.ecCodewordsPerBlock = ecCodewordsPerBlock;
34 
35         this.ecBlocks = new EcBlock[2];
36         this.ecBlocks[0] = *ecb1;
37         this.ecBlocks[1] = *ecb2;
38     }
39 
40     this(int ecCodewordsPerBlock, EcBlock* ecb1)
41     {
42         this.ecCodewordsPerBlock = ecCodewordsPerBlock;
43         this.ecBlocks = new EcBlock[1];
44         this.ecBlocks[0] = *ecb1;
45 
46     }
47     /**
48 	* Gets the number of EC codewords per block.
49 	*
50 	* @return integer
51 	*/
52     public int getEcCodewordsPerBlock()
53     {
54         return this.ecCodewordsPerBlock;
55     }
56     /**
57 	* Gets the total number of EC block appearances.
58 	*
59 	* @return integer
60 	*/
61     public int getNumBlocks()
62     {
63         auto total = 0;
64         foreach (ecBlock; this.ecBlocks)
65         {
66             total += ecBlock.count;
67         }
68         return total;
69     }
70     /**
71 	* Gets the total count of EC codewords.
72 	*
73 	* @return integer
74 	*/
75     public int getTotalEcCodewords()
76     {
77         return this.ecCodewordsPerBlock * this.getNumBlocks();
78     }
79     /**
80 	* Gets the EC blocks included in this collection.
81 	*
82 	* @return SplFixedArray
83 	*/
84     public EcBlock[] getEcBlocks()
85     {
86         return ecBlocks;
87     }
88 }