PhoenixPresentation  2.0.0
Set of cmake function to automate presentation generation
PPath.h File Reference
#include <sys/stat.h>
#include <sys/types.h>
#include "PString.h"
+ Include dependency graph for PPath.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  PPath
 Path of a directory or a file. More...
 

Typedefs

typedef std::vector< PPathPVecPath
 

Functions

PString phoenix_getFileContent (FILE *fp)
 Get the content of a file. More...
 

Typedef Documentation

◆ PVecPath

typedef std::vector<PPath> PVecPath

Definition at line 75 of file PPath.h.

Function Documentation

◆ phoenix_getFileContent()

PString phoenix_getFileContent ( FILE *  fp)

Get the content of a file.

Parameters
fp: file pointer to be used
Returns
content of file fp

Definition at line 28 of file PPath.cpp.

28  {
29  if(fp == NULL){return "";}
30  //Let's get the size of the file
31  fseek(fp, 0, SEEK_END);
32  long fileOffset(ftell(fp));
33  fseek(fp, 0, SEEK_SET);
34  //Is the file is empty we quit
35  if(fileOffset == 0l){
36  return "";
37  }
38  //If the size of the file is -1lu this should be a stream which has no defined end yet, such as the popen output
39  if(fileOffset == -1l){
40  //So we have to use the old method which consist to read the stream character per character until EOF
41  //We have to use a std::string instead of PString to have smarter resize strategy
42  std::string strBuffer("");
43  int buffer;
44  while(!feof(fp)){
45  buffer = fgetc(fp);
46  if(buffer != EOF) strBuffer += (char)buffer;
47  else break;
48  }
49  return strBuffer;
50  }else{
51  size_t fileSize(fileOffset);
52  //If we know the size of the file, we can resize our PString once for all and load the content with fread
53  PString bufferAllFile;
54  bufferAllFile.resize(fileSize);
55  if(fread(bufferAllFile.data(), sizeof(char), fileSize, fp) == fileSize){
56 
57  }
58  return bufferAllFile;
59  }
60 }
Extends the std::string.
Definition: PString.h:16

Referenced by PPath::loadFileContent(), and phoenix_popen().

+ Here is the caller graph for this function: