ome-xml  5.5.1
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:
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 
90  asXMLElement (common::xml::dom::Document& document) const;
91 
93  virtual void
95  common::xml::dom::Element& element) const;
96  protected:
109  virtual void
111  common::xml::dom::Element& element) const = 0;
112 
113  public:
115  virtual void
116  update (const common::xml::dom::Element& element,
117  ::ome::xml::model::OMEModel& model);
118 
120  virtual bool
121  link (std::shared_ptr<Reference>& reference,
122  std::shared_ptr<::ome::xml::model::OMEModelObject>& object);
123 
133  static std::vector<common::xml::dom::Element>
135  const std::string& name);
136 
144  static std::string
145  stripNamespacePrefix (const std::string& value);
146 
147  protected:
157  template<typename T>
159  {
160  private:
162  const std::shared_ptr<const T>& cmp;
163 
164  public:
170  compare_element(const std::shared_ptr<const T>& cmp):
171  cmp(cmp)
172  {}
173 
181  bool
182  operator () (const std::shared_ptr<T>& element)
183  {
184  return cmp && element && cmp == element;
185  }
186 
193  bool
194  operator () (const std::shared_ptr<const T>& element)
195  {
196  return cmp && element && cmp == element;
197  }
198 
205  bool
206  operator () (const std::weak_ptr<T>& element)
207  {
208  std::shared_ptr<const T> shared_element(element);
209  return cmp && shared_element && cmp == shared_element;
210  }
211 
218  bool
219  operator () (const std::weak_ptr<const T>& element)
220  {
221  std::shared_ptr<const T> shared_element(element);
222  return cmp && shared_element && cmp == shared_element;
223  }
224  };
225 
236  template<class C, typename T>
237  bool
238  contains(const C& container,
239  const std::shared_ptr<T>& element)
240  {
241  return (std::find_if(container.begin(),
242  container.end(),
243  compare_element<T>(element)) != container.end());
244  }
245 
248  };
249 
250  }
251  }
252  }
253 }
254 
255 #endif // OME_XML_MODEL_DETAIL_OMEMODELOBJECT_H
256 
257 /*
258  * Local Variables:
259  * mode:C++
260  * End:
261  */
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:247
compare_element(const std::shared_ptr< const T > &cmp)
Constructor.
Definition: OMEModelObject.h:170
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:158
const std::shared_ptr< const T > & cmp
The element to compare other elements with.
Definition: OMEModelObject.h:162
bool operator()(const std::shared_ptr< T > &element)
Compare element with another element.
Definition: OMEModelObject.h:182
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:238