include/wipal/pcap/list_of_traces.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 PCAP_LIST_OF_TRACES_HXX_
00023 # define PCAP_LIST_OF_TRACES_HXX_
00024 
00025 # include <boost/tokenizer.hpp>
00026 # include <boost/foreach.hpp>
00027 
00028 # include "list_of_traces.hh"
00029 
00030 namespace pcapxx
00031 {
00032 
00033   template <class Desc, class Bottom>
00034   list_of_traces<Desc, Bottom>::list_of_traces(const std::string& trace_names,
00035                                                const std::string& separators)
00036   {
00037     typedef boost::char_separator<char>         separator_type;
00038     typedef boost::tokenizer<separator_type>    tokenizer_type;
00039     typedef std::vector<std::string>            vector;
00040 
00041     const separator_type        sep (separators.c_str());
00042     const tokenizer_type        tok (trace_names, sep);
00043     vector                      names;
00044 
00045     BOOST_FOREACH(const std::string& t, tok)
00046       names.push_back(t);
00047 
00048     switch (names.size())
00049       {
00050       case 0:
00051         name_ = "[]";
00052         break;
00053       case 1:
00054         name_ = names.front();
00055         break;
00056       default:
00057         {
00058           size_t        len = 0;
00059           bool          cont = true;
00060 
00061           while (cont)
00062             {
00063               const std::string ref = names.front().substr(0, ++len);
00064 
00065               for (size_t i = 1; cont and i < names.size(); ++i)
00066                 if (names[i].substr(0, len) != ref)
00067                   cont = false;
00068             }
00069           name_ = '[' + names.front().substr(0, len - 1) + "*]";
00070           break;
00071         }
00072       }
00073 
00074     BOOST_FOREACH(const std::string& s, names)
00075       push_back(Desc (s));
00076   }
00077 
00078   template <class Desc, class Bottom>
00079   const std::string&
00080   list_of_traces<Desc, Bottom>::file_name() const
00081   {
00082     return name_;
00083   }
00084 
00085   template <class Desc, class Bottom>
00086   void
00087   list_of_traces<Desc, Bottom>::expect(typename Desc::link_type l) const
00088   {
00089     for (size_t i = 0; i < this->size(); ++i)
00090       this->iterable(i).expect(l);
00091   }
00092 
00093 } // End of namespace pcapxx.
00094 
00095 #endif // ! PCAP_LIST_OF_TRACES_HXX_

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