Ignore:
Timestamp:
Nov 12, 2010, 5:01:35 AM (11 years ago)
Author:
Peter Johansson
Message:

closes #457. Lifting out plotting functions in Stats into a new class
StatsPlotter?. In same manner lifting out print functions from
Node/Directory/File? into a new hierarchy
NodePrinter/DirectoryPrinter/FilePrinter?. To accomplish these splits
without to much recoding some friendships are introduced. These new
classes are only needed for svndigest (not svncopyright) and are
therefore placed in a library named libsvndigest together with Graph
class and first_page functions. Remaining functionality, shared
between svncopyright and svndigest, are located in libsvndigest_core
and linked into both binaries.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/lib/NodePrinter.h

    r1289 r1290  
    1 #ifndef _theplu_svndigest_node_
    2 #define _theplu_svndigest_node_
     1#ifndef _theplu_svndigest_node_printer_
     2#define _theplu_svndigest_node_printer_
    33
    44// $Id$
     
    4141namespace svndigest{
    4242
    43   class Alias;
    44   class NodeVisitor;
    45 
    46   ///
    47   /// If something goes wrong in the use of the Node or its derived
    48   /// classes, a NodeException is thrown.
    49   ///
    50   struct NodeException : public std::runtime_error
    51   { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
     43  class Node;
    5244
    5345  ///
    54   /// Abstract Base Class for files.
     46  /// Base class for FilePrinter and DirectoryPrinter
    5547  ///
    56   class Node
     48  class NodePrinter
    5749  {
    5850  public:
     
    6153    /// @brief Constructor
    6254    ///
    63     Node(const unsigned int, const std::string&, const std::string&,
    64          const std::string& = "");
     55    NodePrinter(void);
    6556
    6657    ///
    6758    /// @brief Destructor
    6859    ///
    69     virtual ~Node(void);
    70 
    71     ///
    72     /// @brief Get the author of the latest commit.
    73     ///
    74     std::string author(void) const;
    75 
    76 
    77     /**
    78        @brief Check whether node is binary.
    79 
    80        @return True if node is binary.
    81     */
    82     inline bool binary(void) const { return binary_; }
    83 
    84     ///
    85     /// @return true if directory
    86     ///
    87     virtual bool dir(void) const;
    88 
    89     ///
    90     /// @return href to this node
    91     ///
    92     virtual std::string href(void) const=0;
    93 
    94     void html_tablerow(std::ostream&, const std::string&,
    95                        const std::string& css,
    96                        const std::string& user) const;
    97 
    98     /**
    99        @brief Check whether node should be ignored in statistics.
    100 
    101        If a node is to be ignored the statistics implementer should
    102        respect this state. Currently binary files and items with
    103        property svndigest:ignore are to be ignored by svndigest. If
    104        the node is a directory then the direcotry and its siblings
    105        should be ignored by statistics.
    106 
    107        @return True of node should be ignored by statistics.
    108 
    109        @see SVNproperty::svndigest_ingorable
    110     */
    111     inline bool ignore(void) const
    112     { return binary_ || svndigest_ignore_ || link_; }
    113 
    114     /**
    115        Create the TinyStats based on the stored CollectionStats
    116      */
    117     void init_tiny_stats(void);
    118 
    119     ///
    120     /// @brief Get the revision number of the latest commit.
    121     ///
    122     virtual svn_revnum_t last_changed_rev(void) const=0;
    123 
    124     /**
    125        @return log of this node in a recursive manner.
    126     */
    127     const SVNlog& log(void) const;
    128 
    129     /**
    130        @return The explicit string identifying the underlying derived
    131        class.
    132     */
    133     virtual std::string node_type(void) const=0;
    134 
    135     ///
    136     /// @return
    137     ///
    138     inline const std::string& local_path(void) const { return local_path_; }
    139 
    140     ///
    141     /// Function returning everything after the last '/'
    142     ///
    143     /// @return name of node (not full path)
    144     ///
    145     std::string name(void) const;
     60    virtual ~NodePrinter(void);
    14661
    14762    /**
     
    15469
    15570    /**
    156        @return output path for example 'lib/Node.h.html' for this file
     71       @return output path for example 'lib/NodePrinter.h.html' for this file
    15772     */
    15873    virtual std::string output_path(void) const=0;
    159 
    160     ///
    161     /// @todo doc
    162     ///
    163     inline const std::string& path(void) const { return path_; }
    16474
    16575    ///
     
    17383                              const SVNlog&) const;
    17484
    175     /**
    176        \return true if svncopyright::ignore property was set
    177      */
    178     bool svncopyright_ignore(void) const;
    179 
    180     /**
    181        @brief Check if item used to create this object has been
    182        assigned property svndigest:ignore.
    183 
    184        Currently files with property svndigest:ignore are to be
    185        ignored by svndigest. It is the responsibility of the
    186        statistics implementer to obey the ignore state.
    187 
    188        @return True if item property svndigest:ignore was set.
    189     */
    190     inline bool svndigest_ignore(void) const { return svndigest_ignore_; }
    191 
    192     /**
    193      */
    194     const StatsCollection& stats(void) const;
    195 
    196     StatsCollection& stats(void);
    197 
    198     /**
    199        Access point for a NodeVisitor to start traversing Node and its
    200        daughter nodes.
    201      */
    202     virtual void traverse(NodeVisitor& visitor)=0;
    203 
    204     /**
    205        \see SVNinfo::url(void)
    206     */
    207     std::string url(void) const;
    208    
    209     inline const SVNinfo& svn_info(void) const { return svninfo_; }
    210 
    21185  protected:
    21286    ///
     
    21589    void path_anchor(std::ostream& os) const;
    21690
    217     unsigned int level_;
    218     std::string output_dir_;
    219     std::string path_; // absolute path
    220     static std::string project_;
    221     StatsCollection stats_;
    222     TinyStats tiny_stats_;
    223 
    22491  private:
    22592    ///
    22693    /// @brief Copy Constructor, not implemented
    22794    ///
    228     Node(const Node&);
     95    NodePrinter(const NodePrinter&);
    22996
    230     void html_tabletd(std::ostream&, const std::string& stats_type,
    231                       const std::string& user,
    232                       LineTypeParser::line_type lt) const;
    233 
    234     virtual void log_core(SVNlog&) const=0;
     97    virtual const Node& node(void) const=0;
    23598
    23699    virtual void print_core(bool verbose=false) const=0;
     
    245108                            const SVNlog&) const=0;
    246109
    247     bool binary_;
    248     bool link_;
    249     std::string local_path_; // path from root
    250     mutable SVNlog* log_;
    251     bool svndigest_ignore_;
    252     bool svncopyright_ignore_;
    253     SVNinfo svninfo_;
    254110  };
    255111
    256   /**
    257      \brief Functor class to compare pointers of Nodes
    258   */
    259   struct NodePtrLess
    260   {
    261     /**
    262        @return true if first and second are of same type (Directory or
    263        File) and name of first is (alphabetically) less than name of
    264        second; or if first is a Directory and second is a File.
    265      */
    266     inline bool operator()(const Node* first, const Node* second) const
    267     {   
    268       if (first->dir()==second->dir())
    269         return first->name()<second->name();
    270       return first->dir();
    271     }
    272   };
     112
     113
    273114
    274115}} // end of namespace svndigest and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.