diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 5b79a5415be450374d4fd7937805c31124ee120f..0000000000000000000000000000000000000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -build/ -.cache/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index e03f45162be44af9894e33d14b09e82ef97db134..0000000000000000000000000000000000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "lldb", - "request": "launch", - "name": "Debug", - "program": "${workspaceFolder}/build/src/lab0_debug", - "args": [ - "-t", - ], - "cwd": "${workspaceFolder}" - } - ] -} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 7386a5a775a373abc65aca67a7a7bd6ce515aecf..0000000000000000000000000000000000000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.5.0) -project(stl_debug VERSION 0.1.0 LANGUAGES C CXX) - -set(CMAKE_CXX_STANDARD 17) - -set(default_build_type "Debug") - -INCLUDE_DIRECTORIES( - include -) - -add_subdirectory(src) - diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d2562b61c11bc1d9b2d18ebf0cf886681c32975a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +- Lab0 已经发布 `git checkout lab0` \ No newline at end of file diff --git a/include/Human.hpp b/include/Human.hpp deleted file mode 100644 index 2a307bd63112b6ef48417d28182e339867937cb4..0000000000000000000000000000000000000000 --- a/include/Human.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include -class Human -{ -private: - /* data */ - std::string name_; - int age_; -public: - explicit Human(int age, const std::string name = "") : name_(name), age_(age) {}; - virtual ~Human(); - virtual std::string print() const; - -}; diff --git a/include/Student.hpp b/include/Student.hpp deleted file mode 100644 index c461ff1d5c23cb45a4c9c8654b651d02a955410c..0000000000000000000000000000000000000000 --- a/include/Student.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Human.hpp" -#include - -class Student : public Human -{ -private: - /* data */ - std::string school_; -public: - Student() = delete; - explicit Student(int age, const std::string name = "", const std::string school = "") : Human(age, name), school_(school) {}; - virtual ~Student() override; - virtual std::string print() const override; -}; \ No newline at end of file diff --git a/include/logging.hpp b/include/logging.hpp deleted file mode 100644 index 032e8d465291742ed90af66975989d2baf4811e5..0000000000000000000000000000000000000000 --- a/include/logging.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef LOGGING_HPP -#define LOGGING_HPP - -#include -#include -#include - -enum LogLevel -{ - DEBUG = 0, - INFO, - WARNING, - ERROR -}; -struct LocationInfo -{ - LocationInfo(std::string file, int line, const char *func) : file_(file), line_(line), func_(func) {} - ~LocationInfo() = default; - - std::string file_; - int line_; - const char *func_; -}; -class LogStream; -class LogWriter; - -class LogWriter -{ -public: - LogWriter(LocationInfo location, LogLevel loglevel) - : location_(location), log_level_(loglevel) - { - char *logv = std::getenv("LOGV"); - if (logv) - { - std::string string_logv = logv; - env_log_level = std::stoi(logv); - } - else - { - env_log_level = 4; - } - }; - - void operator<(const LogStream &stream); - -private: - void output_log(const std::ostringstream &g); - LocationInfo location_; - LogLevel log_level_; - int env_log_level; -}; - -class LogStream -{ -public: - template - LogStream &operator<<(const T &val) noexcept - { - sstream_ << val; - return *this; - } - - friend class LogWriter; - -private: - std::stringstream sstream_{}; -}; - -std::string level2string(LogLevel level); -std::string get_short_name(const char *file_path); - -#define __FILESHORTNAME__ get_short_name(__FILE__) -#define LOG_IF(level) \ - LogWriter(LocationInfo(__FILESHORTNAME__, __LINE__, __FUNCTION__), level) < LogStream() -#define LOG(level) LOG_##level -#define LOG_DEBUG LOG_IF(DEBUG) -#define LOG_INFO LOG_IF(INFO) -#define LOG_WARNING LOG_IF(WARNING) -#define LOG_ERROR LOG_IF(ERROR) - -#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 722da0930f6369e8ca428ce8099f3a116d5a551c..0000000000000000000000000000000000000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_executable( - lab0_debug main.cpp Human.cpp Student.cpp logging.cpp -) \ No newline at end of file diff --git a/src/Human.cpp b/src/Human.cpp deleted file mode 100644 index bc1b993bb47bf02b172af7ebcd1663d5522ea913..0000000000000000000000000000000000000000 --- a/src/Human.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Human.hpp" -#include -#include - -Human::~Human() { - printf("Human destructor called\n"); -} - -std::string Human::print() const { - std::string res; - std::stringstream ss; - ss << "My name is " << name_ << " and I am " << age_ << " years old\n"; - ss >> res; - return res; -} \ No newline at end of file diff --git a/src/Student.cpp b/src/Student.cpp deleted file mode 100644 index c7576ea54718fa6260dee6d44d2558d2059e1cc9..0000000000000000000000000000000000000000 --- a/src/Student.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "Student.hpp" -#include "Human.hpp" -#include "cstring" -#include -#include - -Student::~Student() { - printf("Student destructor called\n"); -} - -std::string Student::print() const { - std::string res; - std::stringstream ss; - ss << Human::print(); - ss << "I'm from " << school_ << "\n"; - ss >> res; - return res; -} \ No newline at end of file diff --git a/src/logging.cpp b/src/logging.cpp deleted file mode 100644 index 9d508956a1b2b051adfa19da833bb6ad9a3dec13..0000000000000000000000000000000000000000 --- a/src/logging.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "logging.hpp" - -void LogWriter::operator<(const LogStream &stream) { - std::ostringstream msg; - msg << stream.sstream_.rdbuf(); - output_log(msg); -} - -void LogWriter::output_log(const std::ostringstream &msg) { - if (log_level_ >= env_log_level) - std::cout << "[" << level2string(log_level_) << "] " - << "(" << location_.file_ - << ":" << location_.line_ - << "L "<< location_.func_<<")" - << msg.str() << std::endl; - -} -std::string level2string(LogLevel level) { - switch (level) - { - case DEBUG: - return "DEBUG"; - - case INFO: - return "INFO"; - - case WARNING: - return "WARNING"; - - case ERROR: - return "ERROR"; - - default: - return ""; - } -} -std::string get_short_name(const char * file_path) { - std::string short_file_path = file_path; - int index = short_file_path.find_last_of('/'); - - return short_file_path.substr(index+1); -} diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 14e5a6ccbfb882b82a0c39713501f3ba707cf679..0000000000000000000000000000000000000000 --- a/src/main.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include "Human.hpp" -#include "Student.hpp" -#include "logging.hpp" -#include - -class check{ - public: - explicit check(Student* student){ - printf("Student object created\n"); - } -}; - -int main(int argc, char** argv){ - if(argc == 1 || std::string(argv[1]) != "-t"){ - std::cerr << "error: invalid argument\n"; - exit(-1); - } - printf("Hello, from stl_debug!\n"); - std::vector vec; - Human human(25, "John Doe"); - Student student(20, "Jane Doe", "MIT"); - vec.push_back(&human); - vec.push_back(&student); - for (const auto& h : vec) { - std::cout << h->print(); - } - // auto student1 = new Student(); //TODO: Error 1 : why? - auto student1 = static_cast(vec.back()); - // check check1 = check(student); //TODO: Error 2 : why? - check check1 = check(student1); - // LOG(DEBUG) << student1->print(); - // LOG(WARNING) << human.print(); - - // std::list list; - // list.push_back(1); - // for(auto i: list){ - // list.remove(i); - // } - return 0; -}