OpenASIP 2.2
Loading...
Searching...
No Matches
ValueReplacer.hh
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 ValueReplacer.hh
26 *
27 * Declaration of ValueReplacer class.
28 *
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30 *
31 * @note rating: yellow
32 */
33
34#ifndef TTA_REFERENCE_REPLACER_HH
35#define TTA_REFERENCE_REPLACER_HH
36
37#include <set>
38
39#include "Exception.hh"
40
41namespace TPEF {
42 class BinaryStream;
43 class SafePointable;
44/**
45 * Abstract base class of value replacer classes.
46 *
47 * A value replacer class handles writing of object references into an
48 * output binary stream. An object reference is represented with a value in
49 * the stream. The order in which reference values are computed may depend
50 * on the data already written into the stream, which may include other
51 * references whose value is not yet available. When an object reference
52 * must be written out and its corresponding value is not yet available,
53 * value replacers are used.
54 *
55 * E.g., If file offset to the body of the section should is written
56 * while writing section header, FileOffsetReplacer is used
57 * to write FileOffset of the first element of the section.
58 * When file offset of the first element is known, the
59 * FileOffsetReplacer object knows where to replace write that offset.
60 *
61 * Value replacers defer the writing of the actual reference values. A
62 * dummy reference value is written out in stream sequential order and later
63 * replaced witht he actual value whent his becomes available.
64 *
65 * The ValueReplacer base class is not a pure interface: it handles all
66 * bookkeeping of deferred replacements.
67 *
68 * Each concrete value replacer handles the writing of reference to a
69 * specific object type in a specific data format.
70 */
72public:
73 static void finalize();
74
75 static void initialize(BinaryStream& stream);
76
77 void resolve();
78
79protected:
80 ValueReplacer(const SafePointable* obj);
81
82 ValueReplacer(const ValueReplacer& replacer);
83
84 virtual ~ValueReplacer();
85
86 /// Does replacement if can. If can't returns false.
87 virtual bool tryToReplace() = 0;
88
89 /// Creates dynamically allocated clone of object.
90 virtual ValueReplacer* clone() = 0;
91
92 static BinaryStream& stream();
93 const SafePointable* reference() const;
94 unsigned int streamPosition() const;
95
96private:
97 static void addReplacement(ValueReplacer* obj);
98
99 /// File offset where replacement is done.
100 unsigned int streamPosition_;
101 /// Reference which to be written.
103 /// Stream for writing replacements.
105
106 /// Replacements which should be done afterwards.
107 static std::set<ValueReplacer*> replacements_;
108};
109}
110
111#endif
static BinaryStream & stream()
static void finalize()
static void initialize(BinaryStream &stream)
static std::set< ValueReplacer * > replacements_
Replacements which should be done afterwards.
static void addReplacement(ValueReplacer *obj)
virtual ValueReplacer * clone()=0
Creates dynamically allocated clone of object.
unsigned int streamPosition_
File offset where replacement is done.
virtual bool tryToReplace()=0
Does replacement if can. If can't returns false.
static BinaryStream * stream_
Stream for writing replacements.
unsigned int streamPosition() const
const SafePointable * reference() const
const SafePointable * reference_
Reference which to be written.