ome-xml  5.2.4
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 <ostream>
43 #include <set>
44 #include <string>
45 #include <utility>
46 
47 #include <boost/filesystem.hpp>
48 
49 #include <ome/compat/cstdint.h>
50 #include <ome/compat/memory.h>
51 
52 namespace ome
53 {
54  namespace xml
55  {
56 
57  class OMETransformResolverImpl;
58 
73  {
74  public:
80  struct Schema
81  {
83  Schema():
84  name()
85  {}
86 
92  Schema(const std::string& name):
93  name(name)
94  {}
95 
103  bool
104  operator< (const Schema& rhs) const
105  {
106  return name < rhs.name;
107  }
108 
110  std::string name;
111  };
112 
125  enum Quality
126  {
127  POOR = 1000000LU,
128  FAIR = 10000LU,
129  GOOD = 100LU,
130  EXCELLENT = 1LU
131  };
132 
140  static std::string
142 
150  struct Transform
151  {
153  Transform();
154 
163  Transform(const boost::filesystem::path& file);
164 
171  Transform(const boost::filesystem::path& file,
172  Quality quality);
173 
181  bool
182  operator< (const Transform& rhs) const
183  {
184  return schemas < rhs.schemas;
185  }
186 
188  boost::filesystem::path file;
190  std::pair<std::string, std::string> schemas;
192  uint32_t weight;
193  };
194 
195  public:
203 
210  OMETransformResolver(const boost::filesystem::path& transformdir);
211 
214 
221  std::set<std::string>
222  schema_versions() const;
223 
240  std::pair<std::vector<Transform>, Quality>
241  transform_order(const std::string& source,
242  const std::string& target) const;
243 
251  void
252  write_graphviz(std::ostream& os);
253 
254  private:
256  ome::compat::shared_ptr<OMETransformResolverImpl> impl;
257  };
258 
266  template<class charT, class traits>
267  inline std::basic_ostream<charT,traits>&
268  operator<< (std::basic_ostream<charT,traits>& os,
269  const OMETransformResolver::Quality& quality)
270  {
271  return os << OMETransformResolver::quality_name(quality);
272  }
273 
274  }
275 }
276 
277 #endif // OME_XML_MODEL_OMETRANSFORMRESOLVER_H
278 
279 /*
280  * Local Variables:
281  * mode:C++
282  * End:
283  */
ome::compat::shared_ptr< OMETransformResolverImpl > impl
Private implementation details.
Definition: OMETransformResolver.h:256
Quality
Transformation quality.
Definition: OMETransformResolver.h:125
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:128
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:80
OMETransformResolver()
Default constructor.
Definition: OMETransformResolver.cpp:283
Slight data loss.
Definition: OMETransformResolver.h:129
std::string name
Name of the schema.
Definition: OMETransformResolver.h:110
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:104
Discover and query available OME-XML transforms.
Definition: OMETransformResolver.h:72
Schema(const std::string &name)
Construct with name.
Definition: OMETransformResolver.h:92
Schema()
Default constructor.
Definition: OMETransformResolver.h:83
uint32_t weight
The quality metric for the transform (less is better).
Definition: OMETransformResolver.h:192
std::pair< std::string, std::string > schemas
The source and target schema versions.
Definition: OMETransformResolver.h:190
Metadata for a schema transform between two schema versions.
Definition: OMETransformResolver.h:150
boost::filesystem::path file
The XSL transform.
Definition: OMETransformResolver.h:188
Extreme data loss.
Definition: OMETransformResolver.h:127
No data loss.
Definition: OMETransformResolver.h:130
static std::string quality_name(OMETransformResolver::Quality quality)
Get the name associated with a Quality enumeration.
Definition: OMETransformResolver.cpp:160