Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2018 Digital Barriers plc. All rights reserved.
3  * Contact:
4  *
5  * This file is part of the Papillon SDK.
6  *
7  * You can't use, modify or distribute any part of this file without
8  * the explicit written agreements of Digital Barriers.
9  */
15 #pragma once
16 #include <PapillonCommon.h>
17 #include <PFileStream.h>
18 #include <PResult.h>
19 #include <PString.h>
31 {
32 public:
37  template<class T>
38  static PResult ReadFromFile(const PString& filename, T& object, ESerialisationFormat format = E_BINARY_FORMAT)
39  {
40  PFileStream fs;
42  return object.Read(fs, format);
43  }
49  template<class T>
50  static PResult WriteToFile(const PString& filename, const T& object, ESerialisationFormat format = E_BINARY_FORMAT)
51  {
52  PFileStream fs;
54  return object.Write(fs, format);
55  }
57 private:
58  PFileIO();
59 };
The PFileStream class is a PByteStream whose backing store is a binary file.
Definition: PFileStream.h:24
The PString class provides an Unicode character strings.
Definition: PString.h:37
The PResult class represents the result returned by most of Papillon functions; this class is used to...
Definition: PResult.h:159
static PResult Open(const PString &filename, int openFlags, PFileStream &fileStream)
Opens a stream from the specified binary file for reading or writing.
static PResult ReadFromFile(const PString &filename, T &object, ESerialisationFormat format=E_BINARY_FORMAT)
Reads a Papillon object from a binary file.
Definition: PFileIO.h:38
Class PFileStream: a PByteStream (byte stream) whose backing store is a binary file.
Class PString: an unicode character strings (use copy-on-write idiom).
Class PResult: a result returned by most of Papillon functions; this class is used to replace classic...
Generic functions to read/write Papillon objects from/to binary files.
Definition: PFileIO.h:30
static PResult WriteToFile(const PString &filename, const T &object, ESerialisationFormat format=E_BINARY_FORMAT)
Writes a Papillon object to file as binary data.
Definition: PFileIO.h:50
#define ReturnIfFailed(expr)
Macro used to simulate the following idiom:
Definition: PResult.h:32
Open for writing; discard the contents of the stream when opening.
Definition: PFileStream.h:36
Open for reading.
Definition: PFileStream.h:33