Some tests for 'gmx help -export rst'
[alexxy/gromacs.git] / src / gromacs / utility / file.h
index d1f354c9a44b20745ae3c68587fbe96c35e208cd..5e457360760098321180d4f8c3665dc0b115d44e 100644 (file)
 namespace gmx
 {
 
+class File;
+
+/*! \brief
+ * Parameters for creating a File object.
+ *
+ * This class (mostly) replaces the ability to return a File object from a
+ * function (since File is not copyable): returning a FileInitializer instead
+ * allows the caller to construct the File object.
+ *
+ * \inpublicapi
+ * \ingroup module_utility
+ */
+class FileInitializer
+{
+    public:
+        /*! \brief
+         * Creates the initializer with given parameters.
+         *
+         * The passed strings must remain valid until the initializer is used
+         * to construct a File object.
+         */
+        FileInitializer(const char *filename, const char *mode)
+            : filename_(filename), mode_(mode)
+        {
+        }
+
+    private:
+        const char *filename_;
+        const char *mode_;
+
+        /*! \brief
+         * Needed to allow access to the parameters without otherwise
+         * unnecessary accessors.
+         */
+        friend class File;
+};
+
 /*! \brief
  * Basic file object.
  *
@@ -90,6 +127,14 @@ class File
         File(const char *filename, const char *mode);
         //! \copydoc File(const char *, const char *)
         File(const std::string &filename, const char *mode);
+        /*! \brief
+         * Creates a file object and opens a file.
+         *
+         * \param[in] initializer  Parameters to open the file.
+         * \throws    std::bad_alloc if out of memory.
+         * \throws    FileIOError on any I/O error.
+         */
+        File(const FileInitializer &initializer);
         /*! \brief
          * Destroys the file object.
          *