|
Boost Users : |
Subject: Re: [Boost-users] Using different variables based on template type
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-06-02 22:28:10
Zachary Turner wrote:
> Regarding your other question, I'm not totally sure I understand,
> could you post a short code snippet?
class Serialization {
private:
struct DataStructure {
std::map<std::string, uint16> m_Uint16Map;
std::map<std::string, uint32> m_Uint32Map;
void remove (std::string const& variableName) {
m_Uint16Map.erase(variableName);
m_Uint32Map.erase(variableName);
}
};
typedef boost::shared_ptr<DataStructure> boostData;
std::map<std::string, boostData> m_DataMap;
boostData
m_CurrentStructure;
public:
Serialization(void) {
m_CurrentStructure = boostData(new DataStructure);
m_DataMap[""] = m_CurrentStructure;
}
void putUint16(std::string const& variableName, uint16 variable) {
m_CurrentStructure.remove(variableName);
m_CurrentStructure->m_Uint16Map[variableName] = variable;
}
void putUint32(std::string const& variableName, uint32 variable) {
m_CurrentStructure.remove(variableName);
m_CurrentStructure->m_Uint32Map[variableName] = variable;
}
};
> You can do them in the form of template specializations for the type
> of data to store/retrieve
If I use template specialization I would be creating a function for
every type. This doesn't seem any better than creating a function for
each type I want. Why would I want to do this?
Ryan
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net