initial commit
This commit is contained in:
commit
e6a5581cea
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
13
.github/workflows/ci.yml
vendored
Normal file
13
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
name: ci
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Build
|
||||||
|
run: mkdir build && cd build && ../cbuild
|
279
.gitignore
vendored
Normal file
279
.gitignore
vendored
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
# Prerequisites
|
||||||
|
*.d
|
||||||
|
|
||||||
|
# Compiled Object files
|
||||||
|
*.slo
|
||||||
|
*.lo
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Compiled Dynamic libraries
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Fortran module files
|
||||||
|
*.mod
|
||||||
|
*.smod
|
||||||
|
|
||||||
|
# Compiled Static libraries
|
||||||
|
*.lai
|
||||||
|
*.la
|
||||||
|
*.a
|
||||||
|
*.lib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Bb]uild/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
|
||||||
|
# Visual Studio 2015 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUNIT
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# DNX
|
||||||
|
project.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_i.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# JustCode is a .NET coding add-in
|
||||||
|
.JustCode
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/packages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/packages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/packages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignoreable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
node_modules/
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
.idea/
|
||||||
|
*.sln.iml
|
25
CMakeLists.txt
Normal file
25
CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# CMakeList.txt : CMake project for ImageMan, include source and define
|
||||||
|
# project specific logic here.
|
||||||
|
#
|
||||||
|
cmake_minimum_required(VERSION 3.19)
|
||||||
|
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS 3.19)
|
||||||
|
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
project(kc
|
||||||
|
VERSION
|
||||||
|
1.0
|
||||||
|
DESCRIPTION
|
||||||
|
"C++ scratchpad"
|
||||||
|
LANGUAGES
|
||||||
|
CXX)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
|
add_subdirectory(libs/library)
|
||||||
|
add_subdirectory(src)
|
15
libs/library/CMakeLists.txt
Normal file
15
libs/library/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
set(LIB_NAME "library")
|
||||||
|
|
||||||
|
add_library(${LIB_NAME} src/lib.cpp)
|
||||||
|
|
||||||
|
# We need this directory, and users of our library will need it too
|
||||||
|
target_include_directories(${LIB_NAME} PUBLIC ../../include PRIVATE ./include)
|
||||||
|
|
||||||
|
# All users of this library will need at least C++11
|
||||||
|
target_compile_features(${LIB_NAME} PUBLIC cxx_std_17)
|
||||||
|
|
||||||
|
# IDEs should put the headers in a nice place
|
||||||
|
source_group(
|
||||||
|
TREE "${PROJECT_SOURCE_DIR}/include"
|
||||||
|
PREFIX "Header Files"
|
||||||
|
FILES ${HEADER_LIST})
|
3
libs/library/include/library/lib.hpp
Normal file
3
libs/library/include/library/lib.hpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
7
libs/library/src/lib.cpp
Normal file
7
libs/library/src/lib.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "library/lib.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void example_func() {
|
||||||
|
cout << "hello from a func" << endl;
|
||||||
|
}
|
10
src/CMakeLists.txt
Normal file
10
src/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
add_executable(kc main.cpp)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
Boost
|
||||||
|
GIT_REPOSITORY https://github.com/boostorg/boost.git
|
||||||
|
GIT_TAG boost-1.82.0
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(Boost)
|
||||||
|
|
||||||
|
target_link_libraries(kc PRIVATE Boost::program_options Boost::log Boost::date_time Boost::filesystem Boost::system Boost::thread Boost::log_setup Boost::chrono Boost::atomic library)
|
92
src/config.cpp
Normal file
92
src/config.cpp
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#include <memory>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
|
void on_age(int age)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "On age: " << age;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<po::variables_map> init_config(int argc, const char *argv[])
|
||||||
|
{
|
||||||
|
int def;
|
||||||
|
po::options_description desc("Allowed options");
|
||||||
|
desc.add_options()
|
||||||
|
("help", "produce help message")
|
||||||
|
("compression,c", po::value<int>(), "set compression level")
|
||||||
|
("def,d", po::value<int>(&def)->default_value(10), "set def level")
|
||||||
|
("abc", po::value<int>()->default_value(25), "set abc level")
|
||||||
|
("phone", po::value<std::vector<std::string>>()->multitoken()->zero_tokens()->composing(), "Phone")
|
||||||
|
("age,a", po::value<int>()->notifier(on_age), "age")
|
||||||
|
("config", po::value<std::string>(), "Config file")
|
||||||
|
;
|
||||||
|
|
||||||
|
po::options_description other("Other");
|
||||||
|
desc.add_options()
|
||||||
|
("other-option,o", po::value<int>(), "another option")
|
||||||
|
;
|
||||||
|
|
||||||
|
// Hidden options, will be allowed both on command line and
|
||||||
|
// in config file, but will not be shown to the user.
|
||||||
|
po::options_description hidden("Hidden options");
|
||||||
|
hidden.add_options()
|
||||||
|
("input-file", po::value< vector<string> >(), "input file");
|
||||||
|
|
||||||
|
po::positional_options_description p;
|
||||||
|
p.add("phone", -1);
|
||||||
|
|
||||||
|
po::options_description cmdline_options;
|
||||||
|
cmdline_options.add(desc).add(other).add(hidden);
|
||||||
|
|
||||||
|
po::options_description config_file_options;
|
||||||
|
config_file_options.add(desc).add(hidden);
|
||||||
|
|
||||||
|
po::options_description visible("Allowed options");
|
||||||
|
visible.add(desc).add(other);
|
||||||
|
|
||||||
|
////////////
|
||||||
|
// PARSE
|
||||||
|
////////////
|
||||||
|
|
||||||
|
auto vm = make_shared<po::variables_map>();
|
||||||
|
po::store(po::command_line_parser(argc, argv)
|
||||||
|
.options(desc)
|
||||||
|
.positional(p)
|
||||||
|
.run(),
|
||||||
|
*vm);
|
||||||
|
|
||||||
|
if (vm->count("config"))
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Attempting file config load";
|
||||||
|
std::ifstream ifs{(*vm)["config"].as<std::string>().c_str()};
|
||||||
|
if (ifs) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "File opened, loading...";
|
||||||
|
po::store(po::parse_config_file(ifs, config_file_options), *vm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
po::notify(*vm);
|
||||||
|
|
||||||
|
if (vm->count("help")) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << desc;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm->count("compression")) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Compression level was set to " << (*vm)["compression"].as<int>() << ".";
|
||||||
|
} else {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Compression level was not set.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm->count("def")) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "def level was set to " << (*vm)["def"].as<int>() << ".";
|
||||||
|
} else {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "def level was not set.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return vm;
|
||||||
|
}
|
32
src/logging.cpp
Normal file
32
src/logging.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include <boost/log/core.hpp>
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
#include <boost/log/expressions.hpp>
|
||||||
|
#include <boost/log/utility/setup/file.hpp>
|
||||||
|
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||||
|
#include <boost/log/utility/setup/console.hpp>
|
||||||
|
|
||||||
|
namespace logging = boost::log;
|
||||||
|
namespace src = boost::log::sources;
|
||||||
|
namespace sinks = boost::log::sinks;
|
||||||
|
namespace keywords = boost::log::keywords;
|
||||||
|
|
||||||
|
void init_logging()
|
||||||
|
{
|
||||||
|
logging::register_simple_formatter_factory<logging::trivial::severity_level, char>("Severity");
|
||||||
|
|
||||||
|
logging::add_file_log
|
||||||
|
(
|
||||||
|
keywords::file_name = "kc_%N.log",
|
||||||
|
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
|
||||||
|
keywords::format = "[%TimeStamp%] [%ThreadID%] [%Severity%] %Message%"
|
||||||
|
);
|
||||||
|
|
||||||
|
logging::add_console_log(std::cout, boost::log::keywords::format = "[%TimeStamp%] [%Severity%] >> %Message%");
|
||||||
|
|
||||||
|
logging::core::get()->set_filter
|
||||||
|
(
|
||||||
|
logging::trivial::severity >= logging::trivial::info
|
||||||
|
);
|
||||||
|
|
||||||
|
logging::add_common_attributes();
|
||||||
|
}
|
32
src/main.cpp
Normal file
32
src/main.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "logging.cpp"
|
||||||
|
#include "config.cpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, const char *argv[]) {
|
||||||
|
try{
|
||||||
|
init_logging();
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "================================";
|
||||||
|
BOOST_LOG_TRIVIAL(info) << " kc";
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "================================";
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "starting up....";
|
||||||
|
|
||||||
|
auto config = init_config(argc, argv);
|
||||||
|
|
||||||
|
if(config)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "hello world";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const po::error &ex)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(error) << ex.what();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user