Merge pull request #7 from wlawski/custom-storage
Allow saving SES to provided data storage
This commit is contained in:
		| @@ -26,17 +26,18 @@ for lib in libs: | ||||
|  | ||||
| conf.Finish() | ||||
|  | ||||
| targets = { 'strdiff'    : ['strdiff.cpp',    'common.cpp'], # diff between two string sequences | ||||
|             'intdiff'    : ['intdiff.cpp'],                  # diff between two integer sequences | ||||
|             'unidiff'    : ['unidiff.cpp',    'common.cpp'], # unified diff between two files | ||||
|             'unistrdiff' : ['unistrdiff.cpp', 'common.cpp'], # unified diff between two strings | ||||
|             'bdiff'      : ['bdiff.cpp',      'common.cpp'], # diff between two byte sequences | ||||
|             'strdiff3'   : ['strdiff3.cpp',   'common.cpp'], # three-way string diff program using dtl | ||||
|             'intdiff3'   : ['intdiff3.cpp'],                 # three-way integer diff program using dtl | ||||
|             'patch'      : ['patch.cpp',      'common.cpp'], # string patch program using dtl | ||||
|             'fpatch'     : ['fpatch.cpp',     'common.cpp'], # file patch program using dtl | ||||
|             'st2ses'     : ['st2ses.cpp',     'common.cpp'], # convert SES format file to SES instance | ||||
|             'strdiff_cp' : ['strdiff_cp.cpp', 'common.cpp'], # diff between two string sequences with custom printer | ||||
| targets = { 'strdiff'         : ['strdiff.cpp',         'common.cpp'], # diff between two string sequences | ||||
|             'intdiff'         : ['intdiff.cpp'],                       # diff between two integer sequences | ||||
|             'unidiff'         : ['unidiff.cpp',         'common.cpp'], # unified diff between two files | ||||
|             'unistrdiff'      : ['unistrdiff.cpp',      'common.cpp'], # unified diff between two strings | ||||
|             'bdiff'           : ['bdiff.cpp',           'common.cpp'], # diff between two byte sequences | ||||
|             'strdiff3'        : ['strdiff3.cpp',        'common.cpp'], # three-way string diff program using dtl | ||||
|             'intdiff3'        : ['intdiff3.cpp'],                      # three-way integer diff program using dtl | ||||
|             'patch'           : ['patch.cpp',           'common.cpp'], # string patch program using dtl | ||||
|             'fpatch'          : ['fpatch.cpp',          'common.cpp'], # file patch program using dtl | ||||
|             'st2ses'          : ['st2ses.cpp',          'common.cpp'], # convert SES format file to SES instance | ||||
|             'strdiff_cp'      : ['strdiff_cp.cpp',      'common.cpp'], # diff between two string sequences with custom printer | ||||
|             'strdiff_storage' : ['strdiff_storage.cpp', 'common.cpp'], # diff between two string sequences with custom storage | ||||
|             } | ||||
|  | ||||
| [ env.Program(target, targets[target]) for target in targets ] | ||||
|   | ||||
							
								
								
									
										27
									
								
								examples/storage.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								examples/storage.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| #ifndef DTL_STORAGE | ||||
| #define DTL_STORAGE | ||||
|  | ||||
| #include <dtl/dtl.hpp> | ||||
|  | ||||
| template <typename sesElem, typename storedData > | ||||
| class CustomStorage : public dtl::Storage < sesElem, storedData > | ||||
| { | ||||
| public : | ||||
|     CustomStorage(storedData& sd) : dtl::Storage < sesElem, storedData > (sd) {} | ||||
|     ~CustomStorage() {} | ||||
|     void operator() (const sesElem& se) const { | ||||
|         switch (se.second.type) { | ||||
|         case dtl::SES_ADD: | ||||
|             this->storedData_ = this->storedData_ + "Add: " + se.first + "\n"; | ||||
|             break; | ||||
|         case dtl::SES_DELETE: | ||||
|             this->storedData_ = this->storedData_ + "Delete: " + se.first + "\n"; | ||||
|             break; | ||||
|         case dtl::SES_COMMON: | ||||
|             this->storedData_ = this->storedData_ + "Common: " + se.first + "\n"; | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
| }; | ||||
|  | ||||
| #endif // DTL_STORAGE | ||||
							
								
								
									
										38
									
								
								examples/strdiff_storage.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								examples/strdiff_storage.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| #include <dtl/dtl.hpp> | ||||
| #include "common.hpp" | ||||
| #include <iostream> | ||||
| #include <string> | ||||
|  | ||||
| #include "storage.hpp" | ||||
|  | ||||
| using namespace std; | ||||
|  | ||||
| using dtl::Diff; | ||||
|  | ||||
| int main(int argc, char *argv[]){ | ||||
|      | ||||
|     if (isFewArgs(argc)) { | ||||
|         cerr << "Too few arguments." << endl; | ||||
|         return -1; | ||||
|     } | ||||
|      | ||||
|     typedef char   elem; | ||||
|     typedef string sequence; | ||||
|  | ||||
|     sequence A(argv[1]); | ||||
|     sequence B(argv[2]); | ||||
|      | ||||
|     Diff< elem, sequence > d(A, B); | ||||
|     d.compose(); | ||||
|      | ||||
|     // Shortest Edit Script | ||||
|     cout << "SES" << endl; | ||||
|  | ||||
|     string result; | ||||
|  | ||||
|     d.storeSES < string, CustomStorage > (result); | ||||
|  | ||||
|     cout << result; | ||||
|      | ||||
|     return 0; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user