PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
PPath.cpp File Reference
#include <errno.h>
#include <stdio.h>
#include <regex.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include "phoenix_env.h"
#include "phoenix_system.h"
#include "PPath.h"
+ Include dependency graph for PPath.cpp:

Go to the source code of this file.

Functions

PPath operator+ (const PPath &other1, const PPath &other2)
 Operator + for PPath. More...
 
PPath operator/ (const PPath &other1, const PPath &other2)
 Operator / for PPath to concatenate PPath. More...
 
PString phoenix_getFileContent (FILE *fp)
 Get the content of a file. More...
 

Function Documentation

◆ operator+()

PPath operator+ ( const PPath other1,
const PPath other2 
)

Operator + for PPath.

Parameters
other1: PPath
other2: PPath
Returns
other1 + other2

Definition at line 108 of file PPath.cpp.

108  {
109  PPath out(other1);
110  out += other2;
111  return out;
112 }
Path of a directory or a file.
Definition: PPath.h:17

◆ operator/()

PPath operator/ ( const PPath other1,
const PPath other2 
)

Operator / for PPath to concatenate PPath.

Parameters
other1: PPath
other2: PPath
Returns
other1 / other2

Definition at line 119 of file PPath.cpp.

119  {
120  PPath out(other1);
121  if(other1.size() != 0lu){
122  out += PString("/");
123  }
124  out += other2;
125  return out;
126 }
Extends the std::string.
Definition: PString.h:16

◆ 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 }

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

+ Here is the caller graph for this function: