casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CacheFactory.h
Go to the documentation of this file.
1 //# CacheFactory.h: Factory to return a cache of the proper type
2 //# Copyright (C) 2013
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef CACHE_FACTORY_
28 #define CACHE_FACTORY_
29 
30 #include <casa/BasicSL/String.h>
31 #include <tables/Tables/Table.h>
32 #include <plotms/PlotMS/PlotMS.h>
33 #include <plotms/Data/CalCache.h>
34 #include <plotms/Data/MSCache.h>
36 
37 namespace casa {
38 
39 class CacheFactory {
40 public:
41  static PlotMSCacheBase* getCache(const casacore::String &filename,
42  PlotMSApp *parent) {
43  if(casacore::Table::isReadable(filename)) {
44  casacore::Table tab(filename);
45  // Construct proper empty cache if necessary
46  if(tab.tableInfo().type() == "Calibration")
47  return new CalCache(parent);
48  else
49  return new MSCache(parent);
50  }
51  return NULL;
52  }
53 
54  static bool needNewCache(const PlotMSCacheBase *cache,
55  const casacore::String &filename) {
56  casacore::Table tab(filename);
57  if(!cache) return true;
58  if((cache->cacheType() == PlotMSCacheBase::CAL &&
59  tab.tableInfo().type() != "Calibration") ||
60  (cache->cacheType() == PlotMSCacheBase::MS &&
61  tab.tableInfo().type() == "Calibration")) {
62  return true;
63  }
64  return false;
65  }
66 };
67 
68 } // namespace casa
69 
70 #endif//CACHE_FACTORY_
Main interface class to a read/write table.
Definition: Table.h:153
Controller class for plotms.
Definition: PlotMS.h:55
const String & type() const
Get the table (sub)type.
Definition: TableInfo.h:229
static TableInfo tableInfo(const String &tableName)
Get the table info of the table with the given name.
Definition: Table.h:1210
static bool needNewCache(const PlotMSCacheBase *cache, const casacore::String &filename)
Definition: CacheFactory.h:54
virtual PlotMSCacheBase::Type cacheType() const =0
Identify myself (MS or CAL)
static PlotMSCacheBase * getCache(const casacore::String &filename, PlotMSApp *parent)
Definition: CacheFactory.h:41
String: the storage and methods of handling collections of characters.
Definition: String.h:223
static Bool isReadable(const String &tableName, bool throwIf=False)
Test if a table with the given name exists and is readable.