added get_vector() methods to Finder and Cursor

bool get_vector(std::vector<ModelClass> & result, bool clear_list = true);
  std::vector<ModelClass> get_vector();
This commit is contained in:
Tomasz Sowa 2021-02-23 16:55:28 +01:00
parent c18bb48cc8
commit b672b67e5c
2 changed files with 67 additions and 28 deletions

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2018-2019, Tomasz Sowa
* Copyright (c) 2018-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -246,7 +246,57 @@ public:
}
virtual bool get_list(std::list<ModelClass> & result, bool clear_list = true)
{
return get_list_generic(result, clear_list);
}
virtual std::list<ModelClass> get_list()
{
std::list<ModelClass> result;
get_list(result, false);
return result;
}
virtual bool get_vector(std::vector<ModelClass> & result, bool clear_list = true)
{
if( query_result && query_result->has_db_result() && result.capacity() < query_result->result_rows )
{
result.reserve(query_result->result_rows);
}
return get_list_generic(result, clear_list);
}
virtual std::vector<ModelClass> get_vector()
{
std::vector<ModelClass> result;
get_vector(result, false);
return result;
}
protected:
ModelConnector * model_connector;
ModelData * model_data;
bool has_autogenerated_select;
bool use_table_prefix_for_fetching;
CursorHelper cursor_helper;
FinderHelper finder_helper; // may CursorHelper and FinderHelper should be one class?
QueryResult * query_result;
bool select_status;
template<typename ContainerType>
bool get_list_generic(ContainerType & result, bool clear_list = true)
{
bool res = false;
@ -289,32 +339,6 @@ public:
}
virtual std::list<ModelClass> get_list()
{
std::list<ModelClass> result;
get_list(result, false);
return std::move(result);
}
protected:
ModelConnector * model_connector;
ModelData * model_data;
bool has_autogenerated_select;
bool use_table_prefix_for_fetching;
CursorHelper cursor_helper;
FinderHelper finder_helper; // may CursorHelper and FinderHelper should be one class?
QueryResult * query_result;
bool select_status;
template<typename ContainerType>
bool add_models_to_list(ContainerType & result)
{

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2018-2019, Tomasz Sowa
* Copyright (c) 2018-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -562,6 +562,21 @@ public:
}
bool get_vector(std::vector<ModelClass> & result, bool clear_vector = true)
{
Cursor<ModelClass> cursor = get_cursor();
return cursor.get_vector(result, clear_vector);
}
std::vector<ModelClass> get_vector()
{
std::vector<ModelClass> result;
get_vector(result, false);
return result;
}
protected: