text_format_factory.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <vector>
11 #include "interop/util/map.h"
12 #include "interop/util/assert.h"
17 
23 #define INTEROP_REGISTER_METRIC_TEXT_LAYOUT(Metric, Version) \
24  illumina::interop::io::text_format_factory_proxy< Metric > \
25  illumina_interop_io_text_##Type##Metric##Version(new illumina::interop::io::text_format<Metric, illumina::interop::io::text_layout<Metric, Version> >);
26 
27 
28 namespace illumina { namespace interop { namespace io
29 {
37  template<class Metric>
39  {
41  typedef Metric metric_type;
45  typedef typename Metric::header_type header_type;
49  typedef INTEROP_UNORDERED_MAP(int, metric_format_pointer) text_format_map;
50 
58  abstract_text_format_t* find(int version)
59  {
60  if(version < 0) version = m_latest_version;
61  typename text_format_map::iterator it = m_format_map.find(version);
62  if(it == m_format_map.end()) return 0;
63  return &(*it->second);
64  }
65 
70  void add(abstract_text_format_t *pformat)
71  {
72  const int version = pformat->version();
73  if(version > m_latest_version) m_latest_version = version;
74  m_format_map[version] = metric_format_pointer(pformat);
75  }
80  size_t size()const
81  {
82  return m_format_map.size();
83  }
84 
91  {
92  INTEROP_FORCE_LINK_USE(metric_type);
93  static text_format_factory<Metric> _inst;
94  return _inst;
95  }
96 
97  private:
98  text_format_factory() : m_latest_version(-1) {}
99  text_format_map m_format_map;
100  int m_latest_version;
101 
102  };
105  template<class Metric>
107  {
109  typedef Metric metric_type;
116  text_format_factory_proxy(abstract_text_format_t *pformat)
117  {
119  }
120  };
121 
122 }}}
123 
124 
125 
Metric metric_type
Definition: text_format_factory.h:109
static text_format_factory< Metric > & instance()
Definition: text_format_factory.h:90
Definition: enum_description.h:15
Definition: text_format_factory.h:38
abstract_text_format< metric_type > abstract_text_format_t
Definition: text_format_factory.h:43
abstract_text_format< metric_type > abstract_text_format_t
Definition: text_format_factory.h:111
#define INTEROP_FORCE_LINK_USE(X)
Definition: self_registration.h:15
Metric metric_type
Definition: text_format_factory.h:41
Metric::header_type header_type
Definition: text_format_factory.h:45
typedef INTEROP_UNORDERED_MAP(int, metric_format_pointer) text_format_map
void add(abstract_text_format_t *pformat)
Definition: text_format_factory.h:70
abstract_text_format_t * find(int version)
Definition: text_format_factory.h:58
std::unique_ptr< T > unique_ptr
Definition: unique_ptr.h:96
virtual ::int16_t version() const =0
stdbp::unique_ptr< abstract_text_format_t > metric_format_pointer
Definition: text_format_factory.h:47
size_t size() const
Definition: text_format_factory.h:80
text_format_factory_proxy(abstract_text_format_t *pformat)
Definition: text_format_factory.h:116
Definition: abstract_text_format.h:22
Definition: text_format_factory.h:106