MeVisLab Toolbox Reference
mlIOHandler.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_IOHANDLER_H
14 #define ML_IOHANDLER_H
15 
16 
20 
21 #include "mlParserSystem.h"
22 
23 // include your parser (= TreeNode derivate) header here:
25 #include "mlDebug.h"
26 
27 ML_START_NAMESPACE
28 
34 
35  public:
36 
39  typedef enum {
42 
45 
47  IO_MODE_COUNT
48 
49  } IO_MODE;
50 
53  static const char* IO_MODE_TOKENS[];
54 
58  try {
59  switch (ioMode) {
60 
61  // create XML node:
62  case IO_MODE_XML:
63  return new XMLTreeNode(conMode);
64 
65  // current default: XML
66  default:
67  return new XMLTreeNode(conMode);
68  }
69  } catch (const TreeNodeException& /*e*/) {
70  return nullptr;
71  }
72  }
73 
76  static const char* getDefaultFileExtension(IO_MODE ioMode) {
77 
78  switch (ioMode) {
79 
80  // return preferred XML extension:
81  case IO_MODE_XML:
82  return ".xml";
83 
84  default:
85  return nullptr;
86  }
87  }
88 
90  static IO_MODE getModeFromExtension(const char* fileName);
91 
93  static IO_MODE getModeFromContents(const char* fileName);
94 
95  };
96 
97 
98 ML_END_NAMESPACE
99 
100 
101 
102 #endif // __mlIOHandler_H
103 
Handles the different possible IO modes.
Definition: mlIOHandler.h:33
static IO_MODE getModeFromExtension(const char *fileName)
Returns the mode that fits to file's extension (using getDefaultFileExtension);.
static IO_MODE getModeFromContents(const char *fileName)
Returns the mode that fits to file's contents (only a small part of the file's contents is evaluated)
static const char * getDefaultFileExtension(IO_MODE ioMode)
Get the default file extension Register your own TreeNode type here.
Definition: mlIOHandler.h:76
static TreeNode * createRootTreeNode(IO_MODE ioMode, TreeNode::ConstructionMode conMode)
Creates a root node for reading or writing.
Definition: mlIOHandler.h:57
IO_MODE
Register your parser type here.
Definition: mlIOHandler.h:39
@ IO_MODE_XML
import/export in XML format
Definition: mlIOHandler.h:41
@ IO_MODE_AUTO
auto detect format
Definition: mlIOHandler.h:44
The class TreeNodeException is the base class for all exceptions thrown by the class TreeNode and all...
Definition: mlTreeNode.h:111
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition: mlTreeNode.h:170
ConstructionMode
TreeNode construction modes:
Definition: mlTreeNode.h:213
The class XMLTreeNode implements the abstract class TreeNode to allow export and import of ML objects...
Definition: mlXMLTreeNode.h:83
#define PARSER_EXPORT
Definiert systemspezifische Macros, die f"ur diese DLL gelten sollen.