Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 23rd, 2005, 04:15 AM
John
Guest
 
Posts: n/a
Default dictionary design, comments?

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.


Thanks,
--j


template <typename K,
typename I,
class _Compare = std::less<K>,
class dic_impl = my_dict<K,I,_Compare> >
class dictionary : public dic_impl {

public:

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 http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
  #2  
Old July 23rd, 2005, 04:16 AM
BigBrian
Guest
 
Posts: n/a
Default Re: dictionary design, comments?

Use the bridge pattern.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

  #3  
Old July 23rd, 2005, 04:16 AM
BigBrian
Guest
 
Posts: n/a
Default Re: dictionary design, comments?

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
polymorphically.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles