File: paramFile.h

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 239,888 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 95
file content (134 lines) | stat: -rw-r--r-- 4,182 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#ifndef BALL_FORMAT_PARAMFILE_H
#define BALL_FORMAT_PARAMFILE_H

#include <BALL/SYSTEM/file.h>
#include <BALL/DATATYPE/string.h>

#include <QtCore/QXmlStreamReader>
#include <QtCore/QXmlStreamWriter>
#include <QtCore/QFile>

#include <map>
#include <list>
#include <set>


namespace BALL
{
	/** Class for storing and retrieving parameters (e.g. tool-parameters) to an xml-based file */
	class BALL_EXPORT ParamFile : public File
	{
		public:

			enum ParameterType
			{
				INFILE,
				OUTFILE,
				STRING,
				INT,
				DOUBLE,
				INFILELIST,
				OUTFILELIST,
				STRINGLIST,
				INTLIST,
				DOUBLELIST,
				//TODO: do we REALLY need these two openly galaxy specific parameter types?
				//      couldn't we do it with tags or something more elegant?
				GALAXY_OPT_OUTDIR,
				GALAXY_OPT_OUTID
			};

			struct ParameterDescription
			{
				// constructor
				ParameterDescription()
				{
					name = "";
					description = "";
					category = "";
					mandatory = false;
					advanced = false;
					type = INFILE;
					allowed_values.clear();
					supported_formats.clear();
					hidden = false;
				}

				String name;
				String description;
				String category;
				bool mandatory;
				bool advanced;
				ParameterType type;

				/** If this list is empty, then there are no restrictions on the value of the parameter */
				list<String> allowed_values;

				/** In case of input-/output-files, this list should contain the supported file-extensions. \n
				If the list is empty, no format restrictions are set. */
				list<String> supported_formats;

				// if parameters shall be hidden in galaxy
				bool hidden;
			};

			ParamFile(const String& name, File::OpenMode open_mode);
			~ParamFile();

			/** Write a section to the output file (e.g. parameters for one tool)
			@param section_description a *short* description of this section (e.g. the tool), containing only a few words
			@param section_helptext a longer help-text/detailed description can be specified here
			@param category the category into which the tool falls (e.g. Docking, QSAR, etc.)
			@param descriptions description for all parameters to be saved
			@param value values of all parameters to be saved */
			void writeSection(String section_name, String section_description, String version, const String& section_helptext,
					              const String& category, const std::list<std::pair<String,ParameterDescription> >& descriptions,
												const std::map<String,list<String> >& values);

			/** Read a section from input file (e.g. parameters for one tool)
			@param descriptions descriptions of parameters will be stored here 
			@param values values of parameters will be stored here
			@param overwrite_existing if set to true, entries already existing in 'descriptions' and 'values' will be overwritten. */
			void readSection(String& tool_name, String& section_description, String& version, String& section_helptext,
					             String& category, std::list<std::pair<String, ParameterDescription> >& descriptions,
											 std::map<String,list<String> >& values,
											 bool overwrite_existing=false);

			void close();

			/** From category, parameter_name builds [category]:[parameter_name] */
			static String buildNestedParameterName(const String& category, const String& parameter_name);

			/** Returns [category, parameter] from [category]:[parameter] */
			static Size parseNestedParameterName(const String& parameter_name, String string_array[]);


		protected:

			String filename_;
			File::OpenMode open_mode_;
			bool mode_read_;
			QXmlStreamReader* xmlIn_;
			QXmlStreamWriter* xmlOut_;
			QFile* file_;

		private:

			/**
			 * Given the value of the "tags" attribute of an ITEM or ITEMLIST element, this method
			 * extracts the attribute named "tags" and returns each individual tag, assumming that
			 * each tag has been comma separated (each individual tag is trimmed of whitespace).
			 *
			 * @brief getTags
			 * @param attributes The attributes.
			 * @return A set containing the individual tasks.
			 */
			std::set<String> getTags(QXmlStreamAttributes& attributes);
	};
}

#endif