DataBlock.hh (9181:42807286d6cb) DataBlock.hh (9208:2451e60d4555)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 15 unchanged lines hidden (view full) ---

24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __MEM_RUBY_COMMON_DATABLOCK_HH__
30#define __MEM_RUBY_COMMON_DATABLOCK_HH__
31
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 15 unchanged lines hidden (view full) ---

24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __MEM_RUBY_COMMON_DATABLOCK_HH__
30#define __MEM_RUBY_COMMON_DATABLOCK_HH__
31
32#include <inttypes.h>
33
32#include <cassert>
33#include <iomanip>
34#include <iostream>
35
34#include <cassert>
35#include <iomanip>
36#include <iostream>
37
36#include "mem/ruby/common/TypeDefines.hh"
37
38class DataBlock
39{
40 public:
41 DataBlock()
42 {
43 alloc();
44 }
45
46 DataBlock(const DataBlock &cp);
47
48 ~DataBlock()
49 {
50 if (m_alloc)
51 delete [] m_data;
52 }
53
54 DataBlock& operator=(const DataBlock& obj);
55
38class DataBlock
39{
40 public:
41 DataBlock()
42 {
43 alloc();
44 }
45
46 DataBlock(const DataBlock &cp);
47
48 ~DataBlock()
49 {
50 if (m_alloc)
51 delete [] m_data;
52 }
53
54 DataBlock& operator=(const DataBlock& obj);
55
56 void assign(uint8* data);
56 void assign(uint8_t *data);
57
58 void clear();
57
58 void clear();
59 uint8 getByte(int whichByte) const;
60 const uint8* getData(int offset, int len) const;
61 void setByte(int whichByte, uint8 data);
62 void setData(uint8* data, int offset, int len);
59 uint8_t getByte(int whichByte) const;
60 const uint8_t *getData(int offset, int len) const;
61 void setByte(int whichByte, uint8_t data);
62 void setData(uint8_t *data, int offset, int len);
63 void copyPartial(const DataBlock & dblk, int offset, int len);
64 bool equal(const DataBlock& obj) const;
65 void print(std::ostream& out) const;
66
67 private:
68 void alloc();
63 void copyPartial(const DataBlock & dblk, int offset, int len);
64 bool equal(const DataBlock& obj) const;
65 void print(std::ostream& out) const;
66
67 private:
68 void alloc();
69 uint8* m_data;
69 uint8_t *m_data;
70 bool m_alloc;
71};
72
73inline void
70 bool m_alloc;
71};
72
73inline void
74DataBlock::assign(uint8* data)
74DataBlock::assign(uint8_t *data)
75{
76 assert(data != NULL);
77 if (m_alloc) {
78 delete [] m_data;
79 }
80 m_data = data;
81 m_alloc = false;
82}
83
75{
76 assert(data != NULL);
77 if (m_alloc) {
78 delete [] m_data;
79 }
80 m_data = data;
81 m_alloc = false;
82}
83
84inline uint8
84inline uint8_t
85DataBlock::getByte(int whichByte) const
86{
87 return m_data[whichByte];
88}
89
90inline void
85DataBlock::getByte(int whichByte) const
86{
87 return m_data[whichByte];
88}
89
90inline void
91DataBlock::setByte(int whichByte, uint8 data)
91DataBlock::setByte(int whichByte, uint8_t data)
92{
93 m_data[whichByte] = data;
94}
95
96inline void
97DataBlock::copyPartial(const DataBlock & dblk, int offset, int len)
98{
99 setData(&dblk.m_data[offset], offset, len);

--- 17 unchanged lines hidden ---
92{
93 m_data[whichByte] = data;
94}
95
96inline void
97DataBlock::copyPartial(const DataBlock & dblk, int offset, int len)
98{
99 setData(&dblk.m_data[offset], offset, len);

--- 17 unchanged lines hidden ---