HDFAttributes.h

Go to the documentation of this file.
00001 /* -*- c++ -*-
00002  * $Id: HDFAttributes.h,v 1.10 2006/05/16 20:06:34 brook Exp $
00003  */
00004 
00005 /*
00006  * ClearSilver++ Software License.
00007  *
00008  * Copyright (c) 2005,2006 Brook Milligan <brook@nmsu.edu>
00009  * All rights reserved.
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  * 
00015  * 1. Redistributions of source code must retain the above copyright
00016  *    notice, this list of conditions and the following disclaimer.
00017  * 2. Redistributions in binary form must reproduce the above
00018  *    copyright notice, this list of conditions and the following
00019  *    disclaimer in the documentation and/or other materials provided
00020  *    with the distribution.
00021  * 3. The name of the author may not be used to endorse or promote
00022  *    products derived from this software without specific prior
00023  *    written permission.
00024  * 
00025  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00026  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00027  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00028  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00029  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00031  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00033  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036  */
00037 
00043 #ifndef HDFAttributes_h_
00044 #define HDFAttributes_h_ 1
00045 
00046 #include <iterator>
00047 #include <boost/operators.hpp>
00048 #include <boost/shared_ptr.hpp>
00049 #include "Nodes.h"
00050 
00051 class _attr;                    // forward declaration
00052 
00053 namespace ClearSilver
00054 {
00065   class HDFAttributes : boost::equality_comparable<HDFAttributes>
00066   {
00067   public:
00069     //\{
00070     typedef size_t size_type;
00071     typedef char* key_type;
00072 
00073     class mapped_type
00074     {
00075     public:
00076       mapped_type ();
00077       mapped_type (const char*);
00078       mapped_type (std::string);
00079       mapped_type (char**);     // assume non-nil pointer
00080       mapped_type (const mapped_type&);
00081       ~mapped_type () throw();
00082       mapped_type& operator = (const mapped_type&);
00083       mapped_type& operator = (const char*); // assume non-nil pointer
00084       void swap (mapped_type&) throw();
00085       operator char* ();
00086       operator const char* () const;
00087 
00088     private:
00089       char * value_;
00090       char** valuep_;           // pointer to owner of data (for assignment)
00091     };
00092 
00093     typedef std::pair<const key_type, mapped_type> value_type;
00094     typedef value_type& reference;
00095     typedef const value_type& const_reference;
00096     
00097     class iterator : boost::equality_comparable<HDFAttributes::iterator>
00098     {
00099       friend class HDFAttributes;
00100     public:
00101       struct forward_iterator_tag;
00102       typedef forward_iterator_tag iterator_category;
00103 
00104     public:
00105       iterator ();
00106       explicit iterator (_attr*);
00107       iterator (const iterator&);
00108       ~iterator () throw();
00109       iterator& operator = (const iterator&);
00110       void swap (iterator&) throw ();
00111 
00112       operator bool () const;
00113       value_type  operator * ();
00114       value_type* operator -> ();
00115       iterator& operator ++ ();
00116       iterator  operator ++ (int);
00117 
00118       friend bool operator == (const iterator&, const iterator&);
00119 
00120     private:
00121       _attr* node_;
00122       boost::shared_ptr<value_type> value_;
00123     };
00124 
00125     class const_iterator
00126       : boost::equality_comparable<HDFAttributes::const_iterator>
00127     {
00128       friend class HDFAttributes;
00129     public:
00130       struct forward_iterator_tag;
00131       typedef forward_iterator_tag iterator_category;
00132 
00133     public:
00134       const_iterator ();
00135       explicit const_iterator (_attr*);
00136       const_iterator (const const_iterator&);
00137       ~const_iterator () throw();
00138       const_iterator& operator = (const const_iterator&);
00139       void swap (const_iterator&) throw ();
00140 
00141       operator bool () const;
00142       value_type  operator * ();
00143       value_type* operator -> ();
00144       const_iterator& operator ++ ();
00145       const_iterator  operator ++ (int);
00146 
00147       friend bool operator == (const const_iterator&, const const_iterator&);
00148 
00149     private:
00150       _attr* node_;
00151       boost::shared_ptr<value_type> value_;
00152     };
00153     //\}
00154 
00155   public:
00157     //\{
00159     HDFAttributes ();
00161     explicit HDFAttributes (const Nodes& path, _attr* head);
00163     HDFAttributes (const HDFAttributes&);
00165     ~HDFAttributes () throw();
00166 
00168     HDFAttributes& operator = (const HDFAttributes&);
00169 
00171     void swap (HDFAttributes&) throw();
00172     //\}
00173 
00175     //\{
00177     size_type size () const;
00179     bool empty () const;
00193     size_type count (const key_type& key);
00207     iterator find (const key_type& key);
00221     const_iterator find (const key_type& key) const;
00222     //\}
00223 
00225     mapped_type operator [] (const key_type&);
00226 
00228     //\{
00229     iterator begin ();
00230     iterator end ();
00231     const_iterator begin () const;
00232     const_iterator end () const;
00233     //\}
00234 
00236     //\{
00238     std::pair<iterator,bool> insert (const value_type&);
00240     iterator insert (iterator, const value_type&);
00242     size_type erase (const key_type&) throw();
00244     void erase (iterator);
00246     void erase (iterator begin, iterator end);
00248     void clear () throw();
00249     //\}
00250 
00252     friend bool operator == (const HDFAttributes&, const HDFAttributes&);
00253 
00260     static bool& debug ();
00261 
00262   private:
00263     Nodes path_;
00264     _attr* head_;
00265   };
00266 
00267 };                              // namespace ClearSilver
00268 
00269 #endif

Generated on Tue May 16 14:50:52 2006 for ClearSilver C++ Library by  doxygen 1.4.5