Restructured locations of source.
This commit is contained in:
parent
78a4c6d730
commit
7c4e8e95e8
151 changed files with 1 additions and 0 deletions
70
src/pglab/PgContainer.h
Normal file
70
src/pglab/PgContainer.h
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#ifndef PGCONTAINER_H
|
||||
#define PGCONTAINER_H
|
||||
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
#include <libpq-fe.h>
|
||||
|
||||
class PgDatabaseCatalogue;
|
||||
|
||||
template<typename T>
|
||||
class PgContainer {
|
||||
public:
|
||||
using t_Container = std::vector<T>; ///< Do not assume it will stay a vector only expect bidirectional access
|
||||
|
||||
explicit PgContainer(PgDatabaseCatalogue *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& getByOid(Oid oid) const
|
||||
{
|
||||
auto lb_result = std::lower_bound(m_container.begin(), m_container.end(), oid);
|
||||
if (lb_result != m_container.end() && lb_result->oid == oid)
|
||||
return *lb_result;
|
||||
|
||||
return m_invalidInstance;
|
||||
}
|
||||
|
||||
const T& getByName(const QString &name) const
|
||||
{
|
||||
auto find_res = std::find(m_container.begin(), m_container.end(), name);
|
||||
|
||||
if (find_res != m_container.end())
|
||||
return *find_res;
|
||||
|
||||
return m_invalidInstance;
|
||||
}
|
||||
|
||||
const T& getByIdx(int idx) const
|
||||
{
|
||||
return m_container.at(idx);
|
||||
}
|
||||
protected:
|
||||
PgDatabaseCatalogue *m_catalogue;
|
||||
t_Container m_container;
|
||||
private:
|
||||
T m_invalidInstance;
|
||||
|
||||
};
|
||||
|
||||
#endif // PGCONTAINER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue