OpenASIP 2.2
Loading...
Searching...
No Matches
BitVector.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file BitVector.cc
26 *
27 * Implementation of BitVector class.
28 *
29 * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34
35#include "BitVector.hh"
36#include "MathTools.hh"
37#include "Application.hh"
38
39using std::string;
40
41/**
42 * The constructor.
43 */
46
47
48/**
49 * The constructor.
50 *
51 * Creates a bit vector that is a sub vector of the given vector.
52 *
53 * @param vector The bit vector.
54 * @param firstIndex The index of the given vector that is to be
55 * the first element in the created vector.
56 * @param lastIndex The index of the given vector that is to be that last
57 * element in the created vector.
58 * @exception OutOfRange If the given indexes are too big or too small.
59 */
61 const BitVector& vector, unsigned int firstIndex, unsigned int lastIndex) {
62 if (lastIndex < firstIndex || lastIndex >= vector.size()) {
63 const string procName = "BitVector::BitVector";
64 throw OutOfRange(__FILE__, __LINE__, procName);
65 }
66
67 BitVector::const_iterator firstIter = vector.begin();
68 firstIter += firstIndex;
69 BitVector::const_iterator lastIter = vector.begin();
70 lastIter += lastIndex + 1;
71 insert(begin(), firstIter, lastIter);
72 assert(size() == lastIndex - firstIndex + 1);
73}
74
75/**
76 * The destructor.
77 */
80
81
82/**
83 * Pushes back the given number and increases the size of the vector by the
84 * given amount.
85 *
86 * For example, if number 6 (110) is added with size 5, bits 00110 are
87 * concatenated to the vector. If size 2 is given, then bits 10 are
88 * concatenated to the vector.
89 *
90 * @param integer The number to be added.
91 * @param size The number of bits to be added.
92 */
93void
94BitVector::pushBack(long long unsigned int integer, int size) {
95 for (int i = size - 1; i >= 0; i--) {
96 push_back(MathTools::bit(integer, i));
97 }
98}
99
100
101/**
102 * Pushes back the given bit vector.
103 *
104 * @param bits The bit vector.
105 */
106void
108 reserve(size() + bits.size());
109 for (std::vector<bool>::const_iterator iter = bits.begin();
110 iter != bits.end(); iter++) {
111 push_back(*iter);
112 }
113}
114/**
115 * Pushes back the given bit.
116 *
117 * @param bit The bit to be added.
118 */
119void
121 push_back(bit);
122}
123
124/**
125 * Converts BitVector to std::string format
126 *
127 */
128
129std::string
131 std::string bits;
132 for (unsigned int i = 0; i < this->size(); i++) {
133 bits.append(std::to_string(this->at(i)));
134 }
135 return bits;
136}
#define assert(condition)
virtual ~BitVector()
Definition BitVector.cc:78
void pushBack(long long unsigned int integer, int size)
Definition BitVector.cc:94
std::string toString() const
Definition BitVector.cc:130
static bool bit(ULongWord integer, unsigned int index)