Skip to content

Commit 05fef53

Browse files
committed
Removed --identifier and --headerfile command line option from demo_helloworld example. For issue #58
1 parent 3c7388d commit 05fef53

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

README.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ Hello World!
150150
### Command:
151151

152152
```
153-
bin2cpp.exe --file=helloworld.html --output=.\outdir --headerfile=generated_helloworld.h
154-
--identifier=HelloWorldHtml --chunksize=50
153+
bin2cpp.exe --file=helloworld.html --output=.\outdir
155154
```
156155

157156

@@ -161,13 +160,13 @@ bin2cpp.exe --file=helloworld.html --output=.\outdir --headerfile=generated_hell
161160
bin2cpp v3.0.0 - Convert binary files into C++ source code.
162161
Copyright (C) 2013-2021 end2endzone.com. All rights reserved.
163162
bin2cpp is open source software, see http://github.com/end2endzone/bin2cpp
164-
Embedding "helloworld.html" using chunks of 50 bytes...
165-
Writing file ".\outdir\generated_helloworld.h"...
166-
Writing file ".\outdir\generated_helloworld.cpp"...
163+
Embedding "helloworld.html"...
164+
Writing file ".\outdir\helloworld.h"...
165+
Writing file ".\outdir\helloworld.cpp"...
167166
```
168167

169168

170-
### Output file: generated_helloworld.h
169+
### Output file: helloworld.h
171170

172171
```cpp
173172
/**
@@ -177,8 +176,8 @@ Writing file ".\outdir\generated_helloworld.cpp"...
177176
* Source code for file 'helloworld.html', last modified 1548537787.
178177
* Do not modify this file.
179178
*/
180-
#ifndef GENERATED_HELLOWORLD_H
181-
#define GENERATED_HELLOWORLD_H
179+
#ifndef HELLOWORLD_H
180+
#define HELLOWORLD_H
182181

183182
#include <stddef.h>
184183

@@ -197,14 +196,14 @@ namespace bin2cpp
197196
virtual bool save(const char * filename) const = 0;
198197
};
199198
#endif //BIN2CPP_EMBEDDEDFILE_CLASS
200-
const File & getHelloWorldHtmlFile();
199+
const File & getHelloworldhtmlFile();
201200
}; //bin2cpp
202201

203-
#endif //GENERATED_HELLOWORLD_H
202+
#endif //HELLOWORLD_H
204203
```
205204

206205

207-
### Output file: generated_helloworld.cpp
206+
### Output file: helloworld.cpp
208207

209208
```cpp
210209
/**
@@ -217,17 +216,17 @@ namespace bin2cpp
217216
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
218217
#define _CRT_SECURE_NO_WARNINGS
219218
#endif
220-
#include "generated_helloworld.h"
219+
#include "helloworld.h"
221220
#include <string> //for std::string
222221
#include <iostream>
223222
#include <fstream> //for ofstream
224223
namespace bin2cpp
225224
{
226-
class HelloWorldHtmlFile : public virtual bin2cpp::File
225+
class HelloworldhtmlFile : public virtual bin2cpp::File
227226
{
228227
public:
229-
HelloWorldHtmlFile() { build(); }
230-
virtual ~HelloWorldHtmlFile() {}
228+
HelloworldhtmlFile() { build(); }
229+
virtual ~HelloworldhtmlFile() {}
231230
virtual size_t getSize() const { return 238; }
232231
virtual const char * getFileName() const { return "helloworld.html"; }
233232
virtual const char * getFilePath() const { return getFileName(); }
@@ -236,15 +235,12 @@ namespace bin2cpp
236235
{
237236
mBuffer.clear();
238237
mBuffer.reserve(getSize()); //allocate all required memory at once to prevent reallocations
239-
mBuffer.append("<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta", 50);
240-
mBuffer.append(" charset=\"utf-8\">\r\n <meta name=\"viewport\" content", 50);
241-
mBuffer.append("=\"width=device-width, initial-scale=1, user-scalab", 50);
242-
mBuffer.append("le=yes\">\r\n <title>Hello World!</title>\r\n</head>\r\n", 50);
238+
mBuffer.append("<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"utf-8\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=yes\">\r\n <title>Hello World!</title>\r\n</head>\r\n", 200);
243239
mBuffer.append("<body>\r\nHello World!\r\n</body>\r\n</html>", 38);
244240
}
245241
virtual bool save(const char * filename) const
246242
{
247-
std::ofstream f(filename, std::ios::out | std::ios::binary);
243+
std::ofstream f(filename, std::ios::out | std::ios::binary | std::ios::trunc);
248244
if (f.fail()) return false;
249245
size_t fileSize = getSize();
250246
const char * buffer = getBuffer();
@@ -255,7 +251,7 @@ namespace bin2cpp
255251
private:
256252
std::string mBuffer;
257253
};
258-
const File & getHelloWorldHtmlFile() { static HelloWorldHtmlFile _instance; return _instance; }
254+
const File & getHelloworldhtmlFile() { static HelloworldhtmlFile _instance; return _instance; }
259255
}; //bin2cpp
260256
```
261257

@@ -268,12 +264,13 @@ At runtime, show file properties and save/export data back to a file.
268264
#include <stdio.h>
269265
#include <string>
270266
#include <iostream>
271-
#include "generated_helloworld.h" //a single include file is all you need
267+
268+
#include "helloworld.h" //a single include file is all you need
272269

273270
int main(int argc, char* argv[])
274271
{
275272
//get a reference to the embedded file
276-
const bin2cpp::File & resource = bin2cpp::getHelloWorldHtmlFile();
273+
const bin2cpp::File & resource = bin2cpp::getHelloworldhtmlFile();
277274

278275
//print information about the file.
279276
std::cout << "Embedded file '" << resource.getFileName() << "' is " << resource.getSize() << " bytes long.\n";

samples/demo_helloworld/CMakeLists.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
set(GENERATED_TEST_FILES
2-
${CMAKE_CURRENT_BINARY_DIR}/generated_helloworld.h
3-
${CMAKE_CURRENT_BINARY_DIR}/generated_helloworld.cpp
2+
${CMAKE_CURRENT_BINARY_DIR}/helloworld.h
3+
${CMAKE_CURRENT_BINARY_DIR}/helloworld.cpp
44
)
55

66
add_custom_command( OUTPUT ${GENERATED_TEST_FILES}
77
# Execute bin2cpp generator
88
COMMAND $<TARGET_FILE:bin2cpp>
99
--file=${CMAKE_CURRENT_SOURCE_DIR}/helloworld.html
1010
--output=${CMAKE_CURRENT_BINARY_DIR}
11-
--headerfile=generated_helloworld.h
12-
--identifier=HelloWorldHtml
13-
--chunksize=50
1411
)
1512

1613
# Show all generated files in a common folder
@@ -19,7 +16,7 @@ source_group("Generated Files" FILES ${GENERATED_TEST_FILES})
1916
include_directories(${CMAKE_CURRENT_BINARY_DIR})
2017

2118
add_executable(demo_helloworld
22-
helloworld.cpp
19+
demo_helloworld.cpp
2320
${GENERATED_TEST_FILES}
2421
)
2522

samples/demo_helloworld/helloworld.cpp renamed to samples/demo_helloworld/demo_helloworld.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#include <string>
33
#include <iostream>
44

5-
#include "generated_helloworld.h" //a single include file is all you need
5+
#include "helloworld.h" //a single include file is all you need
66

77
int main(int argc, char* argv[])
88
{
99
//get a reference to the embedded file
10-
const bin2cpp::File & resource = bin2cpp::getHelloWorldHtmlFile();
10+
const bin2cpp::File & resource = bin2cpp::getHelloworldhtmlFile();
1111

1212
//print information about the file.
1313
std::cout << "Embedded file '" << resource.getFileName() << "' is " << resource.getSize() << " bytes long.\n";

samples/demo_helloworld/helloworld.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ mkdir outdir 1>NUL 2>NUL
55

66
set path=%cd%\..\..\build\bin\Release;%cd%\..\..\build\bin\Debug;%PATH%
77

8-
bin2cpp.exe --file=helloworld.html --output=.\outdir --headerfile=generated_helloworld.h --identifier=HelloWorldHtml --chunksize=50
8+
bin2cpp.exe --file=helloworld.html --output=.\outdir
99

1010
pause

0 commit comments

Comments
 (0)