///////////////////////////////////////////////////////////////// // ieVaneer.cpp - demonstrate serialization of STL Containers // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2008 // ///////////////////////////////////////////////////////////////// #include #include #include #include template class iePVaneer { public: iePVaneer() {} iePVaneer(const T& t) : t_(t) {} operator T () { return t_; } std::ostream& operator>>(std::ostream& strm) { strm << typeid(*this).name() << "\n"; strm << t_ << "\n"; return strm; } std::istream& operator<<(std::istream& strm) { // exercise for student return strm; } private: T t_; }; template class ieVaneer : public T { public: ieVaneer(const T& t) : T(t) {} std::ostream& operator>>(std::ostream& strm) { strm << *this; return strm; } std::istream& operator<<(std::istream& strm) { // exercise for student return strm; } }; template class ieCVaneer : public T { public: std::ostream& operator>>(std::ostream& strm) { strm << typeid(T).name() << "\n\n"; strm << typeid(value_type).name() << "\n\n"; T::iterator iter; for(iter=begin(); iter!=end(); ++iter) { (*iter).operator>>(strm); strm << "\n"; } strm << "\n"; return strm; } std::istream& operator<<(std::istream& strm) { // exercise for students return strm; } }; void main() { std::cout << "\n Demonstrate Serialization of STL Types - Vaneer "; std::cout << "\n =================================================\n\n"; iePVaneer iev = 3; std::cout << iev << "\n\n"; iev >> std::cout; std::cout << "\n"; ieCVaneer< std::list< ieVaneer < std::string > > > ievLS1; ievLS1.push_back(std::string("arrdvark")); ievLS1.push_back(std::string("platypus")); ievLS1.push_back(std::string("zebra")); ievLS1 >> std::cout; ieCVaneer< std::list< ieVaneer < std::string > > > ievLS2; ievLS2.push_back(std::string("horse")); ievLS2.push_back(std::string("cow")); ievLS2.push_back(std::string("sheep")); ieCVaneer< std::vector< ieCVaneer< std::list< ieVaneer < std::string > > > > > ievVLS; ievVLS.push_back(ievLS1); ievVLS.push_back(ievLS2); ievVLS >> std::cout; std::cout << "\n\n"; }