<commit_before>// @(#)root/base:$Name:  $:$Id: TAttAxis.cxx,v 1.9 2004/09/13 16:39:12 brun Exp $
// Author: Rene Brun   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TFile.h"
#include "TMath.h"
#include "TAttAxis.h"
#include "TStyle.h"
#include "TVirtualPad.h"
#include "TColor.h"

ClassImp(TAttAxis)

//______________________________________________________________________________
//
//  Manages histogram axis attributes
//

TAttAxis::TAttAxis()
{
   // Constructor.
   ResetAttAxis();
}

//______________________________________________________________________________
TAttAxis::~TAttAxis()
{
   // Destructor.
}

//______________________________________________________________________________
void TAttAxis::Copy(TAttAxis &attaxis) const
{
   // Copy of the object.
   attaxis.fNdivisions  = fNdivisions;
   attaxis.fAxisColor   = fAxisColor;
   attaxis.fLabelColor  = fLabelColor;
   attaxis.fLabelFont   = fLabelFont;
   attaxis.fLabelOffset = fLabelOffset;
   attaxis.fLabelSize   = fLabelSize;
   attaxis.fTickLength  = fTickLength;
   attaxis.fTitleOffset = fTitleOffset;
   attaxis.fTitleSize   = fTitleSize;
   attaxis.fTitleColor  = fTitleColor;
   attaxis.fTitleFont   = fTitleFont;
}

//______________________________________________________________________________
void TAttAxis::ResetAttAxis(Option_t *option)
{
   if (gStyle) {
      fNdivisions  = gStyle->GetNdivisions(option);
      fAxisColor   = gStyle->GetAxisColor(option);
      fLabelColor  = gStyle->GetLabelColor(option);
      fLabelFont   = gStyle->GetLabelFont(option);
      fLabelOffset = gStyle->GetLabelOffset(option);
      fLabelSize   = gStyle->GetLabelSize(option);
      fTickLength  = gStyle->GetTickLength(option);
      fTitleOffset = gStyle->GetTitleOffset(option);
      fTitleSize   = gStyle->GetTitleSize(option);
      fTitleColor  = gStyle->GetTitleColor(option);
      fTitleFont   = gStyle->GetTitleFont(option);
   } else {
      fNdivisions  = 510;
      fAxisColor   = 1;
      fLabelColor  = 1;
      fLabelFont   = 62;
      fLabelOffset = 0.005;
      fLabelSize   = 0.04;
      fTickLength  = 0.03;
      fTitleOffset = 1;
      fTitleSize   = fLabelSize;
      fTitleColor  = 1;
      fTitleFont   = 62;
   }
}

//______________________________________________________________________________
void TAttAxis::SaveAttributes(ofstream &out, const char *name, const char *subname)
{
    // Save axis attributes as C++ statement(s) on output stream out

   if (fNdivisions != 510) {
      out<<"   "<<name<<subname<<"->SetNdivisions("<<fNdivisions<<");"<<endl;
   }
   if (fAxisColor != 1) {
      if (fAxisColor > 228) {
         TColor::SaveColor(out, fAxisColor);
         out<<"   "<<name<<subname<<"->SetAxisColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetAxisColor("<<fAxisColor<<");"<<endl;
   }
   if (fLabelColor != 1) {
      if (fLabelColor > 228) {
         TColor::SaveColor(out, fLabelColor);
         out<<"   "<<name<<subname<<"->SetLabelColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetLabelColor("<<fLabelColor<<");"<<endl;
   }
   if (fLabelFont != 62) {
      out<<"   "<<name<<subname<<"->SetLabelFont("<<fLabelFont<<");"<<endl;
   }
   if (TMath::Abs(fLabelOffset-0.005) > 0.0001) {
      out<<"   "<<name<<subname<<"->SetLabelOffset("<<fLabelOffset<<");"<<endl;
   }
   if (TMath::Abs(fLabelSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<endl;
   }
   if (TMath::Abs(fTitleSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleSize("<<fTitleSize<<");"<<endl;
   }
   if (TMath::Abs(fTickLength-0.03) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTickLength("<<fTickLength<<");"<<endl;
   }
   if (TMath::Abs(fTitleOffset-1) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleOffset("<<fTitleOffset<<");"<<endl;
   }
   if (fTitleColor != 1) {
      if (fTitleColor > 228) {
         TColor::SaveColor(out, fTitleColor);
         out<<"   "<<name<<subname<<"->SetTitleColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetTitleColor("<<fTitleColor<<");"<<endl;
   }
   if (fTitleFont != 62) {
      out<<"   "<<name<<subname<<"->SetTitleFont("<<fTitleFont<<");"<<endl;
   }
}

//______________________________________________________________________________
void TAttAxis::SetAxisColor(Color_t color)
{
//   Set color of the line axis and tick marks

   fAxisColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelColor(Color_t color)
{
//   Set color of labels

   fLabelColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelFont(Style_t font)
{

   fLabelFont = font;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelOffset(Float_t offset)
{
//   Set distance between the axis and the labels
//   The distance is expressed in per cent of the pad width

   fLabelOffset = offset;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelSize(Float_t size)
{
//   Set size of axis labels
//   The size is expressed in per cent of the pad width

   fLabelSize = size;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetNdivisions(Int_t n, Bool_t optim)
{
//   Set the number of divisions for this axis
//   if optim = kTRUE (default), the number of divisions will be
//                      optimized around the specified value.
//   if optim = kFALSE, or n < 0, the axis will be forced to use
//                      exactly n divisions.

   fNdivisions = n;
   if (!optim) fNdivisions = -TMath::Abs(n);
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTickLength(Float_t length)
{
//   Set tick mark length
//   The length is expressed in per cent of the pad width

   fTickLength = length;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleOffset(Float_t offset)
{
//   Set distance between the axis and the axis title
//   Offset is a correction factor with respect to the "standard" value.
//   offset = 1  uses the default position that is computed in function
//   of the label offset and size.
//   offset = 1.2 will add 20 per cent more to the default offset.

   fTitleOffset = offset;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleSize(Float_t size)
{
//   Set size of axis title
//   The size is expressed in per cent of the pad width

   fTitleSize = size;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleColor(Color_t color)
{
//   Set color of axis title

   fTitleColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleFont(Style_t font)
{

   fTitleFont = font;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::Streamer(TBuffer &R__b)
{
   // Stream an object of class TAttAxis.

   if (R__b.IsReading()) {
      UInt_t R__s, R__c;
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
      if (R__v > 3) {
         TAttAxis::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
         return;
      }
      //====process old versions before automatic schema evolution
      R__b >> fNdivisions;
      R__b >> fAxisColor;
      R__b >> fLabelColor;
      R__b >> fLabelFont;
      R__b >> fLabelOffset;
      R__b >> fLabelSize;
      R__b >> fTickLength;
      R__b >> fTitleOffset;
      // !file is the case of only TMapFile
      TFile *file = (TFile*)R__b.GetParent();
      if (R__v > 1 && (!file || (file && file->GetVersion() > 900)))
         R__b >> fTitleSize;
      else
         fTitleSize = fLabelSize;
      if (R__v > 2) {
         R__b >> fTitleColor;
         R__b >> fTitleFont;
      }
      //====end of old versions

   } else {
      TAttAxis::Class()->WriteBuffer(R__b,this);
   }
}
<commit_msg>- Complete TAttAxis::SetNdivisions help - Changes to make the rules checker happy<commit_after>// @(#)root/base:$Name:  $:$Id: TAttAxis.cxx,v 1.10 2005/11/16 20:04:11 pcanal Exp $
// Author: Rene Brun   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TFile.h"
#include "TMath.h"
#include "TAttAxis.h"
#include "TStyle.h"
#include "TVirtualPad.h"
#include "TColor.h"

ClassImp(TAttAxis)

//______________________________________________________________________________
//
//  Manages histogram axis attributes
//

TAttAxis::TAttAxis()
{
   // Constructor.
   ResetAttAxis();
}

//______________________________________________________________________________
TAttAxis::~TAttAxis()
{
   // Destructor.
}

//______________________________________________________________________________
void TAttAxis::Copy(TAttAxis &attaxis) const
{
   // Copy of the object.

   attaxis.fNdivisions  = fNdivisions;
   attaxis.fAxisColor   = fAxisColor;
   attaxis.fLabelColor  = fLabelColor;
   attaxis.fLabelFont   = fLabelFont;
   attaxis.fLabelOffset = fLabelOffset;
   attaxis.fLabelSize   = fLabelSize;
   attaxis.fTickLength  = fTickLength;
   attaxis.fTitleOffset = fTitleOffset;
   attaxis.fTitleSize   = fTitleSize;
   attaxis.fTitleColor  = fTitleColor;
   attaxis.fTitleFont   = fTitleFont;
}

//______________________________________________________________________________
void TAttAxis::ResetAttAxis(Option_t *option)
{
   // Reset axis attributes

   if (gStyle) {
      fNdivisions  = gStyle->GetNdivisions(option);
      fAxisColor   = gStyle->GetAxisColor(option);
      fLabelColor  = gStyle->GetLabelColor(option);
      fLabelFont   = gStyle->GetLabelFont(option);
      fLabelOffset = gStyle->GetLabelOffset(option);
      fLabelSize   = gStyle->GetLabelSize(option);
      fTickLength  = gStyle->GetTickLength(option);
      fTitleOffset = gStyle->GetTitleOffset(option);
      fTitleSize   = gStyle->GetTitleSize(option);
      fTitleColor  = gStyle->GetTitleColor(option);
      fTitleFont   = gStyle->GetTitleFont(option);
   } else {
      fNdivisions  = 510;
      fAxisColor   = 1;
      fLabelColor  = 1;
      fLabelFont   = 62;
      fLabelOffset = 0.005;
      fLabelSize   = 0.04;
      fTickLength  = 0.03;
      fTitleOffset = 1;
      fTitleSize   = fLabelSize;
      fTitleColor  = 1;
      fTitleFont   = 62;
   }
}

//______________________________________________________________________________
void TAttAxis::SaveAttributes(ofstream &out, const char *name, const char *subname)
{
    // Save axis attributes as C++ statement(s) on output stream out

   if (fNdivisions != 510) {
      out<<"   "<<name<<subname<<"->SetNdivisions("<<fNdivisions<<");"<<endl;
   }
   if (fAxisColor != 1) {
      if (fAxisColor > 228) {
         TColor::SaveColor(out, fAxisColor);
         out<<"   "<<name<<subname<<"->SetAxisColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetAxisColor("<<fAxisColor<<");"<<endl;
   }
   if (fLabelColor != 1) {
      if (fLabelColor > 228) {
         TColor::SaveColor(out, fLabelColor);
         out<<"   "<<name<<subname<<"->SetLabelColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetLabelColor("<<fLabelColor<<");"<<endl;
   }
   if (fLabelFont != 62) {
      out<<"   "<<name<<subname<<"->SetLabelFont("<<fLabelFont<<");"<<endl;
   }
   if (TMath::Abs(fLabelOffset-0.005) > 0.0001) {
      out<<"   "<<name<<subname<<"->SetLabelOffset("<<fLabelOffset<<");"<<endl;
   }
   if (TMath::Abs(fLabelSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<endl;
   }
   if (TMath::Abs(fTitleSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleSize("<<fTitleSize<<");"<<endl;
   }
   if (TMath::Abs(fTickLength-0.03) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTickLength("<<fTickLength<<");"<<endl;
   }
   if (TMath::Abs(fTitleOffset-1) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleOffset("<<fTitleOffset<<");"<<endl;
   }
   if (fTitleColor != 1) {
      if (fTitleColor > 228) {
         TColor::SaveColor(out, fTitleColor);
         out<<"   "<<name<<subname<<"->SetTitleColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetTitleColor("<<fTitleColor<<");"<<endl;
   }
   if (fTitleFont != 62) {
      out<<"   "<<name<<subname<<"->SetTitleFont("<<fTitleFont<<");"<<endl;
   }
}

//______________________________________________________________________________
void TAttAxis::SetAxisColor(Color_t color)
{
   // Set color of the line axis and tick marks

   fAxisColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelColor(Color_t color)
{
   // Set color of labels

   fLabelColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelFont(Style_t font)
{
   // Set labels' font.

   fLabelFont = font;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelOffset(Float_t offset)
{
   // Set distance between the axis and the labels
   // The distance is expressed in per cent of the pad width

   fLabelOffset = offset;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetLabelSize(Float_t size)
{
   // Set size of axis labels
   // The size is expressed in per cent of the pad width

   fLabelSize = size;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetNdivisions(Int_t n, Bool_t optim)
{
   // Set the number of divisions for this axis.
   //
   // if optim = kTRUE (default), the number of divisions will be
   //                   optimized around the specified value.
   // if optim = kFALSE, or n < 0, the axis will be forced to use
   //                   exactly n divisions.
   //
   // n = n1 + 100*n2 + 10000*n3
   //
   // Where n1 is the number of primary divisions,
   // n2 is the number of second order divisions and
   // n3 is the number of third order divisions.
   //
   // e.g. 512 means 12 primary and 5 secondary divisions.
   //
   // If the number of divisions is "optimized" (see above) n1, n2, n3 are
   // maximum values.

   fNdivisions = n;
   if (!optim) fNdivisions = -TMath::Abs(n);
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTickLength(Float_t length)
{
   // Set tick mark length
   // The length is expressed in per cent of the pad width

   fTickLength = length;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleOffset(Float_t offset)
{
   // Set distance between the axis and the axis title
   // Offset is a correction factor with respect to the "standard" value.
   // offset = 1  uses the default position that is computed in function
   // of the label offset and size.
   // offset = 1.2 will add 20 per cent more to the default offset.

   fTitleOffset = offset;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleSize(Float_t size)
{
   // Set size of axis title
   // The size is expressed in per cent of the pad width

   fTitleSize = size;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleColor(Color_t color)
{
   // Set color of axis title

   fTitleColor = color;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::SetTitleFont(Style_t font)
{
   // Set the title font.

   fTitleFont = font;
   if (gPad) gPad->Modified();
}

//______________________________________________________________________________
void TAttAxis::Streamer(TBuffer &R__b)
{
   // Stream an object of class TAttAxis.

   if (R__b.IsReading()) {
      UInt_t R__s, R__c;
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
      if (R__v > 3) {
         TAttAxis::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
         return;
      }
      //====process old versions before automatic schema evolution
      R__b >> fNdivisions;
      R__b >> fAxisColor;
      R__b >> fLabelColor;
      R__b >> fLabelFont;
      R__b >> fLabelOffset;
      R__b >> fLabelSize;
      R__b >> fTickLength;
      R__b >> fTitleOffset;
      // !file is the case of only TMapFile
      TFile *file = (TFile*)R__b.GetParent();
      if (R__v > 1 && (!file || (file && file->GetVersion() > 900)))
         R__b >> fTitleSize;
      else
         fTitleSize = fLabelSize;
      if (R__v > 2) {
         R__b >> fTitleColor;
         R__b >> fTitleFont;
      }
      //====end of old versions

   } else {
      TAttAxis::Class()->WriteBuffer(R__b,this);
   }
}
<|endoftext|>


<commit_before>// @(#)root/base:$Name:  $:$Id: TAttFill.cxx,v 1.12 2006/04/06 09:38:58 couet Exp $
// Author: Rene Brun   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TAttFill.h"
#include "TVirtualPad.h"
#include "TStyle.h"
#include "TVirtualX.h"
#include "TVirtualPadEditor.h"
#include "TColor.h"

ClassImp(TAttFill)

//______________________________________________________________________________
//*-*-*-*-*-*-*-*-*-*-*-*-*Fill Area Attributes class*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      ==========================
//*-*  Fill Area attributes are:
//*-*    Fill Color
//*-*    Fill Style
//*-*
//*-*  This class is used (in general by secondary inheritance)
//*-*  by many other classes (graphics, histograms).
//*-*
//*-*  The following table shows the list of default colors.
//Begin_Html
/*

*/
//End_Html
//
//  Conventions for fill styles:
//    0    : hollow
//    1001 : Solid
//    2001 : hatch style
//    3000+pattern_number (see below)
//    4000 :the window is transparent.
//    4000 to 4100 the window is 100% transparent to 100% opaque
//
//  pattern_number can have any value from 1 to 25 (see table), or any value
// from 100 to 999. For the latest the numbering convention is the following:
//
//            pattern_number = ijk      (FillStyle = 3ijk)
//
//    i (1-9) : specify the space between each hatch
//              1 = 1/2mm  9 = 6mm
//
//    j (0-9) : specify angle between 0 and 90 degrees
//
//              0 = 0
//              1 = 10
//              2 = 20
//              3 = 30
//              4 = 45
//              5 = Not drawn
//              6 = 60
//              7 = 70
//              8 = 80
//              9 = 90
//
//    k (0-9) : specify angle between 90 and 180 degrees
//              0 = 180
//              1 = 170
//              2 = 160
//              3 = 150
//              4 = 135
//              5 = Not drawn
//              6 = 120
//              7 = 110
//              8 = 100
//              9 = 90
//
//*-*  The following table shows the list of pattern styles.
//Begin_Html
/*

*/
//End_Html
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

//______________________________________________________________________________
TAttFill::TAttFill()
{
//*-*-*-*-*-*-*-*-*-*-*-*-*AttFill default constructor*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      ===========================
//*-*  Default fill attributes are taking from the current style
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
   if (!gStyle) return;
   fFillColor = gStyle->GetFillColor();
   fFillStyle = gStyle->GetFillStyle();
}

//______________________________________________________________________________
TAttFill::TAttFill(Color_t color, Style_t style)
{
//*-*-*-*-*-*-*-*-*-*-*-*-*AttFill normal constructor*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      ===========================
//*-*    color Fill Color
//*-*    style Fill Style
//*-*
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
   fFillColor = color;
   fFillStyle = style;
}

//______________________________________________________________________________
TAttFill::~TAttFill()
{
//*-*-*-*-*-*-*-*-*-*-*-*-*AttFill destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      =================
}

//______________________________________________________________________________
void TAttFill::Copy(TAttFill &attfill) const
{
//*-*-*-*-*-*-*-*-*Copy this fill attributes to a new attfill*-*-*-*-*-*-*-*-*
//*-*              ==========================================
   attfill.fFillColor  = fFillColor;
   attfill.fFillStyle  = fFillStyle;
}

//______________________________________________________________________________
void TAttFill::Modify()
{
//*-*-*-*-*-*-*-*Change current fill area attributes if necessary*-*-*-*-*-*-*
//*-*            ================================================

   if (!gPad) return;
   if (!gPad->IsBatch()) {
      gVirtualX->SetFillColor(fFillColor);
      gVirtualX->SetFillStyle(fFillStyle);
   }

   gPad->SetAttFillPS(fFillColor,fFillStyle);
}

//______________________________________________________________________________
void TAttFill::ResetAttFill(Option_t *)
{
//*-*-*-*-*-*-*-*-*Reset this fill attributes to default values*-*-*-*-*-*-*
//*-*              ============================================
   fFillColor = 1;
   fFillStyle = 0;
}

//______________________________________________________________________________
void TAttFill::SaveFillAttributes(ostream &out, const char *name, Int_t coldef, Int_t stydef)
{
    // Save fill attributes as C++ statement(s) on output stream out

   if (fFillColor != coldef) {
      if (fFillColor > 228) {
         TColor::SaveColor(out, fFillColor);
         out<<"   "<<name<<"->SetFillColor(ci);" << endl;
      } else
         out<<"   "<<name<<"->SetFillColor("<<fFillColor<<");"<<endl;
   }
   if (fFillStyle != stydef) {
      out<<"   "<<name<<"->SetFillStyle("<<fFillStyle<<");"<<endl;
   }
}

//______________________________________________________________________________
void TAttFill::SetFillAttributes()
{
//*-*-*-*-*-*-*-*-*Invoke the DialogCanvas Fill attributes*-*-*-*-*-*-*
//*-*              =======================================

   //if (gPad) gPad->UpdateFillAttributes(fFillColor,fFillStyle);

   TVirtualPadEditor::UpdateFillAttributes(fFillColor,fFillStyle);
}
<commit_msg>- New documentation.<commit_after>// @(#)root/base:$Name:  $:$Id: TAttFill.cxx,v 1.13 2006/07/03 16:10:43 brun Exp $
// Author: Rene Brun   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TAttFill.h"
#include "TVirtualPad.h"
#include "TStyle.h"
#include "TVirtualX.h"
#include "TVirtualPadEditor.h"
#include "TColor.h"

ClassImp(TAttFill)

//______________________________________________________________________________
/* Begin_Html

Fill Area Attributes class

This class is used (in general by secondary inheritance)
by many other classes (graphics, histograms). It holds all the fill area
attributes.

Fill Area attributes

Fill Area attributes are:

Fill Area color.

Fill Area style.

Fill Area color

The fill area color is a color index (integer) pointing in the ROOT
color table.
The fill area color of any class inheriting from <tt>TAttFill</tt> can
be changed using the method <tt>SetFillColor</tt> and retrieved using the
method <tt>GetFillColor</tt>.
The following table shows the first 50 default colors.
End_Html
Begin_Macro(source)
{
   TCanvas *c = new TCanvas("c","Fill Area colors",0,0,500,200);
   c.DrawColorTable();
   return c;
}
End_Macro

Begin_Html

Fill Area style

The fill area style defines the pattern used to fill a polygon.
The fill area style of any class inheriting from <tt>TAttFill</tt> can
be changed using the method <tt>SetFillStyle</tt> and retrieved using the
method <tt>GetFillStyle</tt>.

Conventions for fill styles:

  0    : hollow

  1001 : Solid

  2001 : hatch style

  3000+pattern_number (see below)

  For TPad only:

  4000 :the window is transparent.

  4000 to 4100 the window is 100% transparent to 100% opaque.

pattern_number can have any value from 1 to 25 (see table), or any
value from 100 to 999. For the latest the numbering convention is the following:

      pattern_number = ijk      (FillStyle = 3ijk)

      i (1-9) : specify the space between each hatch
                1 = 1/2mm  9 = 6mm

      j (0-9) : specify angle between 0 and 90 degrees
                0 = 0
                1 = 10
                2 = 20
                3 = 30
                4 = 45
                5 = Not drawn
                6 = 60
                7 = 70
                8 = 80
                9 = 90

      k (0-9) : specify angle between 90 and 180 degrees
                0 = 180
                1 = 170
                2 = 160
                3 = 150
                4 = 135
                5 = Not drawn
                6 = 120
                7 = 110
                8 = 100
                9 = 90

The following table shows the list of pattern styles.
The first table displays the 25 fixed patterns. They cannot be
customized unlike the hatches displayed in the second table which be
customized using:

 <tt>gStyle->SetHatchesSpacing()</tt> to define the spacing between hatches.

 <tt>gStyle->SetHatchesLineWidth()</tt> to define the hatches line width.

End_Html
Begin_Macro(source)
fillpatterns.C
End_Macro */

//______________________________________________________________________________
TAttFill::TAttFill()
{
   // AttFill default constructor.
   // Default fill attributes are taking from the current style

   if (!gStyle) return;
   fFillColor = gStyle->GetFillColor();
   fFillStyle = gStyle->GetFillStyle();
}

//______________________________________________________________________________
TAttFill::TAttFill(Color_t color, Style_t style)
{
   // AttFill normal constructor.
   // color Fill Color
   // style Fill Style

   fFillColor = color;
   fFillStyle = style;
}

//______________________________________________________________________________
TAttFill::~TAttFill()
{
   // AttFill destructor.
}

//______________________________________________________________________________
void TAttFill::Copy(TAttFill &attfill) const
{
   // Copy this fill attributes to a new TAttFill.

   attfill.fFillColor  = fFillColor;
   attfill.fFillStyle  = fFillStyle;
}

//______________________________________________________________________________
void TAttFill::Modify()
{
   // Change current fill area attributes if necessary.

   if (!gPad) return;
   if (!gPad->IsBatch()) {
      gVirtualX->SetFillColor(fFillColor);
      gVirtualX->SetFillStyle(fFillStyle);
   }

   gPad->SetAttFillPS(fFillColor,fFillStyle);
}

//______________________________________________________________________________
void TAttFill::ResetAttFill(Option_t *)
{
   // Reset this fill attributes to default values.

   fFillColor = 1;
   fFillStyle = 0;
}

//______________________________________________________________________________
void TAttFill::SaveFillAttributes(ostream &out, const char *name, Int_t coldef, Int_t stydef)
{
    // Save fill attributes as C++ statement(s) on output stream out

   if (fFillColor != coldef) {
      if (fFillColor > 228) {
         TColor::SaveColor(out, fFillColor);
         out<<"   "<<name<<"->SetFillColor(ci);" << endl;
      } else
         out<<"   "<<name<<"->SetFillColor("<<fFillColor<<");"<<endl;
   }
   if (fFillStyle != stydef) {
      out<<"   "<<name<<"->SetFillStyle("<<fFillStyle<<");"<<endl;
   }
}

//______________________________________________________________________________
void TAttFill::SetFillAttributes()
{
   // Invoke the DialogCanvas Fill attributes.

   TVirtualPadEditor::UpdateFillAttributes(fFillColor,fFillStyle);
}
<|endoftext|>


<commit_before>// Copyright 2012 Cloudera Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "common/init.h"

#include <gperftools/heap-profiler.h>
#include <gperftools/malloc_extension.h>

#include "common/logging.h"
#include "common/status.h"
#include "exec/kudu-util.h"
#include "exprs/expr.h"
#include "gutil/atomicops.h"
#include "util/cpu-info.h"
#include "util/debug-util.h"
#include "util/decimal-util.h"
#include "util/disk-info.h"
#include "util/logging-support.h"
#include "util/mem-info.h"
#include "util/network-util.h"
#include "util/os-info.h"
#include "util/redactor.h"
#include "util/test-info.h"
#include "runtime/decimal-value.h"
#include "runtime/exec-env.h"
#include "runtime/hdfs-fs-cache.h"
#include "runtime/lib-cache.h"
#include "runtime/mem-tracker.h"
#include "runtime/timestamp-parse-util.h"
#include "rpc/authentication.h"
#include "rpc/thrift-util.h"
#include "util/thread.h"

#include "common/names.h"

DECLARE_string(hostname);
DECLARE_string(redaction_rules_file);
// TODO: renamed this to be more generic when we have a good CM release to do so.
DECLARE_int32(logbufsecs);
DECLARE_string(heap_profile_dir);
DECLARE_bool(enable_process_lifetime_heap_profiling);

DEFINE_int32(max_log_files, 10, "Maximum number of log files to retain per severity "
    "level. The most recent log files are retained. If set to 0, all log files are "
    "retained.");

// Defined by glog. This allows users to specify the log level using a glob. For
// example -vmodule=*scanner*=3 would enable full logging for scanners. If redaction
// is enabled, this option won't be allowed because some logging dumps table data
// in ways the authors of redaction rules can't anticipate.
DECLARE_string(vmodule);

// tcmalloc will hold on to freed memory. We will periodically release the memory back
// to the OS if the extra memory is too high. If the memory used by the application
// is less than this fraction of the total reserved memory, free it back to the OS.
static const float TCMALLOC_RELEASE_FREE_MEMORY_FRACTION = 0.5f;

using std::string;

// Maintenance thread that runs periodically. It does a few things:
// 1) flushes glog every logbufsecs sec. glog flushes the log file only if
//    logbufsecs has passed since the previous flush when a new log is written. That means
//    that on a quiet system, logs will be buffered indefinitely.
// 2) checks that tcmalloc has not left too much memory in its pageheap
shared_ptr<impala::Thread> maintenance_thread;
static void MaintenanceThread() {
  while(true) {
    sleep(FLAGS_logbufsecs);

    google::FlushLogFiles(google::GLOG_INFO);

    // Tests don't need to run the maintenance thread. It causes issues when
    // on teardown.
    if (impala::TestInfo::is_test()) continue;

#ifndef ADDRESS_SANITIZER
    // Required to ensure memory gets released back to the OS, even if tcmalloc doesn't do
    // it for us. This is because tcmalloc releases memory based on the
    // TCMALLOC_RELEASE_RATE property, which is not actually a rate but a divisor based
    // on the number of blocks that have been deleted. When tcmalloc does decide to
    // release memory, it removes a single span from the PageHeap. This means there are
    // certain allocation patterns that can lead to OOM due to not enough memory being
    // released by tcmalloc, even when that memory is no longer being used.
    // One example is continually resizing a vector which results in many allocations.
    // Even after the vector goes out of scope, all the memory will not be released
    // unless there are enough other deletions that are occurring in the system.
    // This can eventually lead to OOM/crashes (see IMPALA-818).
    // See: http://google-perftools.googlecode.com/svn/trunk/doc/tcmalloc.html#runtime
    size_t bytes_used = 0;
    size_t bytes_in_pageheap = 0;
    MallocExtension::instance()->GetNumericProperty(
        "generic.current_allocated_bytes", &bytes_used);
    MallocExtension::instance()->GetNumericProperty(
        "generic.heap_size", &bytes_in_pageheap);
    if (bytes_used < bytes_in_pageheap * TCMALLOC_RELEASE_FREE_MEMORY_FRACTION) {
      MallocExtension::instance()->ReleaseFreeMemory();
    }

    // When using tcmalloc, the process limit as measured by our trackers will
    // be out of sync with the process usage. Update the process tracker periodically.
    impala::ExecEnv* env = impala::ExecEnv::GetInstance();
    if (env != NULL && env->process_mem_tracker() != NULL) {
      env->process_mem_tracker()->RefreshConsumptionFromMetric();
    }
#endif
    // TODO: we should also update the process mem tracker with the reported JVM
    // mem usage.

    // Check for log rotation in every interval of the maintenance thread
    impala::CheckAndRotateLogFiles(FLAGS_max_log_files);
  }
}

void impala::InitCommonRuntime(int argc, char** argv, bool init_jvm,
    TestInfo::Mode test_mode) {
  CpuInfo::Init();
  DiskInfo::Init();
  MemInfo::Init();
  OsInfo::Init();
  DecimalUtil::InitMaxUnscaledDecimal16();
  TestInfo::Init(test_mode);

  // Verify CPU meets the minimum requirements before calling InitGoogleLoggingSafe()
  // which might use SSSE3 instructions (see IMPALA-160).
  CpuInfo::VerifyCpuRequirements();

  // Set the default hostname. The user can override this with the hostname flag.
  GetHostname(&FLAGS_hostname);

  google::SetVersionString(impala::GetBuildVersion());
  google::ParseCommandLineFlags(&argc, &argv, true);
  if (!FLAGS_redaction_rules_file.empty()) {
    if (VLOG_ROW_IS_ON || !FLAGS_vmodule.empty()) {
      EXIT_WITH_ERROR("Redaction cannot be used in combination with log level 3 or "
          "higher or the -vmodule option because these log levels may log data in "
          "ways redaction rules may not anticipate.");
    }
    const string& error_message = SetRedactionRulesFromFile(FLAGS_redaction_rules_file);
    if (!error_message.empty()) EXIT_WITH_ERROR(error_message);
  }
  impala::InitGoogleLoggingSafe(argv[0]);
  AtomicOps_x86CPUFeaturesInit();
  impala::InitThreading();
  impala::TimestampParser::Init();
  EXIT_IF_ERROR(impala::InitAuth(argv[0]));

  // Initialize maintenance_thread after InitGoogleLoggingSafe and InitThreading.
  maintenance_thread.reset(
      new Thread("common", "maintenance-thread", &MaintenanceThread));

  LOG(INFO) << impala::GetVersionString();
  LOG(INFO) << "Using hostname: " << FLAGS_hostname;
  impala::LogCommandLineFlags();

  InitThriftLogging();

  LOG(INFO) << CpuInfo::DebugString();
  LOG(INFO) << DiskInfo::DebugString();
  LOG(INFO) << MemInfo::DebugString();
  LOG(INFO) << OsInfo::DebugString();
  LOG(INFO) << "Process ID: " << getpid();

  // Required for the FE's Catalog
  impala::LibCache::Init();
  impala::HdfsFsCache::Init();

  if (init_jvm) {
    EXIT_IF_ERROR(JniUtil::Init());
    InitJvmLoggingSupport();
  }

  if (argc == -1) {
    // Should not be called. We need BuiltinsInit() so the builtin symbols are
    // not stripped.
    DCHECK(false);
    Expr::InitBuiltinsDummy();
  }

  impala::InitKuduLogging();

#ifndef ADDRESS_SANITIZER
  // tcmalloc and address sanitizer can not be used together
  if (FLAGS_enable_process_lifetime_heap_profiling) {
    HeapProfilerStart(FLAGS_heap_profile_dir.c_str());
  }
#endif
}
<commit_msg>IMPALA-3114: Add a pause monitor for impala processes.<commit_after>// Copyright 2012 Cloudera Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "common/init.h"

#include <gperftools/heap-profiler.h>
#include <gperftools/malloc_extension.h>

#include "common/logging.h"
#include "common/status.h"
#include "exec/kudu-util.h"
#include "exprs/expr.h"
#include "gutil/atomicops.h"
#include "util/cpu-info.h"
#include "util/debug-util.h"
#include "util/decimal-util.h"
#include "util/disk-info.h"
#include "util/logging-support.h"
#include "util/mem-info.h"
#include "util/network-util.h"
#include "util/os-info.h"
#include "util/pretty-printer.h"
#include "util/redactor.h"
#include "util/test-info.h"
#include "util/thread.h"
#include "util/time.h"
#include "runtime/decimal-value.h"
#include "runtime/exec-env.h"
#include "runtime/hdfs-fs-cache.h"
#include "runtime/lib-cache.h"
#include "runtime/mem-tracker.h"
#include "runtime/timestamp-parse-util.h"
#include "rpc/authentication.h"
#include "rpc/thrift-util.h"

#include "common/names.h"

using namespace impala;

DECLARE_string(hostname);
DECLARE_string(redaction_rules_file);
// TODO: renamed this to be more generic when we have a good CM release to do so.
DECLARE_int32(logbufsecs);
DECLARE_string(heap_profile_dir);
DECLARE_bool(enable_process_lifetime_heap_profiling);

DEFINE_int32(max_log_files, 10, "Maximum number of log files to retain per severity "
    "level. The most recent log files are retained. If set to 0, all log files are "
    "retained.");

DEFINE_int64(pause_monitor_sleep_time_ms, 500, "Sleep time in milliseconds for "
    "pause monitor thread.");

DEFINE_int64(pause_monitor_warn_threshold_ms, 10000, "If the pause monitor sleeps "
    "more than this time period, a warning is logged. If set to 0 or less, pause monitor"
    " is disabled.");

// Defined by glog. This allows users to specify the log level using a glob. For
// example -vmodule=*scanner*=3 would enable full logging for scanners. If redaction
// is enabled, this option won't be allowed because some logging dumps table data
// in ways the authors of redaction rules can't anticipate.
DECLARE_string(vmodule);

// tcmalloc will hold on to freed memory. We will periodically release the memory back
// to the OS if the extra memory is too high. If the memory used by the application
// is less than this fraction of the total reserved memory, free it back to the OS.
static const float TCMALLOC_RELEASE_FREE_MEMORY_FRACTION = 0.5f;

using std::string;

// Maintenance thread that runs periodically. It does a few things:
// 1) flushes glog every logbufsecs sec. glog flushes the log file only if
//    logbufsecs has passed since the previous flush when a new log is written. That means
//    that on a quiet system, logs will be buffered indefinitely.
// 2) checks that tcmalloc has not left too much memory in its pageheap
static scoped_ptr<impala::Thread> maintenance_thread;

// A pause monitor thread to monitor process pauses in impala daemons. The thread sleeps
// for a short interval of time (THREAD_SLEEP_TIME_MS), wakes up and calculates the actual
// time slept. If that exceeds PAUSE_WARN_THRESHOLD_MS, a warning is logged.
static scoped_ptr<impala::Thread> pause_monitor;

static void MaintenanceThread() {
  while (true) {
    sleep(FLAGS_logbufsecs);

    google::FlushLogFiles(google::GLOG_INFO);

    // Tests don't need to run the maintenance thread. It causes issues when
    // on teardown.
    if (impala::TestInfo::is_test()) continue;

#ifndef ADDRESS_SANITIZER
    // Required to ensure memory gets released back to the OS, even if tcmalloc doesn't do
    // it for us. This is because tcmalloc releases memory based on the
    // TCMALLOC_RELEASE_RATE property, which is not actually a rate but a divisor based
    // on the number of blocks that have been deleted. When tcmalloc does decide to
    // release memory, it removes a single span from the PageHeap. This means there are
    // certain allocation patterns that can lead to OOM due to not enough memory being
    // released by tcmalloc, even when that memory is no longer being used.
    // One example is continually resizing a vector which results in many allocations.
    // Even after the vector goes out of scope, all the memory will not be released
    // unless there are enough other deletions that are occurring in the system.
    // This can eventually lead to OOM/crashes (see IMPALA-818).
    // See: http://google-perftools.googlecode.com/svn/trunk/doc/tcmalloc.html#runtime
    size_t bytes_used = 0;
    size_t bytes_in_pageheap = 0;
    MallocExtension::instance()->GetNumericProperty(
        "generic.current_allocated_bytes", &bytes_used);
    MallocExtension::instance()->GetNumericProperty(
        "generic.heap_size", &bytes_in_pageheap);
    if (bytes_used < bytes_in_pageheap * TCMALLOC_RELEASE_FREE_MEMORY_FRACTION) {
      MallocExtension::instance()->ReleaseFreeMemory();
    }

    // When using tcmalloc, the process limit as measured by our trackers will
    // be out of sync with the process usage. Update the process tracker periodically.
    impala::ExecEnv* env = impala::ExecEnv::GetInstance();
    if (env != NULL && env->process_mem_tracker() != NULL) {
      env->process_mem_tracker()->RefreshConsumptionFromMetric();
    }
#endif
    // TODO: we should also update the process mem tracker with the reported JVM
    // mem usage.

    // Check for log rotation in every interval of the maintenance thread
    impala::CheckAndRotateLogFiles(FLAGS_max_log_files);
  }
}

static void PauseMonitorLoop() {
  if (FLAGS_pause_monitor_warn_threshold_ms <= 0) return;
  int64_t time_before_sleep = MonotonicMillis();
  while (true) {
    SleepForMs(FLAGS_pause_monitor_sleep_time_ms);
    int64_t sleep_time = MonotonicMillis() - time_before_sleep;
    time_before_sleep += sleep_time;
    if (sleep_time > FLAGS_pause_monitor_warn_threshold_ms) {
      LOG(WARNING) << "A process pause was detected for approximately " <<
          PrettyPrinter::Print(sleep_time, TUnit::TIME_MS);
    }
  }
}

void impala::InitCommonRuntime(int argc, char** argv, bool init_jvm,
    TestInfo::Mode test_mode) {
  CpuInfo::Init();
  DiskInfo::Init();
  MemInfo::Init();
  OsInfo::Init();
  DecimalUtil::InitMaxUnscaledDecimal16();
  TestInfo::Init(test_mode);

  // Verify CPU meets the minimum requirements before calling InitGoogleLoggingSafe()
  // which might use SSSE3 instructions (see IMPALA-160).
  CpuInfo::VerifyCpuRequirements();

  // Set the default hostname. The user can override this with the hostname flag.
  GetHostname(&FLAGS_hostname);

  google::SetVersionString(impala::GetBuildVersion());
  google::ParseCommandLineFlags(&argc, &argv, true);
  if (!FLAGS_redaction_rules_file.empty()) {
    if (VLOG_ROW_IS_ON || !FLAGS_vmodule.empty()) {
      EXIT_WITH_ERROR("Redaction cannot be used in combination with log level 3 or "
          "higher or the -vmodule option because these log levels may log data in "
          "ways redaction rules may not anticipate.");
    }
    const string& error_message = SetRedactionRulesFromFile(FLAGS_redaction_rules_file);
    if (!error_message.empty()) EXIT_WITH_ERROR(error_message);
  }
  impala::InitGoogleLoggingSafe(argv[0]);
  AtomicOps_x86CPUFeaturesInit();
  impala::InitThreading();
  impala::TimestampParser::Init();
  EXIT_IF_ERROR(impala::InitAuth(argv[0]));

  // Initialize maintenance_thread after InitGoogleLoggingSafe and InitThreading.
  maintenance_thread.reset(
      new Thread("common", "maintenance-thread", &MaintenanceThread));

  pause_monitor.reset(
      new Thread("common", "pause-monitor", &PauseMonitorLoop));

  LOG(INFO) << impala::GetVersionString();
  LOG(INFO) << "Using hostname: " << FLAGS_hostname;
  impala::LogCommandLineFlags();

  InitThriftLogging();

  LOG(INFO) << CpuInfo::DebugString();
  LOG(INFO) << DiskInfo::DebugString();
  LOG(INFO) << MemInfo::DebugString();
  LOG(INFO) << OsInfo::DebugString();
  LOG(INFO) << "Process ID: " << getpid();

  // Required for the FE's Catalog
  impala::LibCache::Init();
  impala::HdfsFsCache::Init();

  if (init_jvm) {
    EXIT_IF_ERROR(JniUtil::Init());
    InitJvmLoggingSupport();
  }

  if (argc == -1) {
    // Should not be called. We need BuiltinsInit() so the builtin symbols are
    // not stripped.
    DCHECK(false);
    Expr::InitBuiltinsDummy();
  }

  impala::InitKuduLogging();

#ifndef ADDRESS_SANITIZER
  // tcmalloc and address sanitizer can not be used together
  if (FLAGS_enable_process_lifetime_heap_profiling) {
    HeapProfilerStart(FLAGS_heap_profile_dir.c_str());
  }
#endif
}
<|endoftext|>


<commit_before>/*!
@file

@copyright Edouard Alligand and Joel Falcou 2015-2017
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_BRIGAND_FUNCTIONS_MISC_ALWAYS_HPP
#define BOOST_BRIGAND_FUNCTIONS_MISC_ALWAYS_HPP

namespace brigand
{
  template<class T>
  struct always
  {
     using type = T;
  };
}
#endif
<commit_msg>Delete always.hpp<commit_after><|endoftext|>


<commit_before>struct State {
    bool begun;
};

{{ GENERATED_CODE }}

void evaluate(NodeId nid, State* state) {
    if (!isInputDirty<Inputs::DUMP>(nid))
        return;

    if (!state->begun) {
        Serial.begin(9600);
    }

    auto line = getValue<Inputs::LINE>(nid);
    if (line) {
        for (auto it = line->iterate(); it; ++it)
            Serial.write((char)*it);
        Serial.write('\n');
        Serial.flush();
    }
}
<commit_msg>fix(workspace): add CR at EOL of Arduino’s console-log node<commit_after>struct State {
    bool begun;
};

{{ GENERATED_CODE }}

void evaluate(NodeId nid, State* state) {
    if (!isInputDirty<Inputs::DUMP>(nid))
        return;

    if (!state->begun) {
        Serial.begin(9600);
    }

    auto line = getValue<Inputs::LINE>(nid);
    if (line) {
        for (auto it = line->iterate(); it; ++it)
            Serial.write((char)*it);
        Serial.write('\r');
        Serial.write('\n');
        Serial.flush();
    }
}
<|endoftext|>


<commit_before>#include "board_graph.hpp"
#include "exception.hpp"

namespace Quoridor {

FilterEdges::FilterEdges() : edges_()
{
}

FilterEdges::~FilterEdges()
{
}

void FilterEdges::add_edge(const edge_descriptor &e)
{
    edges_.insert(e);
}

void FilterEdges::clear()
{
    edges_.clear();
}

template <typename EdgeDesc>
bool FilterEdges::operator()(const EdgeDesc &e) const
{
    return edges_.find(e) == edges_.end();
}

template <class Vertex>
astar_goal_visitor<Vertex>::astar_goal_visitor(Vertex goal) : m_goal(goal)
{
}

template <class Vertex>
template <class Graph>
void astar_goal_visitor<Vertex>::examine_vertex(Vertex u, Graph & /* g */)
{
    if (u == m_goal) {
        throw found_goal();
    }
}

BoardGraph::BoardGraph(int row_num, int col_num)
    : g_(), row_num_(row_num), col_num_(col_num), fe_()
{
    if ((row_num <= 0) || (col_num <= 0)) {
        throw Exception("invalid size");
    }

    g_ = graph_t(row_num_ * col_num_);

    std::vector<std::pair<int, int>> edges;
    int idx;
    int nidx;
    for (int i = 0; i < row_num; ++i) {
        for (int j = 0; j < col_num; ++j) {
            idx = i * col_num + j;
            if (j != 0) {
                nidx = i * col_num + j - 1;
                edges.push_back(std::pair<int, int>(idx, nidx));
            }
            if (j != col_num - 1) {
                nidx = i * col_num + j + 1;
                edges.push_back(std::pair<int, int>(idx, nidx));
            }
            if (i != 0) {
                nidx = (i - 1) * col_num + j;
                edges.push_back(std::pair<int, int>(idx, nidx));
            }
            if (i != row_num - 1) {
                nidx = (i + 1) * col_num + j;
                edges.push_back(std::pair<int, int>(idx, nidx));
            }
        }
    }

    WeightMap weightmap = boost::get(boost::edge_weight, g_);
    edge_descriptor e;
    bool b;
    for (auto &it : edges) {
        boost::tie(e, b) = boost::add_edge(it.first, it.second, g_);
        weightmap[e] = 1;
    }
}

BoardGraph::~BoardGraph()
{
}

void BoardGraph::remove_edges(const Node &node1, const Node &node2)
{
    int inode1 = node1.row() * col_num_ + node1.col();
    int inode2 = node2.row() * col_num_ + node2.col();
    edge_descriptor ed;
    bool b;

    boost::tie(ed, b) = boost::edge(inode1, inode2, g_);
    if (b) {
        g_.remove_edge(ed);
    }

    boost::tie(ed, b) = boost::edge(inode2, inode1, g_);
    if (b) {
        g_.remove_edge(ed);
    }
}

void BoardGraph::block_neighbours(const Node &node)
{
    int inode = node.row() * col_num_ + node.col();
    int nf = 0;
    std::map<int, int> neighbours;

    if (is_neighbours(inode, inode - 1)) {
        block_edge(inode - 1, inode);
        nf |= 1;
        neighbours[0] = inode - 1;
    }
    if (is_neighbours(inode, inode + 1)) {
        block_edge(inode + 1, inode);
        nf |= 4;
        neighbours[2] = inode + 1;
    }
    if (is_neighbours(inode, inode - col_num_)) {
        block_edge(inode - col_num_, inode);
        nf |= 2;
        neighbours[1] = inode - col_num_;
    }
    if (is_neighbours(inode, inode + col_num_)) {
        block_edge(inode + col_num_, inode);
        nf |= 8;
        neighbours[3] = inode + col_num_;
    }

    // link neighbours with each other
    for (int i = 0; i < 4; ++i) {
        if (nf & (1 << i)) {
            // path to the opposite node is open
            if (nf & (1 << ((i + 2) % 4))) {
                unblock_edge(neighbours[i], neighbours[(i + 2) % 4]);
            }
            // path to the opposite node is blocked, open pathes to diagonal nodes
            else {
                if (nf & (1 << ((i + 1) % 4))) {
                    unblock_edge(neighbours[i], neighbours[(i + 1) % 4]);
                }
                if (nf & (1 << ((i + 3) % 4))) {
                    unblock_edge(neighbours[i], neighbours[(i + 3) % 4]);
                }
            }
        }
    }
}

void BoardGraph::unblock_neighbours(const Node &node)
{
    int inode = node.row() * col_num_ + node.col();
    int nf = 0;
    std::map<int, int> neighbours;

    if (is_neighbours(inode, inode - 1)) {
        unblock_edge(inode - 1, inode);
        nf |= 1;
        neighbours[0] = inode - 1;
    }
    if (is_neighbours(inode, inode + 1)) {
        unblock_edge(inode + 1, inode);
        nf |= 4;
        neighbours[2] = inode + 1;
    }
    if (is_neighbours(inode, inode - col_num_)) {
        unblock_edge(inode - col_num_, inode);
        nf |= 2;
        neighbours[1] = inode - col_num_;
    }
    if (is_neighbours(inode, inode + col_num_)) {
        unblock_edge(inode + col_num_, inode);
        nf |= 8;
        neighbours[3] = inode + col_num_;
    }

    // close links between node's neighbours
    for (int i = 0; i < 4; ++i) {
        if (nf & (1 << i)) {
            // path to the opposite node is open
            if (nf & (1 << ((i + 2) % 4))) {
                block_edge(neighbours[i], neighbours[(i + 2) % 4]);
            }
            // path to the opposite node is blocked, open pathes to diagonal nodes
            else {
                if (nf & (1 << ((i + 1) % 4))) {
                    block_edge(neighbours[i], neighbours[(i + 1) % 4]);
                }
                if (nf & (1 << ((i + 3) % 4))) {
                    block_edge(neighbours[i], neighbours[(i + 3) % 4]);
                }
            }
        }
    }
}

void BoardGraph::get_neighbours(const Node &node,
        std::set<Node> *node_list) const
{
    IndexMap index = get(boost::vertex_index, g_);
    int inode = node.row() * col_num_ + node.col();
    Node neighbour_node;

    std::pair<adjacency_iterator, adjacency_iterator> neighbours =
        boost::adjacent_vertices(boost::vertex(inode, g_), g_);
    for (; neighbours.first != neighbours.second; ++ neighbours.first) {
        neighbour_node.set_row((int) index[*neighbours.first] / row_num_);
        neighbour_node.set_col((int) index[*neighbours.first] % col_num_);
        node_list->insert(neighbour_node);
    }
}

bool BoardGraph::find_path(const Node &start_node, const Node &end_node,
        std::list<Node> *path) const
{
    int start_inode = start_node.row() * col_num_ + start_node.col();
    int end_inode = end_node.row() * col_num_ + end_node.col();

    std::vector<vertex_descriptor> p(boost::num_vertices(g_));
    std::vector<int> d(boost::num_vertices(g_));

    vertex_descriptor start = boost::vertex(start_inode, g_);
    vertex_descriptor end = boost::vertex(end_inode, g_);

    Node node;

    try {
        astar_search(g_, start, boost::astar_heuristic<graph_t, int>(),
                boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(astar_goal_visitor<vertex_descriptor>(end)));
    }
    catch (found_goal fg) {
        for (vertex_descriptor v = end_inode;; v = p[v]) {
            if (p[v] == v)
                break;
            node = Node(v / col_num_, v % col_num_);
            path->push_front(node);
        }
        return true;
    }

    return false;
}

bool BoardGraph::is_adjacent(const Node &node1, const Node &node2) const
{
    int inode1 = node1.row() * col_num_ + node1.col();
    int inode2 = node2.row() * col_num_ + node2.col();
    edge_descriptor e;
    bool b;
    boost::tie(e, b) = boost::edge(inode1, inode2, g_);
    return b;
}

void BoardGraph::filter_edges(const Node &node1, const Node &node2)
{
    int inode1 = node1.row() * col_num_ + node1.col();
    int inode2 = node2.row() * col_num_ + node2.col();
    edge_descriptor ed;
    bool b;

    boost::tie(ed, b) = boost::edge(inode1, inode2, g_);
    if (b) {
        fe_.add_edge(ed);
    }

    boost::tie(ed, b) = boost::edge(inode2, inode1, g_);
    if (b) {
        fe_.add_edge(ed);
    }
}

void BoardGraph::reset_filters()
{
    fe_.clear();
}

bool BoardGraph::is_path_exists(const Node &start_node, const Node &end_node) const
{
    int start_inode = start_node.row() * col_num_ + start_node.col();
    int end_inode = end_node.row() * col_num_ + end_node.col();

    boost::filtered_graph<graph_t, FilterEdges> fg(g_, fe_);

    std::vector<boost::filtered_graph<graph_t, FilterEdges>::vertex_descriptor> p(boost::num_vertices(fg));
    std::vector<int> d(boost::num_vertices(fg));

    boost::filtered_graph<graph_t, FilterEdges>::vertex_descriptor start = boost::vertex(start_inode, g_);
    boost::filtered_graph<graph_t, FilterEdges>::vertex_descriptor end = boost::vertex(end_inode, g_);

    try {
        astar_search(fg, start, boost::astar_heuristic<boost::filtered_graph<graph_t, FilterEdges>, int>(),
                boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(astar_goal_visitor<vertex_descriptor>(end)));
    }
    catch (found_goal fg) {
        return true;
    }

    return false;
}

bool BoardGraph::is_neighbours(int inode1, int inode2) const
{
    edge_descriptor e;
    bool b;
    boost::tie(e, b) = boost::edge(inode1, inode2, g_);
    return b;
}

void BoardGraph::block_edge(int inode1, int inode2)
{
    edge_descriptor ed;
    bool b;

    boost::tie(ed, b) = boost::edge(inode1, inode2, g_);
    if (b) {
        g_.remove_edge(ed);
    }
}

void BoardGraph::unblock_edge(int inode1, int inode2)
{
    WeightMap weightmap = boost::get(boost::edge_weight, g_);
    edge_descriptor e;
    bool b;

    boost::tie(e, b) = boost::add_edge(inode1, inode2, g_);
    weightmap[e] = 1;
}

}  /* namespace Quoridor */
<commit_msg>Simplify method BoardGraph::get_neighbours<commit_after>#include "board_graph.hpp"
#include "exception.hpp"

namespace Quoridor {

FilterEdges::FilterEdges() : edges_()
{
}

FilterEdges::~FilterEdges()
{
}

void FilterEdges::add_edge(const edge_descriptor &e)
{
    edges_.insert(e);
}

void FilterEdges::clear()
{
    edges_.clear();
}

template <typename EdgeDesc>
bool FilterEdges::operator()(const EdgeDesc &e) const
{
    return edges_.find(e) == edges_.end();
}

template <class Vertex>
astar_goal_visitor<Vertex>::astar_goal_visitor(Vertex goal) : m_goal(goal)
{
}

template <class Vertex>
template <class Graph>
void astar_goal_visitor<Vertex>::examine_vertex(Vertex u, Graph & /* g */)
{
    if (u == m_goal) {
        throw found_goal();
    }
}

BoardGraph::BoardGraph(int row_num, int col_num)
    : g_(), row_num_(row_num), col_num_(col_num), fe_()
{
    if ((row_num <= 0) || (col_num <= 0)) {
        throw Exception("invalid size");
    }

    g_ = graph_t(row_num_ * col_num_);

    std::vector<std::pair<int, int>> edges;
    int idx;
    int nidx;
    for (int i = 0; i < row_num; ++i) {
        for (int j = 0; j < col_num; ++j) {
            idx = i * col_num + j;
            if (j != 0) {
                nidx = i * col_num + j - 1;
                edges.push_back(std::pair<int, int>(idx, nidx));
            }
            if (j != col_num - 1) {
                nidx = i * col_num + j + 1;
                edges.push_back(std::pair<int, int>(idx, nidx));
            }
            if (i != 0) {
                nidx = (i - 1) * col_num + j;
                edges.push_back(std::pair<int, int>(idx, nidx));
            }
            if (i != row_num - 1) {
                nidx = (i + 1) * col_num + j;
                edges.push_back(std::pair<int, int>(idx, nidx));
            }
        }
    }

    WeightMap weightmap = boost::get(boost::edge_weight, g_);
    edge_descriptor e;
    bool b;
    for (auto &it : edges) {
        boost::tie(e, b) = boost::add_edge(it.first, it.second, g_);
        weightmap[e] = 1;
    }
}

BoardGraph::~BoardGraph()
{
}

void BoardGraph::remove_edges(const Node &node1, const Node &node2)
{
    int inode1 = node1.row() * col_num_ + node1.col();
    int inode2 = node2.row() * col_num_ + node2.col();
    edge_descriptor ed;
    bool b;

    boost::tie(ed, b) = boost::edge(inode1, inode2, g_);
    if (b) {
        g_.remove_edge(ed);
    }

    boost::tie(ed, b) = boost::edge(inode2, inode1, g_);
    if (b) {
        g_.remove_edge(ed);
    }
}

void BoardGraph::block_neighbours(const Node &node)
{
    int inode = node.row() * col_num_ + node.col();
    int nf = 0;
    std::map<int, int> neighbours;

    if (is_neighbours(inode, inode - 1)) {
        block_edge(inode - 1, inode);
        nf |= 1;
        neighbours[0] = inode - 1;
    }
    if (is_neighbours(inode, inode + 1)) {
        block_edge(inode + 1, inode);
        nf |= 4;
        neighbours[2] = inode + 1;
    }
    if (is_neighbours(inode, inode - col_num_)) {
        block_edge(inode - col_num_, inode);
        nf |= 2;
        neighbours[1] = inode - col_num_;
    }
    if (is_neighbours(inode, inode + col_num_)) {
        block_edge(inode + col_num_, inode);
        nf |= 8;
        neighbours[3] = inode + col_num_;
    }

    // link neighbours with each other
    for (int i = 0; i < 4; ++i) {
        if (nf & (1 << i)) {
            // path to the opposite node is open
            if (nf & (1 << ((i + 2) % 4))) {
                unblock_edge(neighbours[i], neighbours[(i + 2) % 4]);
            }
            // path to the opposite node is blocked, open pathes to diagonal nodes
            else {
                if (nf & (1 << ((i + 1) % 4))) {
                    unblock_edge(neighbours[i], neighbours[(i + 1) % 4]);
                }
                if (nf & (1 << ((i + 3) % 4))) {
                    unblock_edge(neighbours[i], neighbours[(i + 3) % 4]);
                }
            }
        }
    }
}

void BoardGraph::unblock_neighbours(const Node &node)
{
    int inode = node.row() * col_num_ + node.col();
    int nf = 0;
    std::map<int, int> neighbours;

    if (is_neighbours(inode, inode - 1)) {
        unblock_edge(inode - 1, inode);
        nf |= 1;
        neighbours[0] = inode - 1;
    }
    if (is_neighbours(inode, inode + 1)) {
        unblock_edge(inode + 1, inode);
        nf |= 4;
        neighbours[2] = inode + 1;
    }
    if (is_neighbours(inode, inode - col_num_)) {
        unblock_edge(inode - col_num_, inode);
        nf |= 2;
        neighbours[1] = inode - col_num_;
    }
    if (is_neighbours(inode, inode + col_num_)) {
        unblock_edge(inode + col_num_, inode);
        nf |= 8;
        neighbours[3] = inode + col_num_;
    }

    // close links between node's neighbours
    for (int i = 0; i < 4; ++i) {
        if (nf & (1 << i)) {
            // path to the opposite node is open
            if (nf & (1 << ((i + 2) % 4))) {
                block_edge(neighbours[i], neighbours[(i + 2) % 4]);
            }
            // path to the opposite node is blocked, open pathes to diagonal nodes
            else {
                if (nf & (1 << ((i + 1) % 4))) {
                    block_edge(neighbours[i], neighbours[(i + 1) % 4]);
                }
                if (nf & (1 << ((i + 3) % 4))) {
                    block_edge(neighbours[i], neighbours[(i + 3) % 4]);
                }
            }
        }
    }
}

void BoardGraph::get_neighbours(const Node &node,
        std::set<Node> *node_list) const
{
    IndexMap index = get(boost::vertex_index, g_);
    int inode = node.row() * col_num_ + node.col();
    vertex_descriptor v = boost::vertex(inode, g_);
    Node neighbour_node;

    adjacency_iterator it;
    adjacency_iterator it_end;
    for (boost::tie(it, it_end) = boost::adjacent_vertices(v, g_);
            it != it_end; ++ it) {
        neighbour_node.set_row(index[*it] / row_num_);
        neighbour_node.set_col(index[*it] % col_num_);
        node_list->insert(neighbour_node);
    }
}

bool BoardGraph::find_path(const Node &start_node, const Node &end_node,
        std::list<Node> *path) const
{
    int start_inode = start_node.row() * col_num_ + start_node.col();
    int end_inode = end_node.row() * col_num_ + end_node.col();

    std::vector<vertex_descriptor> p(boost::num_vertices(g_));
    std::vector<int> d(boost::num_vertices(g_));

    vertex_descriptor start = boost::vertex(start_inode, g_);
    vertex_descriptor end = boost::vertex(end_inode, g_);

    Node node;

    try {
        astar_search(g_, start, boost::astar_heuristic<graph_t, int>(),
                boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(astar_goal_visitor<vertex_descriptor>(end)));
    }
    catch (found_goal fg) {
        for (vertex_descriptor v = end_inode;; v = p[v]) {
            if (p[v] == v)
                break;
            node = Node(v / col_num_, v % col_num_);
            path->push_front(node);
        }
        return true;
    }

    return false;
}

bool BoardGraph::is_adjacent(const Node &node1, const Node &node2) const
{
    int inode1 = node1.row() * col_num_ + node1.col();
    int inode2 = node2.row() * col_num_ + node2.col();
    edge_descriptor e;
    bool b;
    boost::tie(e, b) = boost::edge(inode1, inode2, g_);
    return b;
}

void BoardGraph::filter_edges(const Node &node1, const Node &node2)
{
    int inode1 = node1.row() * col_num_ + node1.col();
    int inode2 = node2.row() * col_num_ + node2.col();
    edge_descriptor ed;
    bool b;

    boost::tie(ed, b) = boost::edge(inode1, inode2, g_);
    if (b) {
        fe_.add_edge(ed);
    }

    boost::tie(ed, b) = boost::edge(inode2, inode1, g_);
    if (b) {
        fe_.add_edge(ed);
    }
}

void BoardGraph::reset_filters()
{
    fe_.clear();
}

bool BoardGraph::is_path_exists(const Node &start_node, const Node &end_node) const
{
    int start_inode = start_node.row() * col_num_ + start_node.col();
    int end_inode = end_node.row() * col_num_ + end_node.col();

    boost::filtered_graph<graph_t, FilterEdges> fg(g_, fe_);

    std::vector<boost::filtered_graph<graph_t, FilterEdges>::vertex_descriptor> p(boost::num_vertices(fg));
    std::vector<int> d(boost::num_vertices(fg));

    boost::filtered_graph<graph_t, FilterEdges>::vertex_descriptor start = boost::vertex(start_inode, g_);
    boost::filtered_graph<graph_t, FilterEdges>::vertex_descriptor end = boost::vertex(end_inode, g_);

    try {
        astar_search(fg, start, boost::astar_heuristic<boost::filtered_graph<graph_t, FilterEdges>, int>(),
                boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(astar_goal_visitor<vertex_descriptor>(end)));
    }
    catch (found_goal fg) {
        return true;
    }

    return false;
}

bool BoardGraph::is_neighbours(int inode1, int inode2) const
{
    edge_descriptor e;
    bool b;
    boost::tie(e, b) = boost::edge(inode1, inode2, g_);
    return b;
}

void BoardGraph::block_edge(int inode1, int inode2)
{
    edge_descriptor ed;
    bool b;

    boost::tie(ed, b) = boost::edge(inode1, inode2, g_);
    if (b) {
        g_.remove_edge(ed);
    }
}

void BoardGraph::unblock_edge(int inode1, int inode2)
{
    WeightMap weightmap = boost::get(boost::edge_weight, g_);
    edge_descriptor e;
    bool b;

    boost::tie(e, b) = boost::add_edge(inode1, inode2, g_);
    weightmap[e] = 1;
}

}  /* namespace Quoridor */
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: TransformerContext.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: hr $ $Date: 2007-06-27 16:26:05 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _XMLOFF_TRANSFORMERCONTEXT_HXX
#define _XMLOFF_TRANSFORMERCONTEXT_HXX

#ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HPP_
#include <com/sun/star/xml/sax/XAttributeList.hpp>
#endif

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#ifndef _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
#include <salhelper/simplereferenceobject.hxx>
#endif
#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif
#ifndef _RTTI_HXX
#include <tools/rtti.hxx>
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include <xmloff/xmltoken.hxx>
#endif

class SvXMLNamespaceMap;
class XMLTransformerBase;

class XMLTransformerContext : public ::salhelper::SimpleReferenceObject
{
    friend class XMLTransformerBase;

    XMLTransformerBase& m_rTransformer;

    ::rtl::OUString m_aQName;

    SvXMLNamespaceMap   *m_pRewindMap;

    SvXMLNamespaceMap  *GetRewindMap() const { return m_pRewindMap; }
    void SetRewindMap( SvXMLNamespaceMap *p ) { m_pRewindMap = p; }

protected:

    XMLTransformerBase& GetTransformer() { return m_rTransformer; }
    const XMLTransformerBase& GetTransformer() const { return m_rTransformer; }

    void SetQName( const ::rtl::OUString& rQName ) { m_aQName = rQName; }

public:
    TYPEINFO();

    const ::rtl::OUString& GetQName() const { return m_aQName; }
    sal_Bool HasQName( sal_uInt16 nPrefix,
                       ::xmloff::token::XMLTokenEnum eToken ) const;
    sal_Bool HasNamespace( sal_uInt16 nPrefix ) const;

    // A contexts constructor does anything that is required if an element
    // starts. Namespace processing has been done already.
    // Note that virtual methods cannot be used inside constructors. Use
    // StartElement instead if this is required.
    XMLTransformerContext( XMLTransformerBase& rTransformer,
                        const ::rtl::OUString& rQName );

    // A contexts destructor does anything that is required if an element
    // ends. By default, nothing is done.
    // Note that virtual methods cannot be used inside destructors. Use
    // EndElement instead if this is required.
    virtual ~XMLTransformerContext();

    // Create a childs element context. By default, the import's
    // CreateContext method is called to create a new default context.
    virtual XMLTransformerContext *CreateChildContext( sal_uInt16 nPrefix,
                                   const ::rtl::OUString& rLocalName,
                                   const ::rtl::OUString& rQName,
                                   const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );

    // StartElement is called after a context has been constructed and
    // before a elements context is parsed. It may be used for actions that
    // require virtual methods. The default is to do nothing.
    virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );

    // EndElement is called before a context will be destructed, but
    // after a elements context has been parsed. It may be used for actions
    // that require virtual methods. The default is to do nothing.
    virtual void EndElement();

    // This method is called for all characters that are contained in the
    // current element. The default is to ignore them.
    virtual void Characters( const ::rtl::OUString& rChars );

    // Is the current context a persistent one (i.e. one that saves is content
    // rather than exporting it directly?
    virtual sal_Bool IsPersistent() const;

    // Export the whole element. By default, nothing is done here
    virtual void Export();

    // Export the element content. By default, nothing is done here
    virtual void ExportContent();
};

#endif  //  _XMLOFF_TRANSFORMERCONTEXT_HXX

<commit_msg>INTEGRATION: CWS changefileheader (1.5.162); FILE MERGED 2008/04/01 16:10:18 thb 1.5.162.3: #i85898# Stripping all external header guards 2008/04/01 13:05:52 thb 1.5.162.2: #i85898# Stripping all external header guards 2008/03/31 16:28:54 rt 1.5.162.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: TransformerContext.hxx,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _XMLOFF_TRANSFORMERCONTEXT_HXX
#define _XMLOFF_TRANSFORMERCONTEXT_HXX

#include <com/sun/star/xml/sax/XAttributeList.hpp>
#include <tools/solar.h>
#include <salhelper/simplereferenceobject.hxx>
#include <rtl/ustring.hxx>
#include <tools/rtti.hxx>
#include <xmloff/xmltoken.hxx>

class SvXMLNamespaceMap;
class XMLTransformerBase;

class XMLTransformerContext : public ::salhelper::SimpleReferenceObject
{
    friend class XMLTransformerBase;

    XMLTransformerBase& m_rTransformer;

    ::rtl::OUString m_aQName;

    SvXMLNamespaceMap   *m_pRewindMap;

    SvXMLNamespaceMap  *GetRewindMap() const { return m_pRewindMap; }
    void SetRewindMap( SvXMLNamespaceMap *p ) { m_pRewindMap = p; }

protected:

    XMLTransformerBase& GetTransformer() { return m_rTransformer; }
    const XMLTransformerBase& GetTransformer() const { return m_rTransformer; }

    void SetQName( const ::rtl::OUString& rQName ) { m_aQName = rQName; }

public:
    TYPEINFO();

    const ::rtl::OUString& GetQName() const { return m_aQName; }
    sal_Bool HasQName( sal_uInt16 nPrefix,
                       ::xmloff::token::XMLTokenEnum eToken ) const;
    sal_Bool HasNamespace( sal_uInt16 nPrefix ) const;

    // A contexts constructor does anything that is required if an element
    // starts. Namespace processing has been done already.
    // Note that virtual methods cannot be used inside constructors. Use
    // StartElement instead if this is required.
    XMLTransformerContext( XMLTransformerBase& rTransformer,
                        const ::rtl::OUString& rQName );

    // A contexts destructor does anything that is required if an element
    // ends. By default, nothing is done.
    // Note that virtual methods cannot be used inside destructors. Use
    // EndElement instead if this is required.
    virtual ~XMLTransformerContext();

    // Create a childs element context. By default, the import's
    // CreateContext method is called to create a new default context.
    virtual XMLTransformerContext *CreateChildContext( sal_uInt16 nPrefix,
                                   const ::rtl::OUString& rLocalName,
                                   const ::rtl::OUString& rQName,
                                   const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );

    // StartElement is called after a context has been constructed and
    // before a elements context is parsed. It may be used for actions that
    // require virtual methods. The default is to do nothing.
    virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );

    // EndElement is called before a context will be destructed, but
    // after a elements context has been parsed. It may be used for actions
    // that require virtual methods. The default is to do nothing.
    virtual void EndElement();

    // This method is called for all characters that are contained in the
    // current element. The default is to ignore them.
    virtual void Characters( const ::rtl::OUString& rChars );

    // Is the current context a persistent one (i.e. one that saves is content
    // rather than exporting it directly?
    virtual sal_Bool IsPersistent() const;

    // Export the whole element. By default, nothing is done here
    virtual void Export();

    // Export the element content. By default, nothing is done here
    virtual void ExportContent();
};

#endif  //  _XMLOFF_TRANSFORMERCONTEXT_HXX

<|endoftext|>