Listing 2: Support for lists of strings
//LbweRep.h
//A class that allows conversions from std::list<CString>
//to std::vector<CString> and back. Class used internally
//by ListBoxWithExtras to represent the list of strings.
#ifndef LBWEREP_H
#define LBWEREP_H
#include <new.h>
#include <fstream.h>
namespace std {
#include <vector.h>
#include <list.h>
#include <deque.h>
}
class LbweRep : public std::vector<CString>
{
public:
LbweRep();
~LbweRep();
LbweRep& operator=(const std::list<CString>&);
LbweRep& operator=(const std::vector<CString>&);
LbweRep& operator=(const CStringList&);
void MakeList(std::list<CString>&);
void MakeVector(std::vector<CString>& v) {v = *this;};
void MakeCStringList(CStringList&);
};
#endif
//lbwe.cpp
#include "stdafx.h"
#include "LbweRep.h"
//Construction and Destruction
LbweRep::LbweRep() {}
LbweRep::~LbweRep() {}
//The only purpose for LbweRep is to make using an LBWE
//easier. The box will populate itself from an embedded public
//LbweRep object. The box information is also available from
//the LbweRep at any time. So this is a handy way to to get
//data from either a modal or modeless LBWE.
LbweRep& LbweRep::operator=(const std::vector<CString>& v)
//Convert an std::vector<CString> into an LbweRep
{
erase(begin(), end());
for (unsigned i = 0; i < v.size(); i++)
push_back(v[i]);
return *this;
}
LbweRep& LbweRep::operator=(const std::list<CString>& l)
// Convert an std::list<CString> into an LbweRep
{
erase(begin(), end());
std::list<CString>::const_iterator i;
for (i = l.begin(); i != l.end(); i++)
push_back(*i);
return *this;
}
LbweRep& LbweRep::operator=(const CStringList& l)
// Convert CStringList to an LbweRep
{
erase(begin(), end());
POSITION pos = l.GetHeadPosition();
while (pos)
{
push_back(l.GetNext(pos));
}
return *this;
}
void LbweRep::MakeCStringList(CStringList& l)
//make CStringList from LbweRep
{
l.RemoveAll();
LbweRep::iterator i;
for (i = begin(); i != end(); i++)
l.AddTail(*i);
}
void LbweRep::MakeList(std::list<CString>& l)
//makes list from LbweRep
{
LbweRep::iterator i;
l.erase(l.begin(), l.end());
for (i = begin(); i != end(); i++)
l.push_back(*i);
}
//End of File