00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PCAP_LIST_OF_TRACES_HXX_
00023 # define PCAP_LIST_OF_TRACES_HXX_
00024
00025 # include "list_of_traces.hh"
00026
00027 namespace pcapxx
00028 {
00029
00030 template <class Desc, class Bottom>
00031 list_of_traces<Desc, Bottom>::list_of_traces(const std::string& trace_names)
00032 {
00033 typedef std::vector<std::string> trace_vect_t;
00034 typedef std::pair<trace_vect_t, std::string> parse_res_t;
00035
00036 const parse_res_t pres = parse(trace_names);
00037 const trace_vect_t& names = pres.first;
00038
00039 std::string file_name;
00040
00041 if (not pres.second.empty())
00042 meta_.add("addr", pres.second);
00043 switch (names.size())
00044 {
00045 case 0:
00046 file_name = "[]";
00047 break;
00048 case 1:
00049 file_name = names.front();
00050 break;
00051 default:
00052 {
00053 size_t len = 0;
00054 bool cont = true;
00055
00056 while (cont and len <= names.front().size())
00057 {
00058 const std::string ref = names.front().substr(0, ++len);
00059
00060 for (size_t i = 1; cont and i < names.size(); ++i)
00061 if (names[i].substr(0, len) != ref)
00062 cont = false;
00063 }
00064 file_name = '[' + names.front().substr(0, len - 1) + "*]";
00065 break;
00066 }
00067 }
00068 meta_.add("file_name", file_name);
00069
00070 BOOST_FOREACH(const std::string& s, names)
00071 push_back(Desc (s));
00072
00073 update_metadata(this);
00074 }
00075
00076 template <class Desc, class Bottom>
00077 list_of_traces<Desc, Bottom>::list_of_traces(const list_of_traces& other):
00078 super_type (static_cast<const super_type&> (other)),
00079 meta_ (other.meta_)
00080 {
00081 update_metadata(this);
00082 }
00083
00084 template<class Desc, class Bottom>
00085 list_of_traces<Desc, Bottom>&
00086 list_of_traces<Desc, Bottom>::operator = (const list_of_traces& rhs)
00087 {
00088 if (&rhs == this)
00089 return *this;
00090
00091 super_type::operator = (rhs);
00092 meta_ = rhs.meta_;
00093 update_metadata(this);
00094 }
00095
00096 template <class Desc, class Bottom>
00097 const std::string&
00098 list_of_traces<Desc, Bottom>::file_name() const
00099 {
00100 return meta_["file_name"].get<std::string>();
00101 }
00102
00103 template <class Desc, class Bottom>
00104 const tool::opt::list&
00105 list_of_traces<Desc, Bottom>::metadata() const
00106 {
00107 return meta_;
00108 }
00109
00110 template <class Desc, class Bottom>
00111 void
00112 list_of_traces<Desc, Bottom>::expect(typename Desc::link_type l) const
00113 {
00114 for (size_t i = 0; i < this->size(); ++i)
00115 this->get(i).expect(l);
00116 }
00117
00118 template <class Desc, class Bottom>
00119 std::pair<std::string, size_t>
00120 list_of_traces<Desc, Bottom>::parse_word(const std::string& trace_names,
00121 const size_t start,
00122 const std::set<char>& stop_seps)
00123 {
00124 std::string w;
00125 size_t i;
00126
00127 for (i = start;
00128 i < trace_names.size() and not stop_seps.count(trace_names[i]);
00129 ++i)
00130 {
00131 if (trace_names[i] == escape_char)
00132 ++i;
00133 if (i < trace_names.size())
00134 w.push_back(trace_names[i]);
00135 }
00136 return std::make_pair(w, i);
00137 }
00138
00139 template <class Desc, class Bottom>
00140 std::pair<std::vector<std::string>, std::string>
00141 list_of_traces<Desc, Bottom>::parse(const std::string& traces_names)
00142 {
00143 std::vector<std::string> names;
00144 std::string addr;
00145 std::set<char> stop_sep_tname;
00146
00147 stop_sep_tname.insert(trace_name_sep);
00148 stop_sep_tname.insert(addr_sep);
00149
00150 size_t i = 0;
00151
00152 while (i < traces_names.size() and traces_names[i] != addr_sep)
00153 {
00154 std::pair<std::string, size_t> w = parse_word(traces_names, i,
00155 stop_sep_tname);
00156 names.push_back(w.first);
00157 i = w.second;
00158 if (i < traces_names.size() and traces_names[i] == trace_name_sep)
00159 ++i;
00160 }
00161 if (i < traces_names.size() and traces_names[i] == addr_sep)
00162 addr = parse_word(traces_names, i + 1, std::set<char> ()).first;
00163 return std::make_pair(names, addr);
00164 }
00165
00166 template <class Desc, class Bottom>
00167 void
00168 list_of_traces<Desc, Bottom>::update_metadata(list_of_traces* p)
00169 {
00170 for (unsigned i = 0; i < this->size(); ++i)
00171 this->get(i).metadata().add("list_of_traces", p);
00172 }
00173
00174 }
00175
00176 #endif // ! PCAP_LIST_OF_TRACES_HXX_