File: trajectoryFileFactory.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 (64 lines) | stat: -rw-r--r-- 2,620 bytes parent folder | download | duplicates (7)
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
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#ifndef BALL_FORMAT_TRAJECTORYFILEFACTORY_H
#define BALL_FORMAT_TRAJECTORYFILEFACTORY_H

#ifndef BALL_SYSTEM_FILE_H
# include <BALL/SYSTEM/file.h>
#endif

namespace BALL
{
	class String;
	class TrajectoryFile;

	/**
	 * This class offers a factory method that given a path to a trajectory file
	 * determines the file type based on the file extension and returns
	 * a pointer to an appropriate subclass of TrajectoryFile
	 */
	class BALL_EXPORT TrajectoryFileFactory
	{
		public:
			/** Open a file.
			* This method tries to determine the filetype based on the file extension of name and
			* returns a pointer to an object of the appropriate subclass of TrajectoryFile if available.
			* If the file should be opened in read-mode and the extension is unknown or the file does not
			* have an extension, we try to automatically detect the format. 
			* If the detection fails, NULL is returned.
			*
			* @param name the path to the requested molecule file
			* @return a pointer to a subclass of TrajectoryFile, NULL if none is appropriate. Be aware that
			*         the file handle has not been checked for validity and that you have to delete it yourself
			*/
			static TrajectoryFile* open(const String& name, File::OpenMode open_mode = std::ios::in);

			/** Open a file.
			 *  When trying to open a file in write-mode, this function can be used to pass along a desired default-format. 
			 *  If the given filename does not have a supported extension, the specified default format will be used.
			 */
			static TrajectoryFile* open(const String& name, File::OpenMode open_mode, String default_format);

			/** Open a file.
			 *  When trying to open a file in write-mode, this function can be used to pass along a desired default-format. 
			 *  If the given filename does not have a supported extension, the format of 'default_format_file' will be used.
			 */
			static TrajectoryFile* open(const String& name, File::OpenMode open_mode, TrajectoryFile* default_format_file);

			/** Return a comma-separated string containing the file-extensions that are supported by TrajectoryFileFactory */
			static String getSupportedFormats();

			/** Return true if the extension of the specified filename is supported; otherwise return false. */
			static bool isFileExtensionSupported(String filename);

		private:

			/** Try to automatically detect the format of an input-file using keywords that are specific for the respective format. */
			static TrajectoryFile* detectFormat(const String& name);
	};

}

#endif // BALL_FORMAT_TRAJECTORYFILEFACTORY_H