Ignore:
Timestamp:
Oct 20, 2017, 12:40:18 PM (2 years ago)
Author:
cameron
Message:

Refactoring of grep_engine based on mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5698 r5700  
    2121namespace grep {
    2222
    23 // Thread function only.
    24 void *DoGrepThreadFunction(void *args);
    25    
    26 
    27 class NonNormalizingReportMatch : public MatchAccumulator {
    28 public:
    29     NonNormalizingReportMatch(std::string linePrefix) : mLinePrefix(linePrefix), mLineCount(0), mPrevious_line_end(nullptr) {}
    30     void accumulate_match(const size_t lineNum, char * line_start, char * line_end) override;
    31     void finalize_match(char * buffer_end) override;
    32     std::string mLinePrefix;
    33     size_t mLineCount;
    34     char * mPrevious_line_end;
    35     std::stringstream mResultStr;
    36    
    37 };
    38 
    39 
    4023class GrepEngine {
    4124public:
    4225
    43     GrepEngine() : mGrepDriver(nullptr), grepMatchFound(false), fileCount(0) {}
    44 
     26    GrepEngine() : mGrepDriver(nullptr), mFileSuffix(InitialTabFlag ? "\t:" : ":"), grepMatchFound(false), fileCount(0) {}
    4527
    4628    virtual ~GrepEngine();
     
    5032    virtual void grepCodeGen(std::vector<re::RE *> REs);
    5133
    52     uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
    53 
    54     uint64_t doGrep(const int32_t fileDescriptor, const uint32_t fileIdx);
     34    void run();
    5535   
    5636    void PrintResults();
    5737   
    5838   
     39   
     40protected:
     41    static void * DoGrepThreadFunction(void *args);
     42    virtual uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
     43    std::string linePrefix(std::string fileName);
     44   
     45    Driver * mGrepDriver;
    5946
    60     Driver * mGrepDriver;
     47    std::vector<std::string> inputFiles;
     48    std::vector<std::stringstream> mResultStrs;
     49   
     50    std::string mFileSuffix;
     51   
    6152    bool grepMatchFound;
    62 
    63     std::vector<std::unique_ptr<NonNormalizingReportMatch>> resultAccums;
    64     std::vector<std::string> inputFiles;
    65    
    6653    std::mutex count_mutex;
    6754    size_t fileCount;
    68    
    6955};
    7056
     
    7258public:
    7359   
    74     CountOnlyGrepEngine() : GrepEngine() {}
     60    CountOnlyGrepEngine() : GrepEngine() {mFileSuffix = ":";}
    7561    void grepCodeGen(std::vector<re::RE *> REs) override;
     62private:
     63    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
    7664   
    7765};
    7866
     67class MatchOnlyGrepEngine : public CountOnlyGrepEngine {
     68public:
     69   
     70    MatchOnlyGrepEngine() : CountOnlyGrepEngine(), mRequiredCount(Mode != FilesWithoutMatch) {mFileSuffix = NullFlag ? std::string("\0", 1) : "\n";}
     71private:
     72    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
     73    unsigned mRequiredCount;       
     74};
     75   
    7976}
    8077
Note: See TracChangeset for help on using the changeset viewer.