xref: /glogg/src/viewinterface.h (revision a44d09bc709514bfc9e2b6b4e435e83e8a36868a)
1 /*
2  * Copyright (C) 2013, 2014 Nicolas Bonnefon and other contributors
3  *
4  * This file is part of glogg.
5  *
6  * glogg is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * glogg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with glogg.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef VIEWINTERFACE_H
21 #define VIEWINTERFACE_H
22 
23 #include <memory>
24 
25 class LogData;
26 class LogFilteredData;
27 class SavedSearches;
28 class QuickFindPattern;
29 
30 // ViewContextInterface represents the private information
31 // the concrete view will be able to save and restore.
32 // It can be marshalled to persistent storage.
33 class ViewContextInterface {
34   public:
~ViewContextInterface()35     virtual ~ViewContextInterface() {}
36 
37     virtual std::string toString() const = 0;
38 };
39 
40 // ViewInterface represents a high-level view on a log file.
41 // This a pure virtual class (interface) which is subclassed
42 // for each type of view.
43 class ViewInterface {
44   public:
45     // Set the log data and filtered data to associate to this view
46     // Ownership stay with the caller but is shared
setData(std::shared_ptr<LogData> log_data,std::shared_ptr<LogFilteredData> filtered_data)47     void setData( std::shared_ptr<LogData> log_data,
48             std::shared_ptr<LogFilteredData> filtered_data )
49     { doSetData( log_data, filtered_data ); }
50 
51     // Set the (shared) quickfind pattern object
setQuickFindPattern(std::shared_ptr<QuickFindPattern> qfp)52     void setQuickFindPattern( std::shared_ptr<QuickFindPattern> qfp )
53     { doSetQuickFindPattern( qfp ); }
54 
55     // Set the (shared) search history object
setSavedSearches(std::shared_ptr<SavedSearches> saved_searches)56     void setSavedSearches( std::shared_ptr<SavedSearches> saved_searches )
57     { doSetSavedSearches( saved_searches ); }
58 
59     // For save/restore of the context
setViewContext(const char * view_context)60     void setViewContext( const char* view_context )
61     { doSetViewContext( view_context ); }
62     // (returned object ownership is transferred to the caller)
context(void)63     std::shared_ptr<const ViewContextInterface> context( void ) const
64     { return doGetViewContext(); }
65 
66     // To allow polymorphic destruction
~ViewInterface()67     virtual ~ViewInterface() {}
68 
69   protected:
70     // Virtual functions (using NVI)
71     virtual void doSetData( std::shared_ptr<LogData> log_data,
72             std::shared_ptr<LogFilteredData> filtered_data ) = 0;
73     virtual void doSetQuickFindPattern(
74             std::shared_ptr<QuickFindPattern> qfp ) = 0;
75     virtual void doSetSavedSearches(
76             std::shared_ptr<SavedSearches> saved_searches ) = 0;
77     virtual void doSetViewContext(
78             const char* view_context ) = 0;
79     virtual std::shared_ptr<const ViewContextInterface>
80         doGetViewContext( void ) const = 0;
81 };
82 #endif
83