source: icGREP/icgrep-devel/icgrep/do_grep.h @ 4440

Last change on this file since 4440 was 4440, checked in by cameron, 5 years ago

Send all output to std::cout, convert line breaks

File size: 2.0 KB
Line 
1#ifndef DO_GREP_H
2#define DO_GREP_H
3/*
4 *  Copyright (c) 2014 International Characters.
5 *  This software is licensed to the public under the Open Software License 3.0.
6 *  icgrep is a trademark of International Characters.
7 */
8
9#include <fstream>
10#include <sstream>
11#include <iostream>
12#include <string>
13#include <stdint.h>
14
15#include "include/simd-lib/bitblock.hpp"
16#include "include/simd-lib/transpose.hpp"
17#include "include/simd-lib/bitblock_iterator.hpp"
18
19struct Output {
20    BitBlock matches;
21    BitBlock LF;
22};
23
24#if (BLOCK_SIZE == 128)
25#define SEGMENT_BLOCKS 7
26#endif
27
28#if (BLOCK_SIZE == 256)
29#define SEGMENT_BLOCKS 15
30#endif
31
32#define SEGMENT_SIZE (BLOCK_SIZE * SEGMENT_BLOCKS)
33
34
35#if (BLOCK_SIZE == 256)
36typedef BitStreamScanner<BitBlock, uint64_t, uint64_t, SEGMENT_BLOCKS> ScannerT;
37#endif
38
39#if (BLOCK_SIZE == 128)
40typedef BitStreamScanner<BitBlock, uint32_t, uint32_t, SEGMENT_BLOCKS> ScannerT;
41#endif
42
43
44typedef void (*process_block_fcn)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output);
45
46
47
48class GrepExecutor {
49public:
50    GrepExecutor(int carry_count, int advance_count, process_block_fcn process_block): 
51    mCountOnlyOption(false), mShowFileNameOption(false), mShowLineNumberingOption(false),
52    mCarries(carry_count), mAdvances(advance_count),
53    mProcessBlockFcn(process_block)
54    {}
55         
56    void setCountOnlyOption(bool doCount = true) {mCountOnlyOption = doCount;}
57    void setShowFileNameOption(bool showF = true) {mShowFileNameOption = showF;}
58    void setShowLineNumberOption(bool showN = true) {mShowLineNumberingOption = showN;}
59   
60    void doGrep(std::string fileName);
61private:
62    ssize_t write_matches(char * buffer, ssize_t first_line_start);
63
64    bool mCountOnlyOption;
65    bool mShowFileNameOption;
66    bool mShowLineNumberingOption;
67    int mCarries;
68    int mAdvances;
69    process_block_fcn mProcessBlockFcn;
70   
71    std::string currentFileName;
72    ScannerT LF_scanner;
73    ScannerT match_scanner;
74    long line_no;
75};
76
77
78#endif
Note: See TracBrowser for help on using the repository browser.