OpenASIP  2.0
ProgramAnnotation.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 ProgramAnnotation.cc
26  *
27  * Implementation of ProgramAnnotation class.
28  *
29  * @author Pekka Jääskeläinen 2006,2014 (pekka.jaaskelainen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 #include "ProgramAnnotation.hh"
35 #include "Conversion.hh"
36 #include "InstructionElement.hh"
37 
38 namespace TTAProgram {
39 
40 /////////////////////////////////////////////////////////////////////////////
41 // ProgramAnnotation
42 /////////////////////////////////////////////////////////////////////////////
43 
44 /**
45  * Constructor.
46  *
47  * @note Exceeding the maximum annotation length of TPEF leads
48  * to an assertion!
49  *
50  * @param id The id of the annotation (a 24-bit value).
51  * @param data The payload data as a string.
52  */
53 ProgramAnnotation::ProgramAnnotation(Id id, const std::string& data) :
54  id_(id) {
55  assert(data.length() <=
57  setStringValue(data);
58 }
59 
61  id_(id) {
62  setIntValue(value);
63 }
64 
65 /**
66  * Constructor.
67  *
68  * @param id The id of the annotation (a 24-bit value).
69  * @param data The payload data as a byte vector.
70  */
72  Id id, const std::vector<Byte>& payload) :
73  id_(id), payload_(payload) {
74  assert(payload.size() <=
76 }
77 
78 /**
79  * Destructor.
80  */
82 }
83 
84 /**
85  * The payload data as a std::string.
86  *
87  * @returns The data as a std::string.
88  */
89 std::string
91  return std::string(payload_.begin(), payload_.end());
92 }
93 
94 int
97 }
98 
99 void
101  std::string data = Conversion::toString(value);
102  payload_ = std::vector<Byte>(data.begin(), data.end());
103 }
104 
105 /**
106  * Returns the id of the annotation.
107  *
108  * @return the id of the annotation.
109  */
112  return id_;
113 }
114 
115 /**
116  * Return the payload data as a non-mutable char vector.
117  *
118  * @return The payload data.
119  */
120 const std::vector<Byte>&
122  return payload_;
123 }
124 
125 } // namespace TTAProgram
TTAProgram
Definition: Estimator.hh:65
TTAProgram::ProgramAnnotation::stringValue
std::string stringValue() const
Definition: ProgramAnnotation.cc:90
TPEF::InstructionAnnotation::MAX_ANNOTATION_BYTES
static const size_t MAX_ANNOTATION_BYTES
Maximum number of bytes that annotation may contain.
Definition: InstructionElement.hh:65
InstructionElement.hh
Conversion::toString
static std::string toString(const T &source)
TTAProgram::ProgramAnnotation::Id
Id
the ID in TPEF is 24 bits, here enum
Definition: ProgramAnnotation.hh:52
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::ProgramAnnotation::id
ProgramAnnotation::Id id() const
Definition: ProgramAnnotation.cc:111
TTAProgram::ProgramAnnotation::intValue
int intValue() const
Definition: ProgramAnnotation.cc:95
TTAProgram::ProgramAnnotation::id_
Id id_
the id
Definition: ProgramAnnotation.hh:226
Conversion.hh
TTAProgram::ProgramAnnotation::setIntValue
void setIntValue(int value)
Definition: ProgramAnnotation.cc:100
TTAProgram::ProgramAnnotation::payload_
std::vector< Byte > payload_
the payload data
Definition: ProgramAnnotation.hh:228
TTAProgram::ProgramAnnotation::setStringValue
void setStringValue(const std::string &data)
Definition: ProgramAnnotation.hh:216
TTAProgram::ProgramAnnotation::~ProgramAnnotation
~ProgramAnnotation()
Definition: ProgramAnnotation.cc:81
TTAProgram::ProgramAnnotation::ProgramAnnotation
ProgramAnnotation(Id id, int value)
Definition: ProgramAnnotation.cc:60
Conversion::toInt
static int toInt(const T &source)
ProgramAnnotation.hh
TTAProgram::ProgramAnnotation::payload
const std::vector< Byte > & payload() const
Definition: ProgramAnnotation.cc:121