Skip to content

Instantly share code, notes, and snippets.

@wieslawsoltes
Created March 29, 2018 12:48
Show Gist options
  • Save wieslawsoltes/53f2cbe7a69a014c695d39c4ad7b7c1c to your computer and use it in GitHub Desktop.
Save wieslawsoltes/53f2cbe7a69a014c695d39c4ad7b7c1c to your computer and use it in GitHub Desktop.
#include <string>
#include <vector>
#include <utility>
template <typename T>
class IRowEditor
{
public:
virtual ~IRowEditor() { }
virtual std::wstring Get(T& item, int nColumn) = 0;
virtual void Set(T& item, int nColumn, std::wstring& value) = 0;
virtual void Set(T& item, int nColumn, std::wstring&& value) = 0;
};
class CItem
{
public:
int nId;
std::wstring szName;
};
class CItemEditor : public IRowEditor<CItem>
{
public:
std::wstring Get(CItem& item, int nColumn)
{
switch (nColumn)
{
case 0: return std::to_wstring(item.nId);
case 1: return item.szName;
case 2: return L"TEST2";
case 3: return L"TEST3";
case 4: return L"TEST4";
case 5: return L"TEST5";
case 6: return L"TEST6";
case 7: return L"TEST7";
}
return L"??";
}
void Set(CItem& item, int nColumn, std::wstring& value)
{
switch (nColumn)
{
case 0: item.nId = std::stoi(value);
case 1: item.szName = value;
case 2: break;
case 3: break;
case 4: break;
case 5: break;
case 6: break;
case 7: break;
}
}
void Set(CItem& item, int nColumn, std::wstring&& value)
{
Set(item, nColumn, std::move(value));
}
};
template <typename T>
class ItemsList
{
public:
IRowEditor<T>* editor;
std::vector<T>* m_Items;
};
int main()
{
std::vector<CItem> m_Items;
CItem item;
m_Items.emplace_back(item);
CItemEditor editor;
ItemsList<CItem> list;
list.editor = &editor;
editor.Set(m_Items[0], 0, L"10");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment