By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,897 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,897 IT Pros & Developers. It's quick & easy.

dictionary design, comments?

P: n/a
I am trying to design a dictionary in such a way that I can
keep the interface and implementation separate. Here is my
initial design. Anyone has any comments on it or suggestions
on how I could make it better.

Does anyone have a good code/pointer that discusses
dictionary design.
template <typename K,
typename I,
class _Compare = std::less<K>,
class dic_impl = my_dict<K,I,_Compare> >
class dictionary : public dic_impl {


typedef typename dic_impl::dic_item dic_item;
typedef typename dic_impl::const_dic_item const_dic_item;

typedef K key_type;
typedef I inf_type;
dictionary(){ };

virtual ~dictionary(){dic_impl::clear();}

const K& key(const_dic_item it) const { return dic_impl::key(it);}
const I& inf(const_dic_item it) const { return dic_impl::inf(it);}
int defined(const K& k) const
{ return (lookup(k) == dic_impl::end()) ? false : true; }

inline dic_item insert(const K& k, const I& i)
{ return dic_impl::insert(k,i); }

inline const_dic_item lookup(const K& k) const
{ return dic_impl::lookup(k); }

inline dic_item lookup(const K& k)
{ return dic_impl::lookup(k); }

inline void del(const K& k) { dic_impl::del(k); }

inline void del_item(dic_item it) { dic_impl::del_item(it); }

void change_inf(dic_item it, const I& i)
{ dic_impl::change_inf(it,i); }

inline void clear() { dic_impl::clear(); }

inline int size() const { return dic_impl::size(); }

inline bool empty() const { return (size()==0) ? true : false; }

inline const_dic_item begin() const { return dic_impl::begin(); }
inline const_dic_item end() const { return dic_impl::end(); }

inline dic_item begin() { return dic_impl::begin(); }
inline dic_item end() { return dic_impl::end(); }

inline const_dic_item succ_item(const_dic_item it) const
{ return dic_impl::succ_item(it);}
inline const_dic_item pred_item(const_dic_item it) const
{ return dic_impl::pred_item(it);}

inline dic_item succ_item(dic_item it)
{ return dic_impl::succ_item(it);}
inline dic_item pred_item(dic_item it)
{ return dic_impl::pred_item(it);}
typedef dictionary<K,I,_Compare,dic_impl> this_type;
}; // end of dictionary
[ See for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Use the bridge pattern.
[ See for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #2

P: n/a
I would use a bridge. You're defining the interface class to be a
subclass of the implementation. Make dic_impl and abstract class and
have your dictionary class aggregate it instead of deriving from it.
You can then derive concrete implementations from the abstract
dic_impl, and the interface can access the implementation
[ See for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.