//=-- DetailedBreakout.h - Breakout for a "Details" page... --------*- C++ -*-=
//
//  PLUGIN DESCRIPTION:
//    This plugin is meant to operate on some sort of a "Details" page, where
//    it lists all (or at least most) of the accesses that have occured for 
//    the day.  As such, this plugin should only be used on relatively low
//    volume web pages.
//
//  PLUGIN PARAMETERS:
//    Filter:        A filter corresponding to the hits you want shown!
//    Mode:          Either "Flat" or "Breakout".  Default=Breakout
//    DominateKey:   The top-level key.  If set to "Host" (the default) the 
//                   plugin output lists the pages that each host visited.  If 
//                   set to "Page", then the plugin outputs the hosts that visit
//                   each page.
//    FoldReloads:   If "True" or "1", duplicate consecutive hits to a page 
//                   from a host are combined onto a single line.  Otherwise,
//                   list on seperate lines.  Default=True.
//    DepthLimit:    Limit the maximum URL depth to a value. Default=0 (disable)
//    MaxKeys:       Limit the number of dominate keys to display... 
//    MaxKeyEntries: Limit the number of entries per dominate key.
//
//  PLUGIN AUTHOR:
//    Chris Lattner, Author of Magicstats  (sabre@nondot.org)
//
//  PLUGIN HOMEPAGE:
//     http://www.nondot.org/sabre/MagicStats/Plugins/DetailedBreakout/
//
//  PLUGIN VERSION / COMPATIBILITY:
//     DetailedBreakout v1.0 / MagicStats 2.0+
//
//=---------------------------------------------------------------------------=
//  This file is copyright (c) 1997-2000 Chris Lattner and stuff.
//=---------------------------------------------------------------------------=

#include "BreakoutRenderer.h"
#include "VarTable.h"
#include "Date.h"

// Primary (P) holds the time of the hit.  The Secondary contains the secondary
// key of the data... if the primary key is Host, then S is URL, if Primary key
// is URL, then Secondary is Host.
//
typedef DataPair<String, String> HitInfo; // {URL|Host}, Referrer info
typedef DataPair<Date, HitInfo > HitRec;  // One record for element of the list
typedef LinkedList<HitRec>       KeyRec;  // One record for each primary key

class DetailedBreakout : public PluginTemplate<PagePlugin,DetailedBreakout> {
public:
  inline static unsigned int GetCurrentVersion() {
    return 101;                       // Version 1.01
  } 

  inline static const char *GetPluginName() {
    return "DetailedBreakout";
  }

  DetailedBreakout(int &CE);

  // The full name consists of all of the data settings that alter the data 
  // that is kept track of and stored.
  void GetFullName(VarTable &Params, String &FullName, int UpdateFreq);
  void ProcessAccess(AccessFormatPlugin &A);

  void OutputHTML(ostream &O, VarTable &Params);
  void ResetState();

  void LoadState(Serialize &I);
  void SaveState(Serialize &O);

private :

  void AddExplodedDirectories(String Path, String &T, int Depth,
                              BreakoutRenderer::Tree &TheTree);

private :
  Table<String, KeyRec> DataTable;
  int DominateKey;  // Either FEURL or FEHost
  int SecondaryKey; // Either FEHost or FEURL
};
