Custom String Filter Design

Suppose I have tons of file names in my_dir/my_subdir, formatted in some way:

data11_7TeV.00179691.physics_Egamma.merge.NTUP_PHOTON.f360_m796_p541_tid319627_00
data11_7TeV.00180400.physics_Egamma.merge.NTUP_PHOTON.f369_m812_p541_tid334757_00
data11_7TeV.00178109.physics_Egamma.merge.D2AOD_DIPHO.f351_m765_p539_p540_tid312017_00

For example, data11_7TeVthis is data_type, 00179691start number, NTUP_PHOTONdata format.

I want to write an interface to do something like this:

dataset = DataManager("my_dir/my_subdir").filter_type("data11_7TeV").filter_run("> 00179691").filter_tag("m = 796");                     
// don't to the filtering, be lazy
cout << dataset.count();                          // count is an action, do the filtering
vector<string> dataset_list = dataset.get_list(); // don't repeat the filtering
dataset.save_filter("file.txt", "ALIAS");         // save the filter (not the filenames), for example save the regex
dataset2 = DataManagerAlias("file.txt", "ALIAS"); // get the saved filter
cout << dataset2.filter_tag("p = 123").count();

I need lazy behavior, for example, no valid filtering should be performed before any actions like countor get_list. I do not want to repeat the filtering if it is already done. I'm just learning something about a design template, and I think I can use:

  • abstract base class AbstractFilterthat implements methodsfilter*
  • factory to solve from the called method that decorator uses
  • , filter *, , :

AbstractFilter::filter_run(string arg) {
    decorator = factory.get_decorator_run(arg);  // if arg is "> 00179691" returns FilterRunGreater(00179691)
    return decorator(this);
}

  • , ,

jQuery, .

- ? , ? , , .

+3
4

, - /. , , , , count() get_list() dataset ( dataset).

, , . , , -, , , . , .

, , A.

, , , std::multimap find(), lower_bound() upper_bound(). - , , , p, m, tid .., A. STL, , .

, / ( ). :

  • , , (, < 100), .

, : std::string data_type; std::vector<int> p; .., , "p" 924 data_type == "XYZ", , .

, , , SQL- , .

+3

. DataManager DataSet, DataSet FilteringPolicy. NullFilteringPolicy, . DataSet filter_type ( t), . factory, filter_type. , filter_run(), FilterPolicy. NullFilterPolicy -ops. , , , .

EDIT: , * this; DataSet. , DataSet . , ++ iostream → <.

+1

, , , .

, , "Domain Specific Language", "" ( ), "" ( , , ).

"" ". , , , " ", :

" - -, ".

, , .

, DSL. , , (, ). : Regex Table Lexer, , .. , .

, , , " " , , , , , , , "" GoF.

, "" , , , .

+1

boost - , .

(, , boost .)

0
source

All Articles