src/PythonHandler.h
branchv_0
changeset 15 60a17d8fc223
parent 14 9ed7c3b6ad7a
child 16 c71600851b01
equal deleted inserted replaced
14:9ed7c3b6ad7a 15:60a17d8fc223
    44 using namespace std;
    44 using namespace std;
    45 using namespace relpipe;
    45 using namespace relpipe;
    46 using namespace relpipe::reader;
    46 using namespace relpipe::reader;
    47 using namespace relpipe::reader::handlers;
    47 using namespace relpipe::reader::handlers;
    48 
    48 
    49 class GrepHandler : public RelationalReaderStringHadler {
    49 class PythonHandler : public RelationalReaderStringHadler {
    50 private:
    50 private:
    51 	shared_ptr<writer::RelationalWriter> relationalWriter;
    51 	shared_ptr<writer::RelationalWriter> relationalWriter;
    52 
    52 
    53 	wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
    53 	wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
    54 	wchar_t* pythonProgramName;
    54 	wchar_t* pythonProgramName;
    61 	boolean_t includeCurrentRecord = true;
    61 	boolean_t includeCurrentRecord = true;
    62 	boolean_t filterCurrentRelation = false;
    62 	boolean_t filterCurrentRelation = false;
    63 
    63 
    64 public:
    64 public:
    65 
    65 
    66 	GrepHandler(ostream& output, const vector<string_t>& arguments) {
    66 	PythonHandler(ostream& output, const vector<string_t>& arguments) {
    67 		relationalWriter.reset(writer::Factory::create(output));
    67 		relationalWriter.reset(writer::Factory::create(output));
    68 
    68 
    69 		pythonProgramName = Py_DecodeLocale("relpipe-tr-python", NULL);
    69 		pythonProgramName = Py_DecodeLocale("relpipe-tr-python", NULL);
    70 		Py_SetProgramName(pythonProgramName);
    70 		Py_SetProgramName(pythonProgramName);
    71 		Py_Initialize();
    71 		Py_Initialize();
    77 			PyMem_RawFree(pythonProgramName);
    77 			PyMem_RawFree(pythonProgramName);
    78 			throw cli::RelpipeCLIException(L"Usage: relpipe-tr-python <relationNameRegExp> <pythonCode>", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND);
    78 			throw cli::RelpipeCLIException(L"Usage: relpipe-tr-python <relationNameRegExp> <pythonCode>", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND);
    79 		}
    79 		}
    80 	}
    80 	}
    81 
    81 
    82 	virtual ~GrepHandler() {
    82 	virtual ~PythonHandler() {
    83 		Py_FinalizeEx();
    83 		Py_FinalizeEx();
    84 		PyMem_RawFree(pythonProgramName);
    84 		PyMem_RawFree(pythonProgramName);
    85 	}
    85 	}
    86 
    86 
    87 	void startRelation(string_t name, vector<AttributeMetadata> attributes) override {
    87 	void startRelation(string_t name, vector<AttributeMetadata> attributes) override {