bioformats  5.1.6
OMEModelObject.h
1 /*
2  * #%L
3  * OME-XML C++ library for working with OME-XML metadata structures.
4  * %%
5  * Copyright © 2006 - 2015 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_DETAIL_OMEMODELOBJECT_H
40 #define OME_XML_MODEL_DETAIL_OMEMODELOBJECT_H
41 
42 #include <ome/common/log.h>
43 
44 #include <ome/xml/model/OMEModelObject.h>
45 
46 namespace ome
47 {
48  namespace xml
49  {
50  namespace model
51  {
58  namespace detail
59  {
60 
65  {
66  protected:
68  OMEModelObject (const std::string& objectType = "OMEModelObject");
69 
70  public:
72  virtual
73  ~OMEModelObject ();
74 
75  protected:
81  OMEModelObject (const OMEModelObject& copy);
82 
83  public:
85  bool
86  validElementName(const std::string& name) const = 0;
87 
88  protected:
101  common::xml::dom::Element& element) const = 0;
102 
103  public:
105  virtual void
106  update (const common::xml::dom::Element& element,
107  ::ome::xml::model::OMEModel& model);
108 
110  virtual bool
111  link (ome::compat::shared_ptr<Reference>& reference,
112  ome::compat::shared_ptr< ::ome::xml::model::OMEModelObject>& object);
113 
123  static std::vector<common::xml::dom::Element>
125  const std::string& name);
126 
134  static std::string
135  stripNamespacePrefix (const std::string& value);
136 
137  protected:
147  template<typename T>
149  {
150  private:
152  const ome::compat::shared_ptr<const T>& cmp;
153 
154  public:
160  compare_element(const ome::compat::shared_ptr<const T>& cmp):
161  cmp(cmp)
162  {}
163 
171  bool
172  operator () (const ome::compat::shared_ptr<T>& element)
173  {
174  return cmp && element && cmp == element;
175  }
176 
183  bool
184  operator () (const ome::compat::shared_ptr<const T>& element)
185  {
186  return cmp && element && cmp == element;
187  }
188 
195  bool
196  operator () (const ome::compat::weak_ptr<T>& element)
197  {
198  ome::compat::shared_ptr<const T> shared_element(element);
199  return cmp && shared_element && cmp == shared_element;
200  }
201 
208  bool
209  operator () (const ome::compat::weak_ptr<const T>& element)
210  {
211  ome::compat::shared_ptr<const T> shared_element(element);
212  return cmp && shared_element && cmp == shared_element;
213  }
214  };
215 
226  template<class C, typename T>
227  bool
228  contains(const C& container,
229  const ome::compat::shared_ptr<T>& element)
230  {
231  return (std::find_if(container.begin(),
232  container.end(),
233  compare_element<T>(element)) != container.end());
234  }
235 
238  };
239 
240  }
241  }
242  }
243 }
244 
245 #endif // OME_XML_MODEL_DETAIL_OMEMODELOBJECT_H
246 
247 /*
248  * Local Variables:
249  * mode:C++
250  * End:
251  */
OME model interface (abstract top-level container)
Definition: OMEModel.h:62
logging::sources::severity_logger_mt< logging::trivial::severity_level > Logger
Message logger.
Definition: log.h:98
ome::common::Logger logger
Message logger.
Definition: OMEModelObject.h:237
virtual bool link(ome::compat::shared_ptr< Reference > &reference, ome::compat::shared_ptr< ::ome::xml::model::OMEModelObject > &object)
Link a given OME model object to this model object.
Definition: OMEModelObject.cpp:90
bool validElementName(const std::string &name) const =0
Check if a given element name is valid for processing by this model object.
Definition: OMEModelObject.cpp:71
bool contains(const C &container, const ome::compat::shared_ptr< T > &element)
Check if a container contains a particular element.
Definition: OMEModelObject.h:228
OMEModelObject()
Constructor.
Definition: OMEModelObject.h:98
DOM Document wrapper.
Definition: Document.h:83
DOM Element wrapper.
Definition: Element.h:66
OME model object (concrete implementation).
Definition: OMEModelObject.h:64
OME model object interface.
Definition: OMEModelObject.h:77
static std::string stripNamespacePrefix(const std::string &value)
Strip the namespace prefix from a tag name.
Definition: OMEModelObject.cpp:126
virtual common::xml::dom::Element asXMLElementInternal(common::xml::dom::Document &document, common::xml::dom::Element &element) const =0
Transform the object hierarchy rooted at this element to XML.
Definition: OMEModelObject.cpp:77
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
const ome::compat::shared_ptr< const T > & cmp
The element to compare other elements with.
Definition: OMEModelObject.h:152
Comparison functor.
Definition: OMEModelObject.h:148
compare_element(const ome::compat::shared_ptr< const T > &cmp)
Constructor.
Definition: OMEModelObject.h:160
bool operator()(const ome::compat::shared_ptr< T > &element)
Compare element with another element.
Definition: OMEModelObject.h:172
Boost.Log compatibility.
virtual void update(const common::xml::dom::Element &element,::ome::xml::model::OMEModel &model)
Update the object hierarchy recursively from an XML DOM tree.
Definition: OMEModelObject.cpp:84
static std::vector< common::xml::dom::Element > getChildrenByTagName(const common::xml::dom::Element &parent, const std::string &name)
Retrieve all the children of an element that have a given tag name.
Definition: OMEModelObject.cpp:97
virtual ~OMEModelObject()
Destructor.
Definition: OMEModelObject.cpp:59
Xerces-C modern C++ wrapper.
Definition: Base.h:53