1 // ----------------------------------------------------------------------------
2 // record_loader.h
3 //
4 // Copyright (C) 2013
5 //		Remi Chateauneu, F4ECW
6 //
7 // This file is part of fldigi.
8 //
9 // Fldigi is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // Fldigi is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with fldigi.  If not, see <http://www.gnu.org/licenses/>.
21 // ----------------------------------------------------------------------------
22 #ifndef RECORD_LOADER_H
23 #define RECORD_LOADER_H
24 
25 #include <iosfwd>
26 #include <string>
27 
28 class RecordLoaderInterface
29 {
30 	RecordLoaderInterface & operator=( const RecordLoaderInterface & );
31 
32 public:
33 	RecordLoaderInterface();
34 
35 	virtual void Clear() = 0 ;
36 
37 	/// Reads just one record.
38 	virtual bool ReadRecord( std::istream & ) = 0 ;
39 
40 	/// Loads a file and stores it for later lookup. Returns the number of records, or -1.
41 	int LoadAndRegister();
42 
43 	std::string ContentSize() const ;
44 
45 	virtual ~RecordLoaderInterface();
46 
47 	/// Base name. In case the URL is not nice enough to build a clean data filename.
48 	virtual std::string base_filename() const ;
49 
50 	/// The place where we store the data locally.
51 	std::pair< std::string, bool > storage_filename(bool create_dir = false) const ;
52 
Url()53 	virtual const char * Url() const { return NULL; }
54 
55 	virtual const char * Description() const = 0 ;
56 
57 	std::string Timestamp() const;
58 
59 	static void SetDataDir( const std::string & data_dir );
60 }; // RecordLoaderInterface
61 
62 /// Loads records from a file or an Url.
63 template< class Catalog >
64 class RecordLoaderSingleton
65 {
66 	static Catalog s_cata_inst ;
67 public:
InstCatalog()68 	static Catalog & InstCatalog() {
69 		return s_cata_inst ;
70 	}
71 };
72 
73 template<class Catalog> Catalog RecordLoaderSingleton< Catalog >::s_cata_inst = Catalog();
74 
75 /// Loads tabular records from a file.
76 template< class Catalog >
77 struct RecordLoader : public RecordLoaderInterface, public RecordLoaderSingleton<Catalog>
78 {
79 }; // RecordLoader
80 
81 void createRecordLoader();
82 
83 #endif // RECORD_LOADER_H
84