実戦プロジェクト--オンラインOJシステム(1)

14436 ワード

プロジェクト要件
シミュレーションバックルはオンラインコンパイラを実現します.
基本フレームワーク
  • オンラインコンパイラはウェブページのコードの内容をサーバーに提出して、コンパイルして、運行して、
  • を提出します
  • 題目管理現在のシステム上のすべてのOJ題目を管理し、ウェブページと対話し、すべての題目リスト及びある題目詳細
  • を取得することができる.
    コード実装
    #pragma once
    #include<stdint.h>
    #include<iostream>
    #include<cstdlib>
    #include<string>
    #include<sys/time.h>
    
    // 
    class TimeUtil{
    	static int64_t TimeStamp(){
    		// 
    		struct TimeUtil tv;// 
    		::gettimeofday(&tv,NULL);
    		return tv.tv_sec;	
    	}
    	static int64_t TimeStampMS(){
    		// 
    		struct TimeUtil tv;
    		::gettimeofday(&tv,NULL);
    		return tv.tv_sec*1000+tv.tv_usec/1000;
    	}
    };
    
    // 
    //[I155089459 UTIL.hpp:31] hello
    //[I... .  ...: ]  
    // 
    //1.FATAL  
    //2.ERROR  
    //3.WARNING  
    //4.INFO   
    
    enum Level{
    	FATAL,
    	ERROR,
    	WARNING,
    	INFO,
    };
    // 
    inline std::ostream& Log(Level level,const std::string& file_name,int line_num){
    	std::string prefix="[";
    	if(level ==  INFO){
    		prefix += "I";
    	}else if(level == WARNING){
    		prefix += "W";
    	}else if(level == ERROR){
    		prefix += "E";
    	}else if(level == FATAL){
    		prefix += "F";
    	}
    	prefix += std::to_string(TimeUtil::TimeStamp());
    	prefix += " ";
    	prefix += file_name;
    	prefix += std::to_string(line_num);
    	prefix += "]";
    	std::cout << prefix;
    	return std::cout;
    }
    
    #define LOG (level) Log(__FILE__,__LINE__);
    // 
    class FileUtil{
    	public:
    		// 
    		static bool Read(const std::string& file_path,std::string* content){
    			content->clear();
    			std::ifstream file(file_path.c_str());
    			if(!file.is_open()){
    				return false;
    			}
    			std::string line;
    			while(std::getline(file,line)){
    				*content += line + "
    "
    ; } file.close(); return true; } // static bool Write(const std::string& file_path,std::string* content){ std::ofstream file(file_path.c_str()); if(!file.is_open()){ return false; } file.write(content.c_str(),content.size()); file.close(); return true; } };