ome-xml  5.5.1
OMETransformResolver.h
1 /*
2  * #%L
3  * OME-XML C++ library for working with OME-XML metadata structures.
4  * %%
5  * Copyright © 2016 Open Microscopy Environment:
6  * - Massachusetts Institute of Technology
7  * - National Institutes of Health
8  * - University of Dundee
9  * - Board of Regents of the University of Wisconsin-Madison
10  * - Glencoe Software, Inc.
11  * %%
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright notice,
16  * this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * The views and conclusions contained in the software and documentation are
34  * those of the authors and should not be interpreted as representing official
35  * policies, either expressed or implied, of any organization.
36  * #L%
37  */
38 
39 #ifndef OME_XML_MODEL_OMETRANSFORMRESOLVER_H
40 #define OME_XML_MODEL_OMETRANSFORMRESOLVER_H
41 
42 #include <cstdint>
43 #include <memory>
44 #include <ostream>
45 #include <set>
46 #include <string>
47 #include <utility>
48 
49 #include <boost/filesystem.hpp>
50 
51 namespace ome
52 {
53  namespace xml
54  {
55 
56  class OMETransformResolverImpl;
57 
72  {
73  public:
79  struct Schema
80  {
82  Schema():
83  name()
84  {}
85 
91  Schema(const std::string& name):
92  name(name)
93  {}
94 
102  bool
103  operator< (const Schema& rhs) const
104  {
105  return name < rhs.name;
106  }
107 
109  std::string name;
110  };
111 
124  enum Quality
125  {
126  POOR = 1000000LU,
127  FAIR = 10000LU,
128  GOOD = 100LU,
129  EXCELLENT = 1LU
130  };
131 
139  static std::string
141 
149  struct Transform
150  {
152  Transform();
153 
162  Transform(const boost::filesystem::path& file);
163 
170  Transform(const boost::filesystem::path& file,
171  Quality quality);
172 
180  bool
181  operator< (const Transform& rhs) const
182  {
183  return schemas < rhs.schemas;
184  }
185 
187  boost::filesystem::path file;
189  std::pair<std::string, std::string> schemas;
191  uint32_t weight;
192  };
193 
194  public:
202 
209  OMETransformResolver(const boost::filesystem::path& transformdir);
210 
213 
220  std::set<std::string>
221  schema_versions() const;
222 
239  std::pair<std::vector<Transform>, Quality>
240  transform_order(const std::string& source,
241  const std::string& target) const;
242 
250  void
251  write_graphviz(std::ostream& os);
252 
253  private:
255  std::shared_ptr<OMETransformResolverImpl> impl;
256  };
257 
265  template<class charT, class traits>
266  inline std::basic_ostream<charT,traits>&
267  operator<< (std::basic_ostream<charT,traits>& os,
268  const OMETransformResolver::Quality& quality)
269  {
270  return os << OMETransformResolver::quality_name(quality);
271  }
272 
273  }
274 }
275 
276 #endif // OME_XML_MODEL_OMETRANSFORMRESOLVER_H
277 
278 /*
279  * Local Variables:
280  * mode:C++
281  * End:
282  */
Quality
Transformation quality.
Definition: OMETransformResolver.h:124
void write_graphviz(std::ostream &os)
Write a GraphViz dot representation of the internal graph state.
Definition: OMETransformResolver.cpp:417
Moderate data loss.
Definition: OMETransformResolver.h:127
std::set< std::string > schema_versions() const
Get the available schema versions for transformation.
Definition: OMETransformResolver.cpp:303
~OMETransformResolver()
Destructor.
Definition: OMETransformResolver.cpp:298
Metadata for a schema version.
Definition: OMETransformResolver.h:79
OMETransformResolver()
Default constructor.
Definition: OMETransformResolver.cpp:283
Slight data loss.
Definition: OMETransformResolver.h:128
std::string name
Name of the schema.
Definition: OMETransformResolver.h:109
std::pair< std::vector< Transform >, Quality > transform_order(const std::string &source, const std::string &target) const
Determine the optimal transform order between schema versions.
Definition: OMETransformResolver.cpp:317
Open Microscopy Environment C++ implementation.
bool operator<(const Schema &rhs) const
Compare with other Schema.
Definition: OMETransformResolver.h:103
Discover and query available OME-XML transforms.
Definition: OMETransformResolver.h:71
Schema(const std::string &name)
Construct with name.
Definition: OMETransformResolver.h:91
Schema()
Default constructor.
Definition: OMETransformResolver.h:82
uint32_t weight
The quality metric for the transform (less is better).
Definition: OMETransformResolver.h:191
std::pair< std::string, std::string > schemas
The source and target schema versions.
Definition: OMETransformResolver.h:189
Metadata for a schema transform between two schema versions.
Definition: OMETransformResolver.h:149
std::shared_ptr< OMETransformResolverImpl > impl
Private implementation details.
Definition: OMETransformResolver.h:255
boost::filesystem::path file
The XSL transform.
Definition: OMETransformResolver.h:187
Extreme data loss.
Definition: OMETransformResolver.h:126
No data loss.
Definition: OMETransformResolver.h:129
static std::string quality_name(OMETransformResolver::Quality quality)
Get the name associated with a Quality enumeration.
Definition: OMETransformResolver.cpp:160