inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/sg/list_item
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_sg_list_item
00005 #define inlib_sg_list_item
00006 
00007 #include "cbk"
00008 
00009 #include <vector>
00010 
00011 namespace inlib {
00012 namespace sg {
00013 
00014 class list_item {
00015 public:
00016   list_item():m_cbk(0){}
00017   list_item(const std::vector<std::string>& a_strings,
00018                    inlib::sg::cbk* a_cbk,
00019                    bool a_dir = false)
00020   :m_strings(a_strings)
00021   ,m_cbk(a_cbk) //take ownership.
00022   ,m_dir(a_dir)
00023   {}
00024   list_item(const std::string& a_label,
00025                    inlib::sg::cbk* a_cbk,
00026                    bool a_dir = false)
00027   :m_cbk(a_cbk) //take ownership.
00028   ,m_dir(a_dir)
00029   {
00030     m_strings.push_back(a_label);
00031   }
00032   virtual ~list_item() {delete m_cbk;}
00033 public:
00034   list_item(const list_item& a_from)
00035   :m_strings(a_from.m_strings)
00036   ,m_cbk(a_from.m_cbk?a_from.m_cbk->copy():0)
00037   ,m_dir(a_from.m_dir)
00038   {}
00039   list_item& operator=(const list_item& a_from){
00040     m_strings = a_from.m_strings;
00041     delete m_cbk;
00042     m_cbk = a_from.m_cbk?a_from.m_cbk->copy():0;
00043     m_dir = a_from.m_dir;
00044     return *this;
00045   }
00046 public:
00047   bool operator==(const list_item& a_v) const {
00048     if(m_strings!=a_v.m_strings) return false;
00049     if(m_dir!=a_v.m_dir) return false;
00050     if(m_cbk) {
00051       if(a_v.m_cbk) {
00052         //return m_cbk->equal(*(a_v.m_cbk)); //do we want that ?
00053         return false;
00054       } else {
00055         return false;
00056       }
00057     } else {
00058       if(a_v.m_cbk) {
00059         return false;
00060       } else {
00061         return true;
00062       }
00063     }
00064   }
00065   bool operator!=(const list_item& a_v) const {return !operator==(a_v);}
00066 public:
00067   const std::vector<std::string>& strings() const {return m_strings;}
00068   inlib::sg::cbk* cbk() const {return m_cbk;}
00069   bool is_dir() const {return m_dir;}
00070 private:
00071   std::vector<std::string> m_strings;
00072   inlib::sg::cbk* m_cbk;
00073   bool m_dir;
00074 };
00075 
00076 }}
00077 
00078 #endif
00079 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines