[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [brprint3d] /: Few Ajusts
From:       Lays Rodrigues <laysrodriguessilva () gmail ! com>
Date:       2015-12-01 1:35:03
Message-ID: E1a3ZqR-0000XT-TZ () scm ! kde ! org
[Download RAW message or body]

Git commit ee5b8121f554038d2f34715c7d98935c0f4fd1fc by Lays Rodrigues.
Committed on 01/12/2015 at 01:28.
Pushed by laysrodrigues into branch 'master'.

Few Ajusts

Change the constructer parameter from const char to
stdString and adapted the code to use it.
Made some commentaries about this class on header.

Signed-off-by: Lays Rodrigues <laysrodriguessilva@gmail.com>

M  +22   -11   FilCount.cpp
M  +14   -2    FilCount.h

http://commits.kde.org/brprint3d/ee5b8121f554038d2f34715c7d98935c0f4fd1fc

diff --git a/FilCount.cpp b/FilCount.cpp
index 1347f0a..cb67be1 100644
--- a/FilCount.cpp
+++ b/FilCount.cpp
@@ -23,20 +23,34 @@
 
 #include "FilCount.h"
 
-FilCount::FilCount(const char *filePath) throw (std::string)
+FilCount::FilCount(std::string filePath) throw (std::string)
 {
-    char instring[100001], *X, *Y, *Z;
-    bool first = true;
-    double vX[2], vY[2], vZ[2] /*0 - Inicial, 1 - Final*/, temp;
-    this->GCode = fopen(filePath, "rt");
+    char instring[100001];
+    char *X;
+    char *Y;
+    char *Z;
+    bool first;
+    double vX[2];
+    double vY[2];
+    double vZ[2]; /*0 - Initial, 1 - Final*/
+    double temp;
+    X = NULL;
+    Y = NULL;
+    Z = NULL;
+    for (instring[0] = 0; instring[0] < 2; instring[0]++){
+        vX[instring[0]] = 0.0;
+        vY[instring[0]] = 0.0;
+        vZ[instring[0]] = 0.0;
+    }
+    instring[0] = 0;
+    this->GCode = fopen(filePath.c_str(), "rt");
     if(this->GCode == NULL){
         std::string exc = "Could not open the file: ";
         exc+=filePath;
         exc+=".";
         throw exc;
     }
-    this->filePath = (char*)malloc((strlen(filePath) + 1) * sizeof(char));
-    strcpy(this->filePath, filePath);
+    _filePath = filePath;
     this->totalSize = 0.0;
     while(fscanf(this->GCode, "%[^\n]\n", instring) != EOF){
         if(!first){
@@ -93,8 +107,6 @@ FilCount::FilCount(const char *filePath) throw (std::string)
 
 FilCount::~FilCount()
 {
-    free(this->filePath);
-    this->filePath = NULL;
     this->totalSize = 0.0;
     fclose(this->GCode);
     this->GCode = NULL;
@@ -107,8 +119,7 @@ double FilCount::getTotalSize()
 
 std::string FilCount::getFilePath()
 {
-    std::string ret = this->filePath;
-    return ret;
+    return _filePath;
 }
 
 long FilCount::getTimeInSeconds(double speed)
diff --git a/FilCount.h b/FilCount.h
index 056b546..051a11c 100644
--- a/FilCount.h
+++ b/FilCount.h
@@ -31,14 +31,26 @@
 
 class FilCount{
 private:
-    char *filePath;
+    std::string _filePath;
     FILE *GCode;
     double totalSize;
 public:
-    FilCount(const char *filePath) throw (std::string);
+    FilCount(std::string filePath) throw (std::string);
     ~FilCount();
+    /*=================== getTotalSize() ==========================
+        Return used filament in milimeters.
+      =============================================================*/
     double getTotalSize();
+
+    /*=================== getFilePath() ===========================
+        Return the file path associated with the class.
+      =============================================================*/
     std::string getFilePath();
+
+    /*=================== getTimeInSeconds(double speed) ==========
+        Given speed (in mm/s), returns the aproximated time
+        of the print job.
+      =============================================================*/
     long getTimeInSeconds(double speed);
 };
 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic