[Lemon-commits] [lemon_svn] alpar: r2567 - hugo/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:53:36 CET 2006
Author: alpar
Date: Wed Feb 22 13:45:59 2006
New Revision: 2567
Added:
hugo/trunk/lemon/vmap.h
Log:
vmap.h: Enables one to create maps with a virtual base class.
Added: hugo/trunk/lemon/vmap.h
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/vmap.h Wed Feb 22 13:45:59 2006
@@ -0,0 +1,112 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_LIST_GRAPH_H
+#define LEMON_LIST_GRAPH_H
+
+///\ingroup graphs
+///\file
+///\brief Virtual map support.
+
+namespace lemon {
+
+ ///Base class of the virtual maps.
+ template<class K, class V>
+ class VMapBase
+ {
+ public:
+ ///\e
+ typedef K Key;
+ ///\e
+ typedef V Value;
+
+ ///\e
+ virtual Value operator[](const Key &) const { return Value();}
+ ///\e
+ virtual void set(const Key &,const Value &) {}
+ };
+
+ ///Base class of the virtual reference maps.
+ template<class K, class V>
+ class VRefMapBase
+ {
+ public:
+ ///\e
+ typedef K Key;
+ ///\e
+ typedef V Value;
+
+ ///\e
+ virtual Value& operator[](Key &) = 0;
+ ///\e
+ virtual Value& operator[](const Key &) const = 0;
+ ///\e
+ virtual void set(const Key &,const Value &) = 0;
+ };
+
+ ///Makes a virtual map from a \ref concept::ReadMap "ReadMap"
+ template<class M, class K=typename M::Key,class V=typename M::Value>
+ class VReadMap : public VMapBase<K,V>
+ {
+ const M ↦
+ public:
+ ///\e
+ VReadMap(const M &m) : map(m) {}
+ virtual Value operator[](const Key &k) const { return map[k];}
+ };
+
+ ///Function interface for \ref VReadMap.
+ template<class M, class K=typename M::Key,class V=typename M::Value>
+ vReadMap(const M& m) {return VReadMap<M,K,V>(m);}
+
+ ///Makes a virtual map from a \ref concept::WriteMap "WriteMap"
+ template<class M, class K=typename M::Key,class V=typename M::Value>
+ class VWriteMap :public VMapBase<K,V>
+ {
+ M ↦
+ public:
+ ///\e
+ VWriteMap(M &m) : map(m) {}
+ virtual void set(const Key &k,const Value &v) { map.set(k,v);}
+ };
+
+ ///Function interface for \ref VWriteMap.
+ template<class M, class K=typename M::Key,class V=typename M::Value>
+ vWriteMap(const M& m) {return VReadMap<M,K,V>(m);}
+
+ ///Makes a virtual map from a \ref concept::ReadWriteMap "ReadWriteMap"
+ template<class M, class K=typename M::Key,class V=typename M::Value>
+ class VReadWriteMap :public VMapBase<K,V>
+ {
+ M ↦
+ public:
+ ///\e
+ VReadWriteMap(M &m) : map(m) {}
+ virtual Value operator[](const Key &k) const { return map[k];}
+ virtual void set(const Key &k,const Value &v) { map.set(k,v);}
+ };
+
+ ///Function interface for \ref VReadWriteMap.
+ template<class M, class K=typename M::Key,class V=typename M::Value>
+ vReadWriteMap(const M& m) {return VReadMap<M,K,V>(m);}
+
+ /// @}
+} //namespace lemon
+
+
+#endif
More information about the Lemon-commits
mailing list