Class.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #if !defined(Class_HPP)
  2. #define Class_HPP
  3. #include "Util.hpp"
  4. #include "robin_hood.hpp"
  5. /*
  6. why hello there!
  7. i know most of this is bad, i honestly don't care too much because it's my first project. -yogurt
  8. */
  9. extern bool parser_exit;
  10. extern int32_t thread_count;
  11. class Class
  12. {
  13. public:
  14. //filled by setup() and build()
  15. string all_object_files, all_libraries, all_library_paths, all_include_paths;
  16. //user defined in .cate file
  17. string name, flags, out_name, out_dir, compiler, final_flags;
  18. vector<string> files, libraries, object_files, include_paths;
  19. //filled from build();
  20. robin_hood::unordered_set<string> library_paths;
  21. bool is_static; //only in library
  22. bool already_built = false, needs_rebuild = false;
  23. bool link = true, threading = false, smol = false;
  24. Class()
  25. {
  26. //these should be enough for most small/medium-sized projects
  27. name.reserve(16);
  28. files.reserve(32);
  29. object_files.reserve(32);
  30. libraries.reserve(8);
  31. library_paths.reserve(8);
  32. all_libraries.reserve(128);
  33. include_paths.reserve(32);
  34. threads.reserve(thread_count * 8);
  35. all_include_paths.reserve(256);
  36. all_libraries.reserve(8*16);
  37. all_object_files.reserve(32*16);
  38. all_library_paths.reserve(8*16);
  39. compiler.reserve(16);
  40. final_flags.reserve(32);
  41. out_name.reserve(32);
  42. flags.reserve(32);
  43. }
  44. virtual ~Class() {};
  45. virtual void build() = 0; //class defined
  46. void clean();
  47. void check(); //check if everything is okay
  48. void setup(); // set up directories and object files
  49. void object_setup(); //set up files and object files.
  50. void library_setup();
  51. void include_setup();
  52. void build_objects(); //build the objects
  53. void create_directories();
  54. //general and self-explanitory
  55. vector<string>& get_array_property(int32_t line, string& property);
  56. void clear_property(int32_t line, string& property);
  57. void add_to_property(int32_t line, string_view property, string_view value);
  58. void set_property(int32_t line, string& property, string& value);
  59. //threading
  60. void build_object(int32_t i);
  61. vector<std::thread>threads;
  62. string command_template;
  63. //other
  64. void smolize();
  65. inline void print_done(string_view name) {
  66. std::cout << GREEN "Done building \"" << name << "\"" COLOR_RESET "\n";
  67. }
  68. };
  69. #endif