initial skeleton
This commit is contained in:
commit
43561467ef
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 && ../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
|
26
CMakeLists.txt
Normal file
26
CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# 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(cppScratch
|
||||||
|
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(libs/dal)
|
||||||
|
add_subdirectory(src)
|
11
include/cppScratch/dal/dal.hpp
Normal file
11
include/cppScratch/dal/dal.hpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// ImageMan.h : Include file for standard system include files,
|
||||||
|
// or project specific include files.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <pqxx/pqxx>
|
||||||
|
|
||||||
|
void dal_func();
|
||||||
|
|
||||||
|
// TODO: Reference additional headers your program requires here.
|
12
include/cppScratch/test.hpp
Normal file
12
include/cppScratch/test.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// ImageMan.h : Include file for standard system include files,
|
||||||
|
// or project specific include files.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
// #include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
void example_func();
|
||||||
|
|
||||||
|
// TODO: Reference additional headers your program requires here.
|
24
libs/dal/CMakeLists.txt
Normal file
24
libs/dal/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
set(LIB_NAME "dal")
|
||||||
|
|
||||||
|
add_library(${LIB_NAME} src/lib.cpp src/secret.cpp)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
libpqxx
|
||||||
|
GIT_REPOSITORY https://github.com/jtv/libpqxx.git
|
||||||
|
GIT_TAG 7.7.5
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_MakeAvailable(libpqxx)
|
||||||
|
|
||||||
|
# We need this directory, and users of our library will need it too
|
||||||
|
target_include_directories(${LIB_NAME} PUBLIC ../../include PRIVATE ./include)
|
||||||
|
target_link_libraries(${LIB_NAME} PUBLIC pqxx)
|
||||||
|
|
||||||
|
# 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})
|
5
libs/dal/include/dal/secret.hpp
Normal file
5
libs/dal/include/dal/secret.hpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void dal_secret();
|
85
libs/dal/src/lib.cpp
Normal file
85
libs/dal/src/lib.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#include "cppScratch/dal/dal.hpp"
|
||||||
|
#include "dal/secret.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void dal_func() {
|
||||||
|
cout << "hello from dal" << endl;
|
||||||
|
dal_secret();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Connect to the database. You can have multiple connections open
|
||||||
|
// at the same time, even to the same database.
|
||||||
|
pqxx::connection c;
|
||||||
|
std::cout << "Connected to " << c.dbname() << '\n';
|
||||||
|
|
||||||
|
// Start a transaction. A connection can only have one transaction
|
||||||
|
// open at the same time, but after you finish a transaction, you
|
||||||
|
// can start a new one on the same connection.
|
||||||
|
pqxx::work tx{c};
|
||||||
|
|
||||||
|
// Query data of two columns, converting them to std::string and
|
||||||
|
// int respectively. Iterate the rows.
|
||||||
|
for (auto [name, salary] : tx.query<std::string, int>(
|
||||||
|
"SELECT name, salary FROM employee ORDER BY name"))
|
||||||
|
{
|
||||||
|
std::cout << name << " earns " << salary << ".\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// For large amounts of data, "streaming" the results is more
|
||||||
|
// efficient. It does not work for all types of queries though.
|
||||||
|
//
|
||||||
|
// You can read fields as std::string_view here, which is not
|
||||||
|
// something you can do in most places. A string_view becomes
|
||||||
|
// meaningless when the underlying string ceases to exist. In this
|
||||||
|
// one situation, you can convert a field to string_view and it
|
||||||
|
// will be valid for just that one iteration of the loop. The next
|
||||||
|
// iteration may overwrite or deallocate its buffer space.
|
||||||
|
for (auto [name, salary] : tx.stream<std::string_view, int>(
|
||||||
|
"SELECT name, salary FROM employee"))
|
||||||
|
{
|
||||||
|
std::cout << name << " earns " << salary << ".\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute a statement, and check that it returns 0 rows of data.
|
||||||
|
// This will throw pqxx::unexpected_rows if the query returns rows.
|
||||||
|
std::cout << "Doubling all employees' salaries...\n";
|
||||||
|
tx.exec0("UPDATE employee SET salary = salary*2");
|
||||||
|
|
||||||
|
// Shorthand: conveniently query a single value from the database.
|
||||||
|
int my_salary = tx.query_value<int>(
|
||||||
|
"SELECT salary FROM employee WHERE name = 'Me'");
|
||||||
|
std::cout << "I now earn " << my_salary << ".\n";
|
||||||
|
|
||||||
|
// Or, query one whole row. This function will throw an exception
|
||||||
|
// unless the result contains exactly 1 row.
|
||||||
|
auto [top_name, top_salary] = tx.query1<std::string, int>(
|
||||||
|
R"(
|
||||||
|
SELECT name, salary
|
||||||
|
FROM employee
|
||||||
|
WHERE salary = max(salary)
|
||||||
|
LIMIT 1
|
||||||
|
)");
|
||||||
|
std::cout << "Top earner is " << top_name << " with a salary of "
|
||||||
|
<< top_salary << ".\n";
|
||||||
|
|
||||||
|
// If you need to access the result metadata, not just the actual
|
||||||
|
// field values, use the "exec" functions. Most of them return
|
||||||
|
// pqxx::result objects.
|
||||||
|
pqxx::result res = tx.exec("SELECT * FROM employee");
|
||||||
|
std::cout << "Columns:\n";
|
||||||
|
for (pqxx::row_size_type col = 0; col < res.columns(); ++col)
|
||||||
|
std::cout << res.column_name(col) << '\n';
|
||||||
|
|
||||||
|
// Commit the transaction. If you don't do this, the database will
|
||||||
|
// undo any changes you made in the transaction.
|
||||||
|
std::cout << "Making changes definite: ";
|
||||||
|
tx.commit();
|
||||||
|
std::cout << "OK.\n";
|
||||||
|
}
|
||||||
|
catch (std::exception const &e)
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR: " << e.what() << '\n';
|
||||||
|
}
|
||||||
|
}
|
8
libs/dal/src/secret.cpp
Normal file
8
libs/dal/src/secret.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "dal/secret.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void dal_secret()
|
||||||
|
{
|
||||||
|
cout << "secret shhh" << endl;
|
||||||
|
}
|
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>
|
8
libs/library/src/lib.cpp
Normal file
8
libs/library/src/lib.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "cppScratch/test.hpp"
|
||||||
|
#include "library/lib.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void example_func() {
|
||||||
|
cout << "hello from a func" << endl;
|
||||||
|
}
|
11
src/CMakeLists.txt
Normal file
11
src/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
add_executable(cppScratch main.cpp)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
json
|
||||||
|
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
||||||
|
GIT_TAG v3.11.2
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_MakeAvailable(json)
|
||||||
|
|
||||||
|
target_link_libraries(cppScratch PRIVATE nlohmann_json::nlohmann_json dal library)
|
10
src/main.cpp
Normal file
10
src/main.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "cppScratch/test.hpp"
|
||||||
|
#include "cppScratch/dal/dal.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
cout << "hello world" << endl;
|
||||||
|
dal_func();
|
||||||
|
example_func();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user