From b672b67e5ce09c5a062663d53c7f1206eab6a2a9 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 23 Feb 2021 16:55:28 +0100 Subject: [PATCH] added get_vector() methods to Finder and Cursor bool get_vector(std::vector & result, bool clear_list = true); std::vector get_vector(); --- src/cursor.h | 78 ++++++++++++++++++++++++++++++++++------------------ src/finder.h | 17 +++++++++++- 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/src/cursor.h b/src/cursor.h index ff49c43..47d639c 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -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 & result, bool clear_list = true) + { + return get_list_generic(result, clear_list); + } + + + virtual std::list get_list() + { + std::list result; + + get_list(result, false); + return result; + } + + + virtual bool get_vector(std::vector & 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 get_vector() + { + std::vector 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 + bool get_list_generic(ContainerType & result, bool clear_list = true) { bool res = false; @@ -289,32 +339,6 @@ public: } - virtual std::list get_list() - { - std::list 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 bool add_models_to_list(ContainerType & result) { diff --git a/src/finder.h b/src/finder.h index 90018db..1bc7466 100644 --- a/src/finder.h +++ b/src/finder.h @@ -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 & result, bool clear_vector = true) + { + Cursor cursor = get_cursor(); + return cursor.get_vector(result, clear_vector); + } + + + std::vector get_vector() + { + std::vector result; + + get_vector(result, false); + return result; + } + protected: