coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dataset.h
Go to the documentation of this file.
1 #ifndef DATASET_H
2 #define DATASET_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
6  * All rights reserved. *
7  * *
8  * Contributed originally by Mike Kinghan, imk@burroingroingjoing.com *
9  * *
10  * Redistribution and use in source and binary forms, with or without *
11  * modification, are permitted provided that the following conditions *
12  * are met: *
13  * *
14  * Redistributions of source code must retain the above copyright *
15  * notice, this list of conditions and the following disclaimer. *
16  * *
17  * Redistributions in binary form must reproduce the above copyright *
18  * notice, this list of conditions and the following disclaimer in the *
19  * documentation and/or other materials provided with the distribution. *
20  * *
21  * Neither the name of Mike Kinghan nor the names of its contributors *
22  * may be used to endorse or promote products derived from this software *
23  * without specific prior written permission. *
24  * *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
32  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
33  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
34  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
35  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
36  * DAMAGE. *
37  * *
38  **************************************************************************/
39 
40 #include "prohibit.h"
41 #include "file_tree.h"
42 
50 struct dataset : private no_copy {
51 
57  struct selector {
65  explicit selector(std::string const & extensions = std::string());
66 
71  bool operator()(std::string const & filename);
72 
74  unsigned files() const {
75  return _files;
76  }
77  private:
79  std::vector<std::string> _filter_extensions;
81  unsigned _files;
82  };
83 
88 
90  unsigned done_files() const {
91  return _done_files;
92  }
93 
95  unsigned error_files() const {
96  return _error_files;
97  }
98 
100  void at_file(std::string const & filename);
101 
102  private:
104  unsigned _done_files = 0;
106  unsigned _error_files = 0;
107  };
108 
113  static void set_filter(std::string extensions) {
114  _selector_ = selector(extensions);
115  }
127  static void add(std::string const & path);
128 
130  static void traverse() {
132  }
133 
135  static unsigned files() {
136  return _selector_.files();
137  }
138 
140  static unsigned done_files() {
141  return _driver_.done_files();
142  }
143 
147  static unsigned error_files() {
148  return _driver_.error_files();
149  }
150 
151 private:
152 
156  static driver _driver_;
159 };
160 
161 #endif /* EOF*/
static selector _selector_
The selector for including files in the dataset
Definition: dataset.h:154
selector(std::string const &extensions=std::string())
Construct from a filter string.
Definition: dataset.cpp:76
static void add(std::string const &path)
Add files to the dataset.
Definition: dataset.cpp:144
unsigned _files
The number of files so far selected.
Definition: dataset.h:81
static unsigned error_files()
Get the number of files abandoned due to errors in traversal of the dataset.
Definition: dataset.h:147
unsigned done_files() const
Get the number of files reached in the dataset.
Definition: dataset.h:90
unsigned files() const
Get the number of files so far selected.
Definition: dataset.h:74
A base for classes employed to traverse a file_tree.
Definition: file_tree.h:285
Encapsulates a set of directory/file trees.
Definition: file_tree.h:55
A utility class to prevent copying of containing class.
Definition: prohibit.h:68
bool operator()(std::string const &filename)
Say whether a file is selected for processing.
Definition: dataset.cpp:91
static driver _driver_
The driver for traversing dataset
Definition: dataset.h:156
Encapsulates the selection of files for processing.
Definition: dataset.h:57
static void set_filter(std::string extensions)
Specify the filtering of files in the dataset.
Definition: dataset.h:113
std::vector< std::string > _filter_extensions
A vector of the file extensions that are to be selected.
Definition: dataset.h:79
static unsigned files()
Get the number of files in the dataset.
Definition: dataset.h:135
void traverse(traverser &action)
Traverse the file_tree.
Definition: file_tree.h:343
static unsigned done_files()
Get the number of files reached by traversal of the dataset
Definition: dataset.h:140
void at_file(std::string const &filename)
Process a file in the dataset.
Definition: dataset.cpp:119
struct driver encapsulates traversal of an input dataset to select and process files.
Definition: dataset.h:87
unsigned error_files() const
Get the number of files abandoned due to errors.
Definition: dataset.h:95
Encapsulates a filesystem path.
Definition: path.h:59
unsigned _error_files
The number of files abandoned due to errors.
Definition: dataset.h:106
struct dataset encapsulates the tree of input files to be processed by coan.
Definition: dataset.h:50
static file_tree _ftree_
The tree of input files.
Definition: dataset.h:158
unsigned _done_files
The number of files reached.
Definition: dataset.h:104
static void traverse()
Traverse the dataset processing the selected files.
Definition: dataset.h:130