//===========================================================================
// @(#) $Name: arts++-1-1-a12 $
// @(#) $Id: ArtsPortMatrixAggregatorMap.hh,v 1.2 2004/04/21 23:51:28 kkeys 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 _ARTSPORTMATRIXAGGREGATORMAP_HH_
#define _ARTSPORTMATRIXAGGREGATORMAP_HH_

#include <map>

#include "ArtsPortMatrixAggregator.hh"
#include "ArtsAggregatorMapKey.hh"

typedef std::map<ArtsAggregatorMapKey,ArtsPortMatrixAggregator *,std::less<ArtsAggregatorMapKey> >  _artsPortMatrixAggregatorMap_t_;

//---------------------------------------------------------------------------
//  class ArtsPortMatrixAggregatorMap : public _artsPortMatrixAggregatorMap_t_
//---------------------------------------------------------------------------
//  This class abstracts a collection of ArtsPortMatrixAggregator objects
//  keyed by an ArtsAggregatorMapKey object.  It can be used to
//  build multiple ArtsPortMatrixAggregator objects from ArtsPortMatrix
//  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 ArtsPortMatrixAggregatorMap using Add()
//  one or more times, you can iterate over the entries and do whatever
//  you'd normally do with an ArtsPortMatrixAggregator object (typically,
//  convert to an ArtsPortMatrix 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 ArtsPortMatrixAggregator) 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 ArtsPortMatrixAggregatorMap : public _artsPortMatrixAggregatorMap_t_
{
public:
  //-------------------------------------------------------------------------
  //  Some typedefs to make things obvious.
  //-------------------------------------------------------------------------
  typedef _artsPortMatrixAggregatorMap_t_::iterator        iterator;
  typedef _artsPortMatrixAggregatorMap_t_::const_iterator  const_iterator;

  //-------------------------------------------------------------------------
  //                       int Add(const Arts & arts)
  //.........................................................................
  //  Adds the data contained in an Arts object (which should be a port
  //  matrix 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 port matrix
  //  data).
  //-------------------------------------------------------------------------
  int Add(const Arts & arts);

  //-------------------------------------------------------------------------
  //     int AddAllFromFile(const std::string & fileName, bool quiet = true)
  //.........................................................................
  //  Adds the data contained in all port matrix objects in the file
  //  named by fileName.  Returns the number of port matrix 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 port matrix object.
  //-------------------------------------------------------------------------
  int AddAllFromFile(const std::string & fileName, bool quiet = true);
  
  
};

#endif  // _ARTSPORTMATRIXAGGREGATORMAP_HH_
