//===========================================================================
// @(#) $Name: arts++-1-1-a8 $
// @(#) $Id: ArtsProtocolTableAggregatorMap.hh,v 1.5 2000/10/02 17:05:19 dwm Exp $
//===========================================================================
//  Copyright Notice
//
//  By accessing this software, arts++, you are duly informed
//  of and agree to be bound by the conditions described below in this
//  notice:
//
//  This software product, arts++, is developed by Daniel W. McRobb, and
//  copyrighted(C) 1998 by the University of California, San Diego
//  (UCSD), with all rights reserved.  UCSD administers the CAIDA grant,
//  NCR-9711092, under which part of this code was developed.
//
//  There is no charge for arts++ software.  You can redistribute it
//  and/or modify it under the terms of the GNU Lesser General Public
//  License, Version 2.1, February 1999, which is incorporated by
//  reference herein.
//
//  arts++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF
//  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that the use
//  of it will not infringe on any third party's intellectual
//  property rights.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with arts++.  Copies can also be obtained from:
//
//    http://www.gnu.org/copyleft/lesser.html
//
//  or by writing to:
//
//  Free Software Foundation, Inc.
//  59 Temple Place, Suite 330
//  Boston, MA 02111-1307
//  USA
//
//  Or contact:
//
//    info@caida.org
//===========================================================================

#ifndef _ARTSPROTOCOLTABLEAGGREGATORMAP_HH_
#define _ARTSPROTOCOLTABLEAGGREGATORMAP_HH_

#include <map>

#include "ArtsProtocolTableAggregator.hh"
#include "ArtsAggregatorMapKey.hh"

typedef map<ArtsAggregatorMapKey,ArtsProtocolTableAggregator *,less<ArtsAggregatorMapKey> >  _artsProtocolTableAggregatorMap_t_;

//---------------------------------------------------------------------------
//  class ArtsProtocolTableAggregatorMap :
//    public _artsProtocolTableAggregatorMap_t_
//---------------------------------------------------------------------------
//  This class abstracts a collection of ArtsProtocolTableAggregator
//  objects keyed by an ArtsAggregatorMapKey object.  It can be used to
//  build multiple ArtsProtocolTableAggregator objects from
//  ArtsProtocolTable objects.
//
//  The ArtsAggregatorMapKey class contains a router IP address
//  and an interface index.  These are the keys we need to keep data
//  separate per router interface, and should be present in the input
//  data (as host and interface attributes in Arts::Attributes()).
//
//  Once you're done loading an ArtsProtocolTableAggregatorMap using
//  Add() one or more times, you can iterate over the entries and do
//  whatever you'd normally do with an ArtsProtocolTableAggregator
//  object (typically, convert to an ArtsProtocolTable object and write
//  to an ofstream).  Note that since an STL <map> iterator dereference
//  returns a <pair>, you'll have access to the key (an
//  ArtsAggregatorMapKey) via (*iter).first and the value (an
//  ArtsProtocolTableAggregator) via (*iter).second.  Standard STL
//  stuff...
//
//  Note we just inherit from an STL map instantiation, since we're not
//  much more than a pure <map>.
//---------------------------------------------------------------------------
class ArtsProtocolTableAggregatorMap :
  public _artsProtocolTableAggregatorMap_t_
{
public:
  //-------------------------------------------------------------------------
  //  Some typedefs to make things obvious.
  //-------------------------------------------------------------------------
  typedef _artsProtocolTableAggregatorMap_t_::iterator        iterator;
  typedef _artsProtocolTableAggregatorMap_t_::const_iterator  const_iterator;

  ~ArtsProtocolTableAggregatorMap()
  {
    iterator  iter;

    for (iter = (*this).begin(); iter != (*this).end(); iter++)
      delete((*iter).second);
    (*this).erase((*this).begin(),(*this).end());
  }
  
  //-------------------------------------------------------------------------
  //                       int Add(const Arts & arts)
  //.........................................................................
  //  Adds the data contained in an Arts object (which should be a
  //  protocol table object) to the aggregator map.  We use the
  //  Attributes() in the input Arts object to determine where in the
  //  map we should add the data (router and interface index).  Returns
  //  0 on success, -1 on failure (i.e. if the Arts object does not
  //  contain protocol table data).
  //-------------------------------------------------------------------------
  int Add(const Arts & arts);

  //-------------------------------------------------------------------------
  //     int AddAllFromFile(const string & fileName, bool quiet = true)
  //.........................................................................
  //  Adds the data contained in all protocol table objects in the file
  //  named by fileName.  Returns the number of protocol table objects
  //  added on success, -1 on failure.  If quiet is set to false, this
  //  function will print a single '.'  on stdout every time it reads a
  //  protocol table object.
  //-------------------------------------------------------------------------
  int AddAllFromFile(const string & fileName, bool quiet = true);
  
  
};

#endif  // _ARTSPROTOCOLTABLEAGGREGATORMAP_HH_
