Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

New Functions:

- ``::tixiSetDocumentPath ``: Provides an option to set a path for a document independently of the saving or opening process.

Version 3.3.1
-------------

Expand Down
14 changes: 14 additions & 0 deletions src/tixi.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,20 @@ DLL_EXPORT ReturnCode tixiCreateDocument (const char *rootElementName, TixiDocum
*/
DLL_EXPORT ReturnCode tixiGetDocumentPath (TixiDocumentHandle handle, char** documentPath);

/**
@brief Sets a file path for the document. The function sets the path independently of the saving/creating functions. This
useful if the document is not saved to disk yet, and an associated filepath is required.

@param[in] handle Document handle as returned by ::tixiOpenDocument, ::tixiOpenDocumentRecursive, ::tixiOpenDocumentFromHTTP, ::tixiCreateDocument or ::tixiImportFromString
@param[in] documentPath New path to the file.

@return
- SUCCESS in case of no errors.
- FAILED if documentPath is a null pointer.
- INVALID_HANDLE if the document handle is invalid.
*/
DLL_EXPORT ReturnCode tixiSetDocumentPath (TixiDocumentHandle handle, const char* xmlFilename);

/**
@brief Write XML-document to disk.

Expand Down
23 changes: 23 additions & 0 deletions src/tixiImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,29 @@ DLL_EXPORT ReturnCode tixiGetDocumentPath(TixiDocumentHandle handle, char** docu
return SUCCESS;
}

DLL_EXPORT ReturnCode tixiSetDocumentPath(TixiDocumentHandle handle, const char* xmlFilename)
{
TixiDocument *document = NULL;

if (!xmlFilename) {
printMsg(MESSAGETYPE_ERROR, "Error: Null Pointer in tixiSetDocumentPath.\n");
return FAILED;
}

document = getDocument(handle);
if (!document) {
printMsg(MESSAGETYPE_ERROR, "Error: Invalid document handle in tixiSetDocumentPath.\n");
return INVALID_HANDLE;
}
if(document->xmlFilename){
free(document->xmlFilename);
}
document->xmlFilename = (char*) malloc(sizeof(char) * (strlen(xmlFilename) + 1));
strcpy(document->xmlFilename, xmlFilename);

return SUCCESS;
}

/*
Distinguish internal/user/fatal errors!!!
*/
Expand Down
15 changes: 15 additions & 0 deletions tests/other_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ TEST(OtherTests2, getDocumentPathNoPath)
tixiCloseDocument(handle2);
}

TEST(OtherTests2,setDocumentPath)
{
const char* s = "<?xml version=\"1.0\" encoding=\"utf-8\"?><root/>";
const char* filename = "checkThisString";
TixiDocumentHandle handle;
char* path = NULL;
ASSERT_EQ(SUCCESS, tixiImportFromString(s, &handle));
ASSERT_EQ(SUCCESS, tixiGetDocumentPath(handle, &path));
ASSERT_EQ(NULL, path);
ASSERT_EQ(SUCCESS, tixiSetDocumentPath(handle, filename));
ASSERT_EQ(SUCCESS, tixiGetDocumentPath(handle, &path));
EXPECT_STREQ(filename, path);
tixiCloseDocument(handle);
}

TEST(OtherTests2, importFromString_invalidxml)
{
const char* s = "<?xml version=\"1.0\" encoding=\"utf-8\"?><root></notmatch>";
Expand Down