ome-xml  5.6.0
OMEModelObject.h
1 /*
2  * #%L
3  * OME-XML C++ library for working with OME-XML metadata structures.
4  * %%
5  * Copyright © 2006 - 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_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:
72  OMEModelObject (const std::string& objectType = "OMEModelObject");
73 
74  public:
76  virtual
77  ~OMEModelObject ();
78 
79  protected:
85  OMEModelObject (const OMEModelObject& copy);
86 
87  public:
89  bool
90  validElementName(const std::string& name) const = 0;
91 
94  asXMLElement (common::xml::dom::Document& document) const;
95 
96  // @copydoc doesn't work here due to doxygen issues with
97  // overloading and parameter namespaces, so duplicate
98  // entirely.
108  virtual void
110  common::xml::dom::Element& element) const;
111  protected:
124  virtual void
126  common::xml::dom::Element& element) const = 0;
127 
128  public:
130  virtual void
131  update (const common::xml::dom::Element& element,
132  ::ome::xml::model::OMEModel& model);
133 
135  virtual bool
136  link (std::shared_ptr<Reference>& reference,
137  std::shared_ptr<::ome::xml::model::OMEModelObject>& object);
138 
148  static std::vector<common::xml::dom::Element>
150  const std::string& name);
151 
159  static std::string
160  stripNamespacePrefix (const std::string& value);
161 
162  protected:
172  template<typename T>
174  {
175  private:
177  const std::shared_ptr<const T>& cmp;
178 
179  public:
185  compare_element(const std::shared_ptr<const T>& cmp):
186  cmp(cmp)
187  {}
188 
196  bool
197  operator () (const std::shared_ptr<T>& element)
198  {
199  return cmp && element && cmp == element;
200  }
201 
208  bool
209  operator () (const std::shared_ptr<const T>& element)
210  {
211  return cmp && element && cmp == element;
212  }
213 
220  bool
221  operator () (const std::weak_ptr<T>& element)
222  {
223  std::shared_ptr<const T> shared_element(element);
224  return cmp && shared_element && cmp == shared_element;
225  }
226 
233  bool
234  operator () (const std::weak_ptr<const T>& element)
235  {
236  std::shared_ptr<const T> shared_element(element);
237  return cmp && shared_element && cmp == shared_element;
238  }
239  };
240 
251  template<class C, typename T>
252  bool
253  contains(const C& container,
254  const std::shared_ptr<T>& element)
255  {
256  return (std::find_if(container.begin(),
257  container.end(),
258  compare_element<T>(element)) != container.end());
259  }
260 
263  };
264 
265  }
266  }
267  }
268 }
269 
270 #endif // OME_XML_MODEL_DETAIL_OMEMODELOBJECT_H
271 
272 /*
273  * Local Variables:
274  * mode:C++
275  * End:
276  */
OME model interface (abstract top-level container)
Definition: OMEModel.h:61
logging::sources::severity_logger_mt< logging::trivial::severity_level > Logger
ome::common::Logger logger
Message logger.
Definition: OMEModelObject.h:262
compare_element(const std::shared_ptr< const T > &cmp)
Constructor.
Definition: OMEModelObject.h:185
OMEModelObject()
Constructor.
Definition: OMEModelObject.h:97
OME model object (concrete implementation).
Definition: OMEModelObject.h:64
OME model object interface.
Definition: OMEModelObject.h:76
static std::string stripNamespacePrefix(const std::string &value)
Strip the namespace prefix from a tag name.
Definition: OMEModelObject.cpp:148
virtual void 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:95
Open Microscopy Environment C++ implementation.
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:101
virtual bool link(std::shared_ptr< Reference > &reference, std::shared_ptr<::ome::xml::model::OMEModelObject > &object)
Link a given OME model object to this model object.
Definition: OMEModelObject.cpp:107
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:70
Comparison functor.
Definition: OMEModelObject.h:173
const std::shared_ptr< const T > & cmp
The element to compare other elements with.
Definition: OMEModelObject.h:177
bool operator()(const std::shared_ptr< T > &element)
Compare element with another element.
Definition: OMEModelObject.h:197
virtual common::xml::dom::Element asXMLElement(common::xml::dom::Document &document) const
Transform the object hierarchy rooted at this element to XML.
Definition: OMEModelObject.cpp:76
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:114
virtual ~OMEModelObject()
Destructor.
Definition: OMEModelObject.cpp:58
bool contains(const C &container, const std::shared_ptr< T > &element)
Check if a container contains a particular element.
Definition: OMEModelObject.h:253