src/blfwk/DataTarget.h
/*
* Copyright (c) 2013-14, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(_DataTarget_h_)
#define _DataTarget_h_
#include "stdafx.h"
#include "DataSource.h"
namespace blfwk
{
// Forward declaration
class DataSource;
class DataTarget
{
public:
struct AddressRange
{
uint32_t m_begin;
uint32_t m_end;
};
public:
DataTarget()
: m_source(0)
{
}
virtual ~DataTarget() {}
virtual bool isBounded() { return false; }
virtual uint32_t getBeginAddress() { return 0; }
virtual uint32_t getEndAddress() { return 0; }
virtual DataTarget::AddressRange getRangeForSegment(DataSource &source, DataSource::Segment &segment) = 0;
inline void setSource(DataSource *source) { m_source = source; }
inline DataSource *getSource() const { return m_source; }
protected:
DataSource *m_source;
};
class ConstantDataTarget : public DataTarget
{
public:
ConstantDataTarget(uint32_t start)
: DataTarget()
, m_begin(start)
, m_end(0)
, m_hasEnd(false)
{
}
ConstantDataTarget(uint32_t start, uint32_t end)
: DataTarget()
, m_begin(start)
, m_end(end)
, m_hasEnd(true)
{
}
virtual bool isBounded() { return m_hasEnd; }
virtual uint32_t getBeginAddress() { return m_begin; }
virtual uint32_t getEndAddress() { return m_end; }
virtual DataTarget::AddressRange getRangeForSegment(DataSource &source, DataSource::Segment &segment);
protected:
uint32_t m_begin;
uint32_t m_end;
bool m_hasEnd;
};
class NaturalDataTarget : public DataTarget
{
public:
NaturalDataTarget()
: DataTarget()
{
}
virtual bool isBounded() { return true; }
virtual DataTarget::AddressRange getRangeForSegment(DataSource &source, DataSource::Segment &segment);
};
}; // namespace blfwk
#endif // _DataTarget_h_
blfwk::ConstantDataTarget::m_end
uint32_t m_end
End address.
Definition: src/blfwk/DataTarget.h:127
blfwk
Definition: BlfwkErrors.h:16
blfwk::ConstantDataTarget::isBounded
virtual bool isBounded()
The target is bounded if an end address was specified.
Definition: src/blfwk/DataTarget.h:119
blfwk::NaturalDataTarget
Target address that is the "natural" location of whatever the source data is.
Definition: src/blfwk/DataTarget.h:138
blfwk::DataTarget::AddressRange
Simple structure that describes an addressed region of memory.
Definition: src/blfwk/DataTarget.h:62
blfwk::DataTarget::m_source
DataSource * m_source
Corresponding data source for this target.
Definition: src/blfwk/DataTarget.h:87
blfwk::NaturalDataTarget::NaturalDataTarget
NaturalDataTarget()
Default constructor.
Definition: src/blfwk/DataTarget.h:142
blfwk::DataTarget
Abstract base class for the target address or range of data.
Definition: src/blfwk/DataTarget.h:57
blfwk::ConstantDataTarget::m_begin
uint32_t m_begin
Start address.
Definition: src/blfwk/DataTarget.h:126
blfwk::ConstantDataTarget::ConstantDataTarget
ConstantDataTarget(uint32_t start, uint32_t end)
Constructor taking both begin and end addresses.
Definition: src/blfwk/DataTarget.h:110
blfwk::ConstantDataTarget
Target with a constant values for the addresses.
Definition: src/blfwk/DataTarget.h:97
blfwk::DataSource::Segment
Discrete, contiguous part of the source&#39;s data.
Definition: src/blfwk/DataSource.h:65
blfwk::ConstantDataTarget::ConstantDataTarget
ConstantDataTarget(uint32_t start)
Constructor taking only a begin address.
Definition: src/blfwk/DataTarget.h:101
blfwk::DataSource
Abstract base class for data sources.
Definition: src/blfwk/DataSource.h:56
blfwk::ConstantDataTarget::m_hasEnd
bool m_hasEnd
Was an end address specified?
Definition: src/blfwk/DataTarget.h:128
blfwk::DataTarget::DataTarget
DataTarget()
Default constructor.
Definition: src/blfwk/DataTarget.h:70
blfwk::NaturalDataTarget::isBounded
virtual bool isBounded()
Natural data targets are bounded by their source&#39;s segment lengths.
Definition: src/blfwk/DataTarget.h:148
blfwk::DataTarget::~DataTarget
virtual ~DataTarget()
Destructor.
Definition: src/blfwk/DataTarget.h:76
blfwk::DataTarget::isBounded
virtual bool isBounded()
Whether the target is just a single address or has an end to it.
Definition: src/blfwk/DataTarget.h:78
blfwk::DataTarget::getRangeForSegment
virtual DataTarget::AddressRange getRangeForSegment(DataSource &source, DataSource::Segment &segment)=0
Return the address range for a segment of a data source.