LCOV - code coverage report
Current view: top level - lemon/lemon/concepts - maps.h (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 0 35 0.0 %
Date: 2020-07-01 15:24:36 Functions: 0 25 0.0 %
Branches: 0 104 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- mode: C++; indent-tabs-mode: nil; -*-
       2                 :            :  *
       3                 :            :  * This file is a part of LEMON, a generic C++ optimization library.
       4                 :            :  *
       5                 :            :  * Copyright (C) 2003-2009
       6                 :            :  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
       7                 :            :  * (Egervary Research Group on Combinatorial Optimization, EGRES).
       8                 :            :  *
       9                 :            :  * Permission to use, modify and distribute this software is granted
      10                 :            :  * provided that this copyright notice appears in all copies. For
      11                 :            :  * precise terms see the accompanying LICENSE file.
      12                 :            :  *
      13                 :            :  * This software is provided "AS IS" with no warranty of any kind,
      14                 :            :  * express or implied, and with no claim as to its suitability for any
      15                 :            :  * purpose.
      16                 :            :  *
      17                 :            :  */
      18                 :            : 
      19                 :            : #ifndef LEMON_CONCEPTS_MAPS_H
      20                 :            : #define LEMON_CONCEPTS_MAPS_H
      21                 :            : 
      22                 :            : #include <lemon/core.h>
      23                 :            : #include <lemon/concept_check.h>
      24                 :            : 
      25                 :            : ///\ingroup map_concepts
      26                 :            : ///\file
      27                 :            : ///\brief The concept of maps.
      28                 :            : 
      29                 :            : namespace lemon {
      30                 :            : 
      31                 :            :   namespace concepts {
      32                 :            : 
      33                 :            :     /// \addtogroup map_concepts
      34                 :            :     /// @{
      35                 :            : 
      36                 :            :     /// Readable map concept
      37                 :            : 
      38                 :            :     /// Readable map concept.
      39                 :            :     ///
      40                 :            :     template<typename K, typename T>
      41                 :            :     class ReadMap
      42                 :            :     {
      43                 :            :     public:
      44                 :            :       /// The key type of the map.
      45                 :            :       typedef K Key;
      46                 :            :       /// \brief The value type of the map.
      47                 :            :       /// (The type of objects associated with the keys).
      48                 :            :       typedef T Value;
      49                 :            : 
      50                 :            :       /// Returns the value associated with the given key.
      51                 :            :       Value operator[](const Key &) const {
      52                 :            :         return *static_cast<Value *>(0);
      53                 :            :       }
      54                 :            : 
      55                 :            :       template<typename _ReadMap>
      56                 :            :       struct Constraints {
      57                 :          0 :         void constraints() {
      58 [ #  # ][ #  # ]:          0 :           Value val = m[key];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      59 [ #  # ][ #  # ]:          0 :           val = m[key];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      60 [ #  # ][ #  # ]:          0 :           typename _ReadMap::Value own_val = m[own_key];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      61 [ #  # ][ #  # ]:          0 :           own_val = m[own_key];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      62                 :            : 
      63 [ #  # ][ #  # ]:          0 :           ignore_unused_variable_warning(key);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      64 [ #  # ][ #  # ]:          0 :           ignore_unused_variable_warning(val);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      65 [ #  # ][ #  # ]:          0 :           ignore_unused_variable_warning(own_key);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      66 [ #  # ][ #  # ]:          0 :           ignore_unused_variable_warning(own_val);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      67                 :          0 :         }
      68                 :            :         const Key& key;
      69                 :            :         const typename _ReadMap::Key& own_key;
      70                 :            :         const _ReadMap& m;
      71                 :            :       };
      72                 :            : 
      73                 :            :     };
      74                 :            : 
      75                 :            : 
      76                 :            :     /// Writable map concept
      77                 :            : 
      78                 :            :     /// Writable map concept.
      79                 :            :     ///
      80                 :            :     template<typename K, typename T>
      81                 :            :     class WriteMap
      82                 :            :     {
      83                 :            :     public:
      84                 :            :       /// The key type of the map.
      85                 :            :       typedef K Key;
      86                 :            :       /// \brief The value type of the map.
      87                 :            :       /// (The type of objects associated with the keys).
      88                 :            :       typedef T Value;
      89                 :            : 
      90                 :            :       /// Sets the value associated with the given key.
      91                 :            :       void set(const Key &, const Value &) {}
      92                 :            : 
      93                 :            :       /// Default constructor.
      94                 :            :       WriteMap() {}
      95                 :            : 
      96                 :            :       template <typename _WriteMap>
      97                 :            :       struct Constraints {
      98                 :          0 :         void constraints() {
      99                 :          0 :           m.set(key, val);
     100                 :          0 :           m.set(own_key, own_val);
     101                 :            : 
     102                 :          0 :           ignore_unused_variable_warning(key);
     103                 :          0 :           ignore_unused_variable_warning(val);
     104                 :          0 :           ignore_unused_variable_warning(own_key);
     105                 :          0 :           ignore_unused_variable_warning(own_val);
     106                 :          0 :         }
     107                 :            :         const Key& key;
     108                 :            :         const Value& val;
     109                 :            :         const typename _WriteMap::Key& own_key;
     110                 :            :         const typename _WriteMap::Value& own_val;
     111                 :            :         _WriteMap& m;
     112                 :            :       };
     113                 :            :     };
     114                 :            : 
     115                 :            :     /// Read/writable map concept
     116                 :            : 
     117                 :            :     /// Read/writable map concept.
     118                 :            :     ///
     119                 :            :     template<typename K, typename T>
     120                 :            :     class ReadWriteMap : public ReadMap<K,T>,
     121                 :            :                          public WriteMap<K,T>
     122                 :            :     {
     123                 :            :     public:
     124                 :            :       /// The key type of the map.
     125                 :            :       typedef K Key;
     126                 :            :       /// \brief The value type of the map.
     127                 :            :       /// (The type of objects associated with the keys).
     128                 :            :       typedef T Value;
     129                 :            : 
     130                 :            :       /// Returns the value associated with the given key.
     131                 :            :       Value operator[](const Key &) const {
     132                 :            :         return *static_cast<Value *>(0);
     133                 :            :       }
     134                 :            : 
     135                 :            :       /// Sets the value associated with the given key.
     136                 :            :       void set(const Key &, const Value &) {}
     137                 :            : 
     138                 :            :       template<typename _ReadWriteMap>
     139                 :            :       struct Constraints {
     140                 :          0 :         void constraints() {
     141                 :          0 :           checkConcept<ReadMap<K, T>, _ReadWriteMap >();
     142                 :          0 :           checkConcept<WriteMap<K, T>, _ReadWriteMap >();
     143                 :          0 :         }
     144                 :            :       };
     145                 :            :     };
     146                 :            : 
     147                 :            : 
     148                 :            :     /// Dereferable map concept
     149                 :            : 
     150                 :            :     /// Dereferable map concept.
     151                 :            :     ///
     152                 :            :     template<typename K, typename T, typename R, typename CR>
     153                 :            :     class ReferenceMap : public ReadWriteMap<K,T>
     154                 :            :     {
     155                 :            :     public:
     156                 :            :       /// Tag for reference maps.
     157                 :            :       typedef True ReferenceMapTag;
     158                 :            :       /// The key type of the map.
     159                 :            :       typedef K Key;
     160                 :            :       /// \brief The value type of the map.
     161                 :            :       /// (The type of objects associated with the keys).
     162                 :            :       typedef T Value;
     163                 :            :       /// The reference type of the map.
     164                 :            :       typedef R Reference;
     165                 :            :       /// The const reference type of the map.
     166                 :            :       typedef CR ConstReference;
     167                 :            : 
     168                 :            :     public:
     169                 :            : 
     170                 :            :       /// Returns a reference to the value associated with the given key.
     171                 :            :       Reference operator[](const Key &) {
     172                 :            :         return *static_cast<Value *>(0);
     173                 :            :       }
     174                 :            : 
     175                 :            :       /// Returns a const reference to the value associated with the given key.
     176                 :            :       ConstReference operator[](const Key &) const {
     177                 :            :         return *static_cast<Value *>(0);
     178                 :            :       }
     179                 :            : 
     180                 :            :       /// Sets the value associated with the given key.
     181                 :            :       void set(const Key &k,const Value &t) { operator[](k)=t; }
     182                 :            : 
     183                 :            :       template<typename _ReferenceMap>
     184                 :            :       struct Constraints {
     185                 :            :         typename enable_if<typename _ReferenceMap::ReferenceMapTag, void>::type
     186                 :          0 :         constraints() {
     187                 :          0 :           checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
     188                 :          0 :           ref = m[key];
     189                 :          0 :           m[key] = val;
     190                 :          0 :           m[key] = ref;
     191                 :          0 :           m[key] = cref;
     192                 :          0 :           own_ref = m[own_key];
     193                 :          0 :           m[own_key] = own_val;
     194                 :          0 :           m[own_key] = own_ref;
     195                 :          0 :           m[own_key] = own_cref;
     196 [ #  # ][ #  # ]:          0 :           m[key] = m[own_key];
     197 [ #  # ][ #  # ]:          0 :           m[own_key] = m[key];
     198                 :          0 :         }
     199                 :            :         const Key& key;
     200                 :            :         Value& val;
     201                 :            :         Reference ref;
     202                 :            :         ConstReference cref;
     203                 :            :         const typename _ReferenceMap::Key& own_key;
     204                 :            :         typename _ReferenceMap::Value& own_val;
     205                 :            :         typename _ReferenceMap::Reference own_ref;
     206                 :            :         typename _ReferenceMap::ConstReference own_cref;
     207                 :            :         _ReferenceMap& m;
     208                 :            :       };
     209                 :            :     };
     210                 :            : 
     211                 :            :     // @}
     212                 :            : 
     213                 :            :   } //namespace concepts
     214                 :            : 
     215                 :            : } //namespace lemon
     216                 :            : 
     217                 :            : #endif

Generated by: LCOV version 1.11