aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-04-19 15:01:33 +0200
committerAdrian Kummerländer2014-04-19 15:01:33 +0200
commit334efe3383c436d61a8e5dd95b923cb0d5db9652 (patch)
tree591f2ab70e64fef5e74077000cfb010365fc5ce9
parent6c205f4859588fc8dad786dce5f2fa32c75fd3f3 (diff)
downloadInputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar
InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.gz
InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.bz2
InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.lz
InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.xz
InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.zst
InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.zip
Further code style fixes
* .. in the face of the planned development of usable external functions using the current proof-of-concept coding * replaced usage of std::shared_ptr in FunctionReadXmlFile class with explicit implementation of default and copy constructor * separated implementation and interfaces
-rw-r--r--CMakeLists.txt3
-rw-r--r--src/function/read_file.cc49
-rw-r--r--src/function/read_file.h36
-rw-r--r--src/function/read_xml_file.cc44
-rw-r--r--src/function/read_xml_file.h (renamed from src/read_xml_file_command.h)44
-rw-r--r--src/read_file_command.h62
-rw-r--r--src/utility.cc54
-rw-r--r--src/utility.h56
-rw-r--r--test.cc4
9 files changed, 207 insertions, 145 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7aadb81..aa6310b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,6 +13,9 @@ include_directories(
add_executable(
test
test.cc
+ src/utility.cc
+ src/function/read_file.cc
+ src/function/read_xml_file.cc
)
target_link_libraries(
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
new file mode 100644
index 0000000..efc1f61
--- /dev/null
+++ b/src/function/read_file.cc
@@ -0,0 +1,49 @@
+#include "read_file.h"
+
+namespace InputXSLT {
+
+xalan::XObjectPtr FunctionReadFile::execute(
+ xalan::XPathExecutionContext& executionContext,
+ xalan::XalanNode* context,
+ const xalan::Function::XObjectArgVectorType& arguments,
+ const xalan::Locator* locator
+) const {
+ if ( arguments.size() != 1 ) {
+ xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
+ executionContext
+ );
+
+ generalError(executionContext, context, locator);
+ }
+
+ xalan::CharVectorType fileNameVector;
+ std::string fileNameString;
+
+ arguments[0]->str().transcode(fileNameVector);
+
+ std::move(
+ fileNameVector.begin(),
+ fileNameVector.end(),
+ fileNameString.begin()
+ );
+
+ return executionContext.getXObjectFactory().createString(
+ xalan::XalanDOMString(
+ InputXSLT::readFile(fileNameString).data()
+ )
+ );
+}
+
+FunctionReadFile* FunctionReadFile::clone(
+ xalan::MemoryManager& manager) const {
+ return xalan::XalanCopyConstruct(manager, *this);
+}
+
+const xalan::XalanDOMString& FunctionReadFile::getError(
+ xalan::XalanDOMString& result) const {
+ result.assign("The read-file() function expects one argument.");
+
+ return result;
+}
+
+}
diff --git a/src/function/read_file.h b/src/function/read_file.h
new file mode 100644
index 0000000..dbcf3d6
--- /dev/null
+++ b/src/function/read_file.h
@@ -0,0 +1,36 @@
+#ifndef INPUTXSLT_SRC_FUNCTION_READ_FILE_H_
+#define INPUTXSLT_SRC_FUNCTION_READ_FILE_H_
+
+#include <xalanc/Include/PlatformDefinitions.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
+#include <xalanc/XalanTransformer/XalanTransformer.hpp>
+#include <xalanc/XPath/XObjectFactory.hpp>
+#include <xalanc/XPath/Function.hpp>
+#include <xalanc/XPath/XObject.hpp>
+
+#include "utility.h"
+
+namespace InputXSLT {
+
+class FunctionReadFile : public xalan::Function {
+ public:
+ virtual xalan::XObjectPtr execute(
+ xalan::XPathExecutionContext&,
+ xalan::XalanNode*,
+ const xalan::Function::XObjectArgVectorType&,
+ const xalan::Locator*
+ ) const;
+
+ virtual FunctionReadFile* clone(xalan::MemoryManager&) const;
+
+ FunctionReadFile& operator=(const FunctionReadFile&) = delete;
+ bool operator==(const FunctionReadFile&) const = delete;
+
+ private:
+ const xalan::XalanDOMString& getError(xalan::XalanDOMString&) const;
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_FUNCTION_READ_FILE_H_
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc
new file mode 100644
index 0000000..616d189
--- /dev/null
+++ b/src/function/read_xml_file.cc
@@ -0,0 +1,44 @@
+#include "read_xml_file.h"
+
+namespace InputXSLT {
+
+FunctionReadXmlFile::FunctionReadXmlFile():
+ parser_() { }
+
+FunctionReadXmlFile::FunctionReadXmlFile(const FunctionReadXmlFile&):
+ parser_() { }
+
+xalan::XObjectPtr FunctionReadXmlFile::execute(
+ xalan::XPathExecutionContext& executionContext,
+ xalan::XalanNode* context,
+ const xalan::Function::XObjectArgVectorType& arguments,
+ const xalan::Locator* locator
+) const {
+ if ( arguments.size() != 1 ) {
+ xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
+ executionContext
+ );
+
+ generalError(executionContext, context, locator);
+ }
+
+ return executionContext.getXObjectFactory().createNodeSet(
+ this->parser_.parseXMLStream(
+ xalan::XSLTInputSource(arguments[0]->str())
+ )
+ );
+}
+
+FunctionReadXmlFile* FunctionReadXmlFile::clone(
+ xalan::MemoryManager& manager) const {
+ return xalan::XalanCopyConstruct(manager, *this);
+}
+
+const xalan::XalanDOMString& FunctionReadXmlFile::getError(
+ xalan::XalanDOMString& result) const {
+ result.assign("The read-xml-file() function expects one argument.");
+
+ return result;
+}
+
+}
diff --git a/src/read_xml_file_command.h b/src/function/read_xml_file.h
index 8aee39f..1556764 100644
--- a/src/read_xml_file_command.h
+++ b/src/function/read_xml_file.h
@@ -1,3 +1,6 @@
+#ifndef INPUTXSLT_SRC_FUNCTION_READ_XML_FILE_H_
+#define INPUTXSLT_SRC_FUNCTION_READ_XML_FILE_H_
+
#include <xalanc/Include/PlatformDefinitions.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
@@ -8,53 +11,32 @@
#include "utility.h"
-#include <memory>
-
namespace InputXSLT {
class FunctionReadXmlFile : public xalan::Function {
public:
+ FunctionReadXmlFile();
+ FunctionReadXmlFile(const FunctionReadXmlFile&);
+
virtual xalan::XObjectPtr execute(
xalan::XPathExecutionContext& executionContext,
xalan::XalanNode* context,
const xalan::Function::XObjectArgVectorType& arguments,
const xalan::Locator* locator
- ) const {
- if ( arguments.size() != 1 ) {
- xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
- executionContext
- );
-
- generalError(executionContext, context, locator);
- }
-
- if ( !this->parser_ ) {
- this->parser_ = std::make_shared<xalan::XercesParserLiaison>();
- }
-
- return executionContext.getXObjectFactory().createNodeSet(
- this->parser_->parseXMLStream(
- xalan::XSLTInputSource(arguments[0]->str())
- )
- );
- }
-
- virtual FunctionReadXmlFile* clone(xalan::MemoryManager& manager) const {
- return xalan::XalanCopyConstruct(manager, *this);
- }
+ ) const;
+
+ virtual FunctionReadXmlFile* clone(xalan::MemoryManager&) const;
FunctionReadXmlFile& operator=(const FunctionReadXmlFile&) = delete;
bool operator==(const FunctionReadXmlFile&) const = delete;
private:
- mutable std::shared_ptr<xalan::XercesParserLiaison> parser_;
-
- const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const {
- result.assign("The read-xml-file() function expects one argument.");
+ mutable xalan::XercesParserLiaison parser_;
- return result;
- }
+ const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const;
};
}
+
+#endif // INPUTXSLT_SRC_FUNCTION_READ_XML_FILE_H_
diff --git a/src/read_file_command.h b/src/read_file_command.h
deleted file mode 100644
index 5e47c36..0000000
--- a/src/read_file_command.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <xalanc/Include/PlatformDefinitions.hpp>
-#include <xercesc/util/PlatformUtils.hpp>
-#include <xalanc/XalanTransformer/XalanTransformer.hpp>
-#include <xalanc/XPath/XObjectFactory.hpp>
-#include <xalanc/XPath/Function.hpp>
-#include <xalanc/XPath/XObject.hpp>
-
-#include "utility.h"
-
-namespace InputXSLT {
-
-class FunctionReadFile : public xalan::Function {
- public:
- virtual xalan::XObjectPtr execute(
- xalan::XPathExecutionContext& executionContext,
- xalan::XalanNode* context,
- const xalan::Function::XObjectArgVectorType& arguments,
- const xalan::Locator* locator
- ) const {
- if ( arguments.size() != 1 ) {
- xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
- executionContext
- );
-
- generalError(executionContext, context, locator);
- }
-
- xalan::CharVectorType fileNameVector;
- std::string fileNameString;
-
- arguments[0]->str().transcode(fileNameVector);
-
- std::move(
- fileNameVector.begin(),
- fileNameVector.end(),
- fileNameString.begin()
- );
-
- return executionContext.getXObjectFactory().createString(
- xalan::XalanDOMString(
- InputXSLT::readFile(fileNameString).data()
- )
- );
- }
-
- virtual FunctionReadFile* clone(xalan::MemoryManager& manager) const {
- return xalan::XalanCopyConstruct(manager, *this);
- }
-
- FunctionReadFile& operator=(const FunctionReadFile&) = delete;
- bool operator==(const FunctionReadFile&) const = delete;
-
- private:
- const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const {
- result.assign("The read-file() function expects one argument.");
-
- return result;
- }
-
-};
-
-}
diff --git a/src/utility.cc b/src/utility.cc
new file mode 100644
index 0000000..fb6fe61
--- /dev/null
+++ b/src/utility.cc
@@ -0,0 +1,54 @@
+#include "utility.h"
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <cstddef>
+#include <cstdio>
+
+namespace {
+
+const int OpenFlags = O_RDONLY;
+const mode_t OpenMode = S_IRUSR | S_IWUSR;
+
+}
+
+namespace InputXSLT {
+
+std::string readFile(const std::string& path) {
+ int descriptor(
+ open(path.data(), OpenFlags, OpenMode)
+ );
+
+ if ( descriptor == -1 ) {
+ close(descriptor);
+
+ return "io error";
+ } else {
+ struct stat info;
+ fstat(descriptor, &info);
+ const std::size_t size(info.st_size);
+
+ char* const buffer(new char[size]);
+
+ ssize_t readSize(read(
+ descriptor,
+ static_cast<void*const>(buffer),
+ size
+ ));
+
+ close(descriptor);
+
+ std::string content(
+ buffer,
+ readSize
+ );
+
+ delete[] buffer;
+
+ return content;
+ }
+}
+
+}
diff --git a/src/utility.h b/src/utility.h
index 82f52aa..b841373 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -1,59 +1,15 @@
-#ifndef UTILITY_H_
-#define UTILITY_H_
+#ifndef INPUTXSLT_SRC_UTILITY_H_
+#define INPUTXSLT_SRC_UTILITY_H_
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include <cstddef>
-#include <cstdio>
+#include <string>
+namespace xalanc_1_11 { };
namespace xalan = xalanc_1_11;
-namespace {
-
-const int OpenFlags = O_RDONLY;
-const mode_t OpenMode = S_IRUSR | S_IWUSR;
-
-}
-
namespace InputXSLT {
-std::string readFile(const std::string& path) {
- int descriptor(
- open(path.data(), OpenFlags, OpenMode)
- );
-
- if ( descriptor == -1 ) {
- close(descriptor);
-
- return "io error";
- } else {
- struct stat info;
- fstat(descriptor, &info);
- const std::size_t size(info.st_size);
-
- char* const buffer(new char[size]);
-
- ssize_t readSize(read(
- descriptor,
- static_cast<void*const>(buffer),
- size
- ));
-
- close(descriptor);
-
- std::string content(
- buffer,
- readSize
- );
-
- delete[] buffer;
-
- return content;
- }
-}
+std::string readFile(const std::string&);
}
-#endif // UTILITY_H_
+#endif // INPUTXSLT_SRC_UTILITY_H_
diff --git a/test.cc b/test.cc
index d6b45bf..cfcf632 100644
--- a/test.cc
+++ b/test.cc
@@ -3,8 +3,8 @@
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/XSLT/XSLTInputSource.hpp>
-#include "src/read_file_command.h"
-#include "src/read_xml_file_command.h"
+#include "function/read_file.h"
+#include "function/read_xml_file.h"
int main() {
xercesc::XMLPlatformUtils::Initialize();