7 #ifndef __data_PathAccessor_h__ 8 #define __data_PathAccessor_h__ 10 #ifdef FE_BOOST_TOKENIZER 11 #include <boost/tokenizer.hpp> 17 class FE_DL_EXPORT VoidAccessor
21 VoidAccessor(
const String &a_path);
23 VoidAccessor &operator=(
const String &a_path);
25 void setup(
const String &a_path);
27 void *access(
const Record r_in, sp<Attribute> &a_rspAttr);
32 std::list<String> m_path;
38 class FE_DL_EXPORT PathAccessor :
public VoidAccessor
42 PathAccessor(
const String &a_path);
44 T *operator()(
const Record record);
49 class FE_DL_EXPORT ScopedPathAccessor
52 ScopedPathAccessor(
void);
53 ScopedPathAccessor(sp<Scope> a_scope,
const String &a_path);
54 ~ScopedPathAccessor(
void);
55 void setup(sp<Scope> a_scope,
const String &a_path);
56 T *operator()(
const Record record);
57 T *operator()(sp<RecordArray>& rspRA, FE_UWORD a_i);
59 Array< Accessor<Record> > m_path;
64 ScopedPathAccessor<T>::ScopedPathAccessor(
void)
69 ScopedPathAccessor<T>::ScopedPathAccessor(sp<Scope> a_scope,
72 setup(a_scope, a_path);
76 ScopedPathAccessor<T>::~ScopedPathAccessor(
void)
81 void ScopedPathAccessor<T>::setup(sp<Scope> a_scope,
const String &a_path)
85 Array<std::string> tokens;
87 #ifdef FE_BOOST_TOKENIZER 88 boost::char_separator<char> sep(
".");
89 typedef boost::tokenizer<boost::char_separator<char> > t_tokenizer;
90 std::string std_str = a_path.c_str();
91 t_tokenizer tokenizer(std_str, sep);
92 for(t_tokenizer::iterator i_t = tokenizer.begin();
93 i_t != tokenizer.end(); ++i_t)
95 tokens.push_back(*i_t);
98 String buffer=a_path.c_str();
100 while(!(token=buffer.parse(
"",
".")).empty())
102 tokens.push_back(token.c_str());
106 if(tokens.size() == 0)
111 m_path.resize(tokens.size()-1);
113 for(
unsigned int i = 0; i < m_path.size(); i++)
115 m_path[i].setup(a_scope, tokens[i].c_str());
117 m_last.setup(a_scope, tokens[tokens.size()-1].c_str());
121 T *ScopedPathAccessor<T>::operator()(
const Record r_in)
123 if(m_last.index() == 0) {
return NULL; }
125 for(
unsigned int i = 0; i < m_path.size(); i++)
127 Record *pRecord = m_path[i].queryAttribute(r_a);
128 if(pRecord && pRecord->isValid())
138 return m_last.queryAttribute(r_a);
143 T *ScopedPathAccessor<T>::operator()(sp<RecordArray>& rspRA, FE_UWORD a_i)
145 Record r_a = rspRA->getRecord(a_i);
150 PathAccessor<T>::PathAccessor(
void)
155 PathAccessor<T>::PathAccessor(
const String &a_path)
156 : VoidAccessor(a_path)
161 PathAccessor<T>::~PathAccessor(
void)
166 T *PathAccessor<T>::operator()(
const Record r_in)
168 if(m_last ==
"") {
return NULL; }
171 for(std::list<String>::iterator i_r = m_path.begin();
172 i_r != m_path.end(); i_r++)
174 sp<Attribute> &attr = r_a.
layout()->scope()->findAttribute(*i_r, i);
179 if(!r_a.layout()->checkAttribute(i))
183 r_a = r_a.accessAttribute<Record>(i);
189 sp<Attribute> &attr = r_a.layout()->scope()->findAttribute(m_last, i);
194 if(!r_a.layout()->checkAttribute(i))
198 return &(r_a.accessAttribute<T>(i));
kernel
Definition: namespace.dox:3
sp< Layout > layout(void) const
Return the Layout.
Definition: RecordSB.h:189