-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow saving SES to provided data storage
It is not always efficient (or possible) to use standard output streams. Moreover, such generated result may be now further processed.
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |