📄 filecontainer.h
字号:
/*
* TOPPERS/JSP Kernel
* Toyohashi Open Platform for Embedded Real-Time Systems/
* Just Standard Profile Kernel
*
* Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
* Toyohashi Univ. of Technology, JAPAN
*
* 忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation
* 偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
* 弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
* 傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
* 棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
* (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
* 尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
* 僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
* (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
* 幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
* 偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
* 偲丏
* (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
* 嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
* 曬崘偡傞偙偲丏
* (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
* 奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
*
* 杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
* 傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
* 娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
* 愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
*
* @(#) $Id: filecontainer.h,v 1.1 2006/04/14 02:46:05 9564907 Exp $
*/
// $Header: J:\\SapporoSoft\\usb20\\S1R72V05\\Debug\\Repository/S1R72V05_Toppers/Toppers/cfg/base/filecontainer.h,v 1.1 2006/04/14 02:46:05 9564907 Exp $
#ifndef FILECONTAINER_H
#define FILECONTAINER_H
#ifdef _MSC_VER
#pragma warning(disable:4786) //僨僶僢僌忣曬傪255暥帤偵愗傝媗傔傑偟偨
#endif
#include "testsuite.h"
#include <string>
#include <map>
#include "base/except.h"
#include "base/message.h"
#include "base/collection.h"
class FileContainer : public RuntimeObject
{
public:
typedef unsigned long address_t;
struct tagVariableInfo {
address_t address;
union {
size_t size;
int value;
};
};
enum tagByteOrder { LITTLE, BIG, HOSTORDER=LITTLE, UNKNOWN }; /* UNKNOWN偼僥僗僩梡 */
protected:
enum tagByteOrder byteorder;
std::map<std::string, struct tagVariableInfo> variableinfo;
FileContainer(void) throw() : byteorder(HOSTORDER) {}
virtual ~FileContainer(void) throw() {}
public:
/* 僀儞僞僼僃乕僗晹 */
virtual void attachModule(const std::string & filename) throw(Exception) = 0;
virtual void loadContents(void * dest, address_t address, size_t size) throw(Exception) = 0;
virtual address_t getSymbolAddress(const std::string & symbol) throw(Exception) = 0;
virtual std::string getArchitecture(void) throw(Exception) = 0;
virtual struct tagVariableInfo getVariableInfo(const std::string & name) throw(Exception);
virtual void attachInfo(const std::string & filename) throw(Exception);
/* 搊榐偝傟偰偄傞僐儞僥僫偺屇傃弌偟 */
static inline FileContainer * getInstance(void) throw(Exception)
{
FileContainer * result;
RuntimeObjectTable::getInstance(&result);
if(result == 0)
ExceptionMessage("[Internal error] Filecontainer has no instance.","[撪晹僄儔乕] FileContainer偺僀儞僗僞儞僗偑偁傝傑偣傫").throwException();
return result;
}
enum tagByteOrder getByteOrder(void) const
{ return byteorder; }
};
class TargetVariableBase
{
protected:
FileContainer::address_t address; //曄悢偺傾僪儗僗
size_t size; //曄悢偺僒僀僘
size_t offset; //懏偡傞峔憿懱偺愭摢偐傜偺僆僼僙僢僩
size_t structure_size; //懏偡傞峔憿懱偺戝偒偝
bool loaded; //抣偑撉弌偟嵪傒偱偁傞偙偲傪曐帩偡傞僼儔僌
inline TargetVariableBase(FileContainer::address_t _address, size_t _size) throw()
: address(_address), size(_size), offset(0), structure_size(_size), loaded(false)
{}
inline TargetVariableBase(FileContainer::address_t addr, size_t sz, size_t ofs, size_t ssz) throw()
: address(addr), size(sz), offset(ofs), structure_size(ssz), loaded(false)
{}
TargetVariableBase(const std::string & sym) throw();
TargetVariableBase(const std::string & sym, size_t _size) throw();
TargetVariableBase(const std::string & sym, const std::string & sz) throw();
TargetVariableBase(const TargetVariableBase & src) throw();
virtual ~TargetVariableBase(void) throw() {}
/* 撪梕偺庢摼 */
void loadContent(void * dest, size_t dest_size) throw(Exception);
/* 僄儞僨傿傾儞曄姺 */
void changeEndian(char * buffer, size_t size) throw();
/* 傾僪儗僗偺堏摦 (偮偄偱偵loaded傪壓偘傞) */
inline void setAddress(int offset) throw()
{
if(isValid()) {
address += offset;
loaded = false;
}
}
public:
inline bool isValid(void) const throw()
{ return this != 0 && address != 0 && size != 0 && structure_size != 0; }
inline size_t getSize(void) const throw()
{ return this != 0 ? size : 0; }
inline size_t getOffset(void) const throw()
{ return this != 0 ? offset : 0; }
inline size_t getStructureSize(void) const throw()
{ return this != 0 ? structure_size : 0; }
inline FileContainer::address_t getAddress(void) const throw()
{ return this != 0 ? address : 0; }
inline bool isLoaded(void) const throw()
{ return this != 0 ? loaded : false; }
/* 婎杮揑側憖嶌 */
inline bool operator == (const TargetVariableBase & right) const throw()
{ return isValid() && right.isValid() && address == right.address; }
inline bool operator != (const TargetVariableBase & right) const throw()
{ return ! operator ==(right); }
inline FileContainer::address_t operator & (void) const throw()
{ return isValid() ? address + offset : 0; }
inline size_t sizeOf(void) const throw()
{ return isValid() ? size : 0; }
};
template<class T>
class TargetVariable : public TargetVariableBase
{
protected:
T entity;
public:
/*
* 僐儞僗僩儔僋僞 (TargetVariableBase偵夞憲)
*/
inline TargetVariable(FileContainer::address_t addr) throw()
: TargetVariableBase(addr, sizeof(T)), entity()
{}
inline TargetVariable(FileContainer::address_t addr, size_t sz) throw()
: TargetVariableBase(addr, sz), entity()
{}
inline TargetVariable(FileContainer::address_t addr, size_t sz, size_t ofs, size_t ssz) throw()
: TargetVariableBase(addr, sz, ofs, ssz), entity()
{}
inline TargetVariable(const std::string & sym) throw()
: TargetVariableBase(sym), entity()
{}
inline TargetVariable(const std::string & sym, const std::string & sz) throw()
: TargetVariableBase(sym, sz), entity()
{}
inline TargetVariable(const TargetVariable<T> & src) throw()
: TargetVariableBase(src), entity()
{
if(isValid() && src.isValid()) {
loaded = src.loaded;
entity = src.entity;
}
}
/* 僨僗僩儔僋僞 (摿偵壗傕偟側偄) */
virtual ~TargetVariable(void) throw()
{}
/* 惓摉敾掕偵奿擺偵廫暘側僒僀僘偑偁傞偐偳偆偐傪捛壛偟偰偍偔 */
inline bool isValid(void) const
{ return TargetVariableBase::isValid() && (sizeof(T) >= getSize()); }
/*
* 億僀儞僞晽偺摦嶌傪偡傞僆儁儗乕僞孮
*/
inline TargetVariable<T> offsetInBytes(int offset) const throw()
{ return TargetVariable<T>(getAddress() + offset, getSize(), getOffset(), getStructureSize()); }
inline TargetVariable<T> operator + (int index) const throw()
{ return offsetInBytes(index * static_cast<int>(getStructureSize())); }
inline TargetVariable<T> operator - (int index) const throw()
{ return offsetInBytes(- index * static_cast<int>(getStructureSize())); }
inline TargetVariable<T> operator ++ (int) throw()
{
TargetVariable<T> result(*this);
++ (*this);
return result;
}
inline TargetVariable<T> operator -- (int) throw()
{
TargetVariable<T> result(*this);
-- (*this);
return result;
}
inline TargetVariable<T> & operator ++ (void) throw()
{
setAddress(static_cast<int>(getStructureSize()));
return *this;
}
inline TargetVariable<T> & operator -- (void) throw()
{
setAddress(-static_cast<int>(getStructureSize()));
return *this;
}
inline TargetVariable<T> & operator += (int sz) throw()
{
setAddress(static_cast<int>(getStructureSize()) * sz);
return *this;
}
inline TargetVariable<T> & operator -= (int sz) throw()
{
setAddress(-static_cast<int>(getStructureSize()) * sz);
return *this;
}
inline const T & operator * (void) throw(Exception)
{
if(!isLoaded())
loadContent(&entity, sizeof(T));
return entity;
}
inline T operator [] (int index) const throw(Exception)
{ return * TargetVariable<T>(getAddress() + index * getStructureSize(), getSize(), getOffset(), getStructureSize()); }
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -