Agent.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2002 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Base/Classes/Pulsar/Agent.h
10 
11 #ifndef __Pulsar_Agent_h
12 #define __Pulsar_Agent_h
13 
14 #include "Pulsar/Archive.h"
15 #include "Registry.h"
16 
17 #include <vector>
18 
19 
20 namespace Pulsar {
21 
22  /* This abstract base class should be inherited through the
23  Advocate template. */
24  class Archive::Agent : public Reference::Able {
25 
26  public:
27 
28  // Destructor
29  virtual ~Agent ();
30 
31  // Advocate the use of the derived class to interpret filename
32  virtual bool advocate (const char* filename) = 0;
33 
34  // Return the name of the derived class
35  virtual std::string get_name () = 0;
36 
37  // Return a description of the derived class
38  virtual std::string get_description () = 0;
39 
40  // Return a null-constructed instance of the derived class
41  virtual Archive* new_Archive () = 0;
42 
43  // Return the name of the plugins directory
44  static std::string get_plugin_path (const char* shell_variable);
45 
46  // Report to cerr on the status of the Registry (and plugins)
47  static void report ();
48 
49  // Return a string containing the list of plugins formatted for output
50  static std::string get_list ();
51 
52  // Get a list of name,description pairs from the registry
53  static void get_list( std::vector<std::pair<std::string,std::string> >& );
54 
55  protected:
56 
57  // The path from which plugin code will be loaded
58  static std::string plugin_path;
59 
60  // Flag that plugin_load has been called
61  static bool loaded;
62 
63  // Initialization function calls plugin_load if dynamic linkage enabled
64  static bool init ();
65 
66  };
67 
68  /* This template base class must be inherited in order to register
69  plugins for use in the Archive::load factory. */
70  template<class Plugin>
71  class Archive::Advocate : public Agent {
72 
73  public:
74 
75  // Constructor ensures that template entry is instantiated
76  Advocate () { entry.get(); }
77 
78  // Return a new instance of the Archive derived class
79  Archive* new_Archive () { return new Plugin; }
80 
81  // ensure that the Advocate is linked into static binaries
82  static void ensure_linkage () { entry.get(); }
83 
84  private:
85 
86  // Enter template constructor adds Advocate<Plugin> to Agent::registry
87  static Registry::List<Archive::Agent>::Enter<typename Plugin::Agent> entry;
88 
89  };
90 
91 #ifdef PSRCHIVE_PLUGIN
92  template<class Plugin>
93  Registry::List<Archive::Agent>::Enter<typename Plugin::Agent>
94  Archive::Advocate<Plugin>::entry;
95 #endif
96 
97 }
98 
99 #endif
Archive()
Default constructor.
Definition: Archive.C:67
const ExtensionType * get() const
Template method searches for an Extension of the specified type.
static Archive * new_Archive(const std::string &class_name)
Factory returns a null-constructed instance of the named class.
Definition: Archive.C:104
static List & get_registry()
unsigned size() const
Defines the PSRCHIVE library.
Definition: CalSource.h:17

Generated using doxygen 1.8.17