Jetson Inference
DNN Vision Library
csvWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __CSV_WRITER_H_
24 #define __CSV_WRITER_H_
25 
26 #include <iostream>
27 #include <fstream>
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <errno.h>
32 
33 #include <string>
34 #include <vector>
35 #include <iostream>
36 
37 
42 class csvWriter
43 {
44 public:
45  // constructor/destructor
46  csvWriter( const char* filename, const char* delimiter=", " );
47  ~csvWriter();
48 
49  // open
50  inline static csvWriter* Open( const char* filename, const char* delimiter=", " );
51 
52  // close/flush
53  inline void Close();
54  inline void Flush();
55 
56  // is open or closed
57  inline bool IsOpen() const;
58  inline bool IsClosed() const;
59 
60  // end the current line
61  inline void EndLine();
62 
63  // write value
64  template<typename T>
65  inline csvWriter& Write( const T& value );
66 
67  // write values
68  template<typename T, typename... Args>
69  inline csvWriter& Write( const T& value, const Args&... args );
70 
71  // write values and end the line
72  template<typename T, typename... Args>
73  inline csvWriter& WriteLine( const T& value, const Args&... args );
74 
75  // stream insertion
76  template<typename T>
77  inline csvWriter& operator << ( const T& value );
78 
79  // stream manipulators
80  inline csvWriter& operator << ( csvWriter& (*value)(csvWriter&) );
81 
82  // set default delimiter
83  inline void SetDelimiter( const char* delimiters );
84 
85  // retrieve default delimiter
86  inline const char* GetDelimiter() const;
87 
88  // retrieve the filename
89  inline const char* GetFilename() const;
90 
91 private:
92  std::ofstream mFile;
93  std::string mFilename;
94  std::string mDelimiter;
95  bool mNewLine;
96 };
97 
98 
103 namespace csv
104 {
105  inline static csvWriter& endl( csvWriter& file );
106  inline static csvWriter& flush( csvWriter& file );
107 }
108 
109 
110 // internal functions
111 #include "csvWriter.hpp"
112 
113 #endif
114 
csvWriter::EndLine
void EndLine()
Definition: csvWriter.hpp:104
csvWriter::IsClosed
bool IsClosed() const
Definition: csvWriter.hpp:98
csv
csv stream manipulators
Definition: csvWriter.h:103
csvWriter::Write
csvWriter & Write(const T &value)
Definition: csvWriter.hpp:112
csvWriter::Flush
void Flush()
Definition: csvWriter.hpp:86
csvWriter::GetDelimiter
const char * GetDelimiter() const
Definition: csvWriter.hpp:162
csvWriter::Open
static csvWriter * Open(const char *filename, const char *delimiter=", ")
Definition: csvWriter.hpp:59
csvWriter::WriteLine
csvWriter & WriteLine(const T &value, const Args &... args)
Definition: csvWriter.hpp:134
csvWriter::GetFilename
const char * GetFilename() const
Definition: csvWriter.hpp:168
csvWriter::Close
void Close()
Definition: csvWriter.hpp:76
csvWriter::SetDelimiter
void SetDelimiter(const char *delimiters)
Definition: csvWriter.hpp:156
csvWriter::csvWriter
csvWriter(const char *filename, const char *delimiter=", ")
Definition: csvWriter.hpp:32
csvWriter
csvWriter
Definition: csvWriter.h:42
csvWriter::operator<<
csvWriter & operator<<(const T &value)
Definition: csvWriter.hpp:144
csvWriter::~csvWriter
~csvWriter()
Definition: csvWriter.hpp:52
csvWriter.hpp
csvWriter::IsOpen
bool IsOpen() const
Definition: csvWriter.hpp:92