Bezig met crudmodel/tab
This commit is contained in:
parent
ee321b3fb1
commit
14ab400ccb
15 changed files with 308 additions and 33 deletions
|
|
@ -101,4 +101,89 @@ private:
|
|||
|
||||
};
|
||||
|
||||
|
||||
template<typename T, typename K=Oid>
|
||||
class PgSPtrContainer: public IPgContainter {
|
||||
public:
|
||||
using t_Elem = std::shared_ptr<T>;
|
||||
using t_Container = std::vector<t_Elem>; ///< Do not assume it will stay a vector only expect bidirectional access
|
||||
|
||||
explicit PgSPtrContainer(std::weak_ptr<PgDatabaseCatalog> cat)
|
||||
: m_catalogue(cat)
|
||||
{}
|
||||
|
||||
|
||||
typename t_Container::const_iterator begin() const
|
||||
{
|
||||
return m_container.begin();
|
||||
}
|
||||
|
||||
typename t_Container::const_iterator end() const
|
||||
{
|
||||
return m_container.end();
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_container.clear();
|
||||
}
|
||||
|
||||
int count() const
|
||||
{
|
||||
return (int)m_container.size();
|
||||
}
|
||||
|
||||
const t_Elem getByKey(const K &key) const
|
||||
{
|
||||
auto lb_result = std::lower_bound(m_container.begin(), m_container.end(), key);
|
||||
if (lb_result != m_container.end() && **lb_result == key)
|
||||
return *lb_result;
|
||||
|
||||
return m_invalidInstance;
|
||||
}
|
||||
|
||||
const t_Elem getByName(const QString name) const
|
||||
{
|
||||
auto find_res = std::find_if(m_container.begin(), m_container.end(),
|
||||
[name](auto e) -> bool { return *e = name; } );
|
||||
|
||||
if (find_res != m_container.end())
|
||||
return *find_res;
|
||||
|
||||
return m_invalidInstance;
|
||||
}
|
||||
|
||||
const t_Elem getByIdx(int idx) const
|
||||
{
|
||||
return m_container.at(idx);
|
||||
}
|
||||
|
||||
/** Override to implement complete loading logic.
|
||||
*
|
||||
* Do not override this function if you only want to implement
|
||||
* the loading of a single element. Override loadElem instead.
|
||||
*/
|
||||
virtual void load(const Pgsql::Result &res) override
|
||||
{
|
||||
m_container.clear();
|
||||
m_container.reserve(res.rows());
|
||||
for (auto row : res)
|
||||
m_container.push_back(loadElem(row));
|
||||
|
||||
std::sort(m_container.begin(), m_container.end());
|
||||
}
|
||||
protected:
|
||||
std::weak_ptr<PgDatabaseCatalog> m_catalogue;
|
||||
t_Container m_container;
|
||||
|
||||
/** Override the implementation for this function to implement loading of single row.
|
||||
*
|
||||
* When overriding this function there is no need to override load.
|
||||
*/
|
||||
virtual t_Elem loadElem(const Pgsql::Row &) = 0;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // PGCONTAINER_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue