src/work/alpar/rw_nonref_map.cc
changeset 1001 afe5cf34aa50
parent 986 e997802b855c
equal deleted inserted replaced
3:df5a04264aa9 4:7d35205bc43d
     8 {
     8 {
     9 public:
     9 public:
    10   typedef GG Graph;
    10   typedef GG Graph;
    11   typedef typename GG::Edge Edge;
    11   typedef typename GG::Edge Edge;
    12   
    12   
    13   typedef Edge KeyType;
    13   typedef Edge Key;
    14   typedef TT ValueType;
    14   typedef TT Value;
    15   
    15   
    16   class RefType 
    16   class RefType 
    17   {
    17   {
    18     Graph &G;
    18     Graph &G;
    19     Edge e;
    19     Edge e;
    20   public:
    20   public:
    21     RefType(Graph &_G,Edge _e) : G(_G), e(_e) { }
    21     RefType(Graph &_G,Edge _e) : G(_G), e(_e) { }
    22     
    22     
    23     operator ValueType() const 
    23     operator Value() const 
    24     {
    24     {
    25       ValueType tmp;
    25       Value tmp;
    26       std::cout << G.id(G.source(e)) << "->"
    26       std::cout << G.id(G.source(e)) << "->"
    27 		<< G.id(G.target(e)) << ": ";
    27 		<< G.id(G.target(e)) << ": ";
    28       std::cin  >> tmp;
    28       std::cin  >> tmp;
    29       return tmp;
    29       return tmp;
    30     }
    30     }
    31     ValueType operator = (ValueType v) const
    31     Value operator = (Value v) const
    32     {
    32     {
    33       std::cout << G.id(G.source(e)) << "->"
    33       std::cout << G.id(G.source(e)) << "->"
    34 		<< G.id(G.target(e)) << ": " << v << '\n';
    34 		<< G.id(G.target(e)) << ": " << v << '\n';
    35       return v;
    35       return v;
    36     }
    36     }
    45 
    45 
    46 template<class K,class T>
    46 template<class K,class T>
    47 class NullMap
    47 class NullMap
    48 {
    48 {
    49 public:
    49 public:
    50   typedef K KeyType;
    50   typedef K Key;
    51   typedef T ValueType;
    51   typedef T Value;
    52   
    52   
    53   class RefType 
    53   class RefType 
    54   {
    54   {
    55     ValueType val;
    55     Value val;
    56   public:
    56   public:
    57     RefType(ValueType v) : val(v) { }   
    57     RefType(Value v) : val(v) { }   
    58     operator ValueType() const { return val; }
    58     operator Value() const { return val; }
    59     ValueType operator = (ValueType v) const { return val; }
    59     Value operator = (Value v) const { return val; }
    60   };
    60   };
    61   
    61   
    62 private:
    62 private:
    63   ValueType val;
    63   Value val;
    64 public:
    64 public:
    65   NullMap(ValueType v) : val(v) { }
    65   NullMap(Value v) : val(v) { }
    66   RefType operator[] (KeyType e) const { return RefType(v);}  
    66   RefType operator[] (Key e) const { return RefType(v);}  
    67 };
    67 };
    68 
    68 
    69 int main()
    69 int main()
    70 {
    70 {
    71   typedef SmartGraph Graph;
    71   typedef SmartGraph Graph;