summaryrefslogtreecommitdiff
path: root/fluid/io/Code_Writer.h
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2025-03-16 17:16:12 -0400
committerGitHub <noreply@github.com>2025-03-16 17:16:12 -0400
commit51a55bc73660f64e8f4b32b8b4d3858f2a786f7b (patch)
tree122ad9f838fcf8f61ed7cf5fa031e8ed69817e10 /fluid/io/Code_Writer.h
parent13a7073a1e007ce5b71ef70bced1a9b15158820d (diff)
Fluid: restructuring and rejuvenation of the source code.
* Add classes for application and project * Removed all globals from Fluid.h * Extracting args and project history into their own classes * Moving globals into Application class * Initialize values inside headers for some classes. * Undo functionality wrapped in a class inside Project. * File reader and writer are now linked to a project. * Avoid global project access * Nodes (former Types) will be managed by a new Tree class. * Removed static members (hidden globals) form Node/Fl_Type. * Adding Tree iterator. * Use nullptr instead of 0, NULL, or 0L * Renamed Fl_..._Type to ..._Node, FL_OVERRIDE -> override * Renaming ..._type to ...::prototype * Splitting Widget Panel into multiple files. * Moved callback code into widget panel file. * Cleaning up Fluid_Image -> Image_asset * Moving Fd_Snap_Action into new namespace fld::app::Snap_Action etc. * Moved mergeback into proj folder. * `enum ID` is now `enum class Type`.
Diffstat (limited to 'fluid/io/Code_Writer.h')
-rw-r--r--fluid/io/Code_Writer.h53
1 files changed, 30 insertions, 23 deletions
diff --git a/fluid/io/Code_Writer.h b/fluid/io/Code_Writer.h
index b4a6518b4..ca23ca0a2 100644
--- a/fluid/io/Code_Writer.h
+++ b/fluid/io/Code_Writer.h
@@ -1,7 +1,7 @@
//
-// Code output routines for the Fast Light Tool Kit (FLTK).
+// Fluid C++ Code Writer header for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2021 by Bill Spitzak and others.
+// Copyright 1998-2025 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -22,43 +22,50 @@
#include <stdarg.h>
#include <stdio.h>
#include <string>
+#include <set>
+#include <map>
-class Fl_Type;
+class Node;
struct Fd_Identifier_Tree;
struct Fd_Text_Tree;
struct Fd_Pointer_Tree;
int is_id(char c);
-int write_strings(const std::string &filename);
namespace fld {
+
+class Project;
+
namespace io {
class Code_Writer
{
-protected:
+private:
+ /// Link Code_Writer class to the project.
+ Project &proj_;
+
/// file pointer for the C++ code file
- FILE *code_file;
+ FILE *code_file = nullptr;
/// file pointer for the C++ header file
- FILE *header_file;
+ FILE *header_file = nullptr;
/// tree of unique but human-readable identifiers
- Fd_Identifier_Tree* id_root;
+ std::map<std::string, void*> unique_id_list { };
/// searchable text tree for text that is only written once to the header file
- Fd_Text_Tree *text_in_header;
+ std::set<std::string> text_in_header { };
/// searchable text tree for text that is only written once to the code file
- Fd_Text_Tree *text_in_code;
+ std::set<std::string> text_in_code { };
/// searchable tree for pointers that are only written once to the code file
- Fd_Pointer_Tree *ptr_in_code;
+ std::set<void*> ptr_in_code { };
/// crc32 for blocks of text written to the code file
- unsigned long block_crc_;
+ unsigned long block_crc_ = 0;
/// if set, we are at the start of a line and can ignore leading spaces in crc
- bool block_line_start_;
+ bool block_line_start_ = true;
/// expanding buffer for vsnprintf
- char *block_buffer_;
+ char *block_buffer_ = nullptr;
/// size of expanding buffer for vsnprintf
- int block_buffer_size_;
+ int block_buffer_size_ = 0;
void crc_add(const void *data, int n=-1);
int crc_printf(const char *format, ...);
@@ -68,19 +75,19 @@ protected:
public:
/// current level of source code indentation
- int indentation;
+ int indentation = 0;
/// set if we write abbreviated file for the source code previewer
/// (disables binary data blocks, for example)
- bool write_codeview;
+ bool write_codeview = false;
/// silly thing to prevent declaring unused variables:
/// When this symbol is on, all attempts to write code don't write
/// anything, but set a variable if it looks like the variable "o" is used:
- int varused_test;
+ int varused_test = 0;
/// set to 1 if varused_test found that a variable is actually used
- int varused;
+ int varused = 0;
public:
- Code_Writer();
+ Code_Writer(Project &proj);
~Code_Writer();
const char* unique_id(void* o, const char*, const char*, const char*);
/// Increment source code indentation level.
@@ -102,14 +109,14 @@ public:
void write_h(const char*, ...) __fl_attr((__format__ (__printf__, 2, 3)));
void write_hc(const char *, int, const char*, const char*);
void write_c_indented(const char *textlines, int inIndent, char inTrailwWith);
- Fl_Type* write_static(Fl_Type* p);
- Fl_Type* write_code(Fl_Type* p);
+ Node* write_static(Node* p);
+ Node* write_code(Node* p);
int write_code(const char *cfile, const char *hfile, bool to_codeview=false);
void write_public(int state); // writes pubic:/private: as needed
void tag(int type, unsigned short uid);
- static unsigned long block_crc(const void *data, int n=-1, unsigned long in_crc=0, bool *inout_line_start=NULL);
+ static unsigned long block_crc(const void *data, int n=-1, unsigned long in_crc=0, bool *inout_line_start=nullptr);
};
} // namespace io