include/wipal/wifi/addr_mapping.hxx

00001 /*
00002  * WiPal - A library and a set of tools to manipulate wireless traces.
00003  * Copyright (C) 2007  Universite Pierre et Marie Curie - Paris 6
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00018  * MA  02110-1301  USA
00019  *
00020  * Author: Thomas Claveirole <thomas.claveirole@lip6.fr>
00021  */
00022 #ifndef WIFI_ADDR_MAPPING_HXX_
00023 # define WIFI_ADDR_MAPPING_HXX_
00024 
00025 # include <utility>
00026 
00027 # include "addr_mapping.hh"
00028 
00029 namespace wifi
00030 {
00031   inline
00032   addr_mapping::addr_mapping(const std::string& filename): datafile (filename)
00033   {
00034     std::ifstream       f (filename.c_str());
00035 
00036     if (f)
00037       load(f);
00038   }
00039 
00040   inline
00041   unsigned
00042   addr_mapping::operator [] (const wifi::addr& a)
00043   {
00044     typedef std::pair<map_type::iterator, bool> insert_return;
00045 
00046     const size_t        i = map_.size() + 1;
00047     const insert_return r = map_.insert(std::make_pair(a, i));
00048 
00049     if (r.second)
00050       *this << i << '\t' << a << '\n';
00051 
00052     return r.first->second;
00053   }
00054 
00055   inline
00056   void
00057   addr_mapping::load(std::istream& in)
00058   {
00059     while (true)
00060       {
00061         std::string     a;
00062         unsigned        i;
00063 
00064         in >> i >> a;
00065         if (not in or in.eof())
00066           break;
00067         map_.insert(std::make_pair(a, i));
00068       }
00069   }
00070 
00071 } // End of namespace wifi.
00072 
00073 #endif // ! WIFI_ADDR_MAPPING_HXX_

Generated on Tue Jan 15 19:32:31 2008 for wipal by  doxygen 1.5.4