Renaming to scsl.

This commit is contained in:
Kyle Isom 2023-10-14 18:38:01 -07:00
parent dd696e2c1f
commit 05790a95fa
32 changed files with 133 additions and 123 deletions

View File

@ -21,7 +21,7 @@
#include "Arena.h"
namespace klib {
namespace scsl {
Arena::Arena()
@ -280,7 +280,7 @@ Arena::Destroy()
std::ostream &
operator<<(std::ostream &os, Arena &arena)
{
auto cursor = arena.NewCursor();
auto cursor = arena.Start();
char cursorString[33] = {0};
snprintf(cursorString, 32, "%#016llx",
(long long unsigned int) cursor);
@ -346,7 +346,7 @@ uint8_t &
Arena::operator[](size_t index)
{
if (index > this->size) {
#if defined(KLIB_DESKTOP_BUILD) and !defined(KLIB_NO_ASSERT)
#if defined(SCSL_DESKTOP_BUILD) and !defined(SCSL_NO_ASSERT)
throw std::range_error("index out of range");
#else
abort();
@ -356,4 +356,4 @@ Arena::operator[](size_t index)
}
} // namespace klib
} // namespace scsl

10
Arena.h
View File

@ -33,7 +33,7 @@
#endif
namespace klib {
namespace scsl {
/// \enum ArenaType
@ -55,7 +55,7 @@ enum class ArenaType
/// Arena is the class that implements a memory arena.
///
/// The Arena uses the concept of a cursor to point to memory in the arena. The
/// #NewCursor and #End methods return pointers to the start and end of the
/// #Start and #End methods return pointers to the start and end of the
/// arena memory.
///
/// The arena should be initialized with one of the Set methods (SetStatic,
@ -130,10 +130,10 @@ public:
/// \return Returns 0 on success and -1 on error.
int Open(const char *path);
/// NewCursor returns a pointer to the start of the memory in the arena.
/// Start returns a pointer to the start of the memory in the arena.
///
/// \return A pointer to the start of the arena memory.
uint8_t *NewCursor() const
uint8_t *Start() const
{ return this->store; }
/// End returns a pointer to the end of the arena memory.
@ -216,7 +216,7 @@ private:
std::ostream &operator<<(std::ostream &os, Arena &arena);
} // namespace klib
} // namespace scsl
#endif

View File

@ -13,7 +13,7 @@
#include "Buffer.h"
namespace klib {
namespace scsl {
/// The defaultCapacity for a new Buffer is a reasonably arbitrary starting
@ -330,7 +330,7 @@ uint8_t &
Buffer::operator[](size_t index)
{
if (index > this->length) {
#if defined(KLIB_DESKTOP_BUILD) and !defined(KLIB_NO_ASSERT)
#if defined(SCSL_DESKTOP_BUILD) and !defined(SCSL_NO_ASSERT)
throw std::range_error("array index out of bounds");
#else
abort();
@ -360,4 +360,4 @@ operator<<(std::ostream &os, const Buffer &buf)
}
} // namespace klib
} // namespace scsl

View File

@ -16,7 +16,7 @@
#include <cstdint>
namespace klib {
namespace scsl {
/// Buffer is a basic line buffer.
///
@ -211,7 +211,7 @@ std::ostream &operator<<(std::ostream &os, const Buffer &buf);
/// differ.
inline bool operator!=(const Buffer &lhs, const Buffer &rhs) { return !(lhs == rhs); };
} // namespace klib
} // namespace scsl
#endif // KGE_BUFFER_H

View File

@ -1,4 +1,4 @@
# Doxygen support for klib.
# Doxygen support for scsl.
find_package(Doxygen)
if (${DOXYGEN_FOUND})
@ -6,11 +6,11 @@ set(DOXYGEN_GENERATE_MAN YES)
set(DOXYGEN_GENERATE_LATEX YES)
#set(DOXYGEN_EXTRACT_ALL YES)
doxygen_add_docs(klib_docs
doxygen_add_docs(scsl_docs
${HEADER_FILES} ${SOURCE_FILES}
USE_STAMP_FILE)
add_dependencies(klib klib_docs)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc/klib)
add_dependencies(scsl scsl_docs)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc/scsl)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/man DESTINATION share)
endif ()

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.25)
project(klib LANGUAGES CXX
project(scsl LANGUAGES CXX
VERSION 0.1.0
DESCRIPTION "Kyle's C++ library")
DESCRIPTION "Shimmering Clarity Standard Library")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_VERBOSE_MAKEFILES TRUE)
@ -25,10 +25,10 @@ else ()
# nothing special for gcc at the moment
endif ()
endif ()
add_compile_definitions(DKLIB_DESKTOP_BUILD)
add_compile_definitions(KLIB_VERSION=${PROJECT_VERSION})
add_compile_definitions(SCSL_DESKTOP_BUILD)
add_compile_definitions(SCSL_VERSION=${PROJECT_VERSION})
set(HEADER_FILES klib.h
set(HEADER_FILES scsl.h
Arena.h
Buffer.h
Dictionary.h
@ -51,55 +51,59 @@ set(SOURCE_FILES
WinHelpers.cc)
if (APPLE)
add_library(klib
add_library(scsl
STATIC
${SOURCE_FILES} ${HEADER_FILES})
else ()
add_library(klib
add_library(scsl
STATIC
${SOURCE_FILES} ${HEADER_FILES})
endif()
add_executable(phonebook phonebook.cc)
target_link_libraries(phonebook klib)
target_link_libraries(phonebook scsl)
include(CTest)
enable_testing()
add_executable(tlv_test tlvTest.cc)
target_link_libraries(tlv_test klib)
target_link_libraries(tlv_test scsl)
add_test(tlvTest tlv_test)
add_executable(dictionary_test dictionaryTest.cc)
target_link_libraries(dictionary_test klib)
target_link_libraries(dictionary_test scsl)
add_test(dictionaryTest dictionary_test)
add_executable(buffer_test bufferTest.cc)
target_link_libraries(buffer_test klib)
target_link_libraries(buffer_test scsl)
add_test(bufferTest buffer_test)
add_executable(stringutil_test stringutil_test.cc)
target_link_libraries(stringutil_test klib)
target_link_libraries(stringutil_test scsl)
add_test(stringutilTest stringutil_test)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
klibConfig.cmake
scslConfig.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)
if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
if (NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(cloc
COMMAND cloc ${SOURCE_FILES} ${HEADER_FILES}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
add_custom_target(deploy-docs
COMMAND rsync --progress -auvz ${CMAKE_CURRENT_BINARY_DIR}/html/* docs.shimmering-clarity.net:sites/cc/
DEPENDS scsl_docs
)
configure_file(klib.pc.in klib.pc @ONLY)
install(TARGETS klib LIBRARY DESTINATION lib)
configure_file(scsl.pc.in scsl.pc @ONLY)
install(TARGETS scsl LIBRARY DESTINATION lib)
install(TARGETS phonebook RUNTIME DESTINATION bin)
install(FILES ${HEADER_FILES} DESTINATION include/klib)
install(FILES klibConfig.cmake DESTINATION share/klib/cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/klib.pc DESTINATION lib/pkgconfig)
install(FILES ${HEADER_FILES} DESTINATION include/scsl)
install(FILES scslConfig.cmake DESTINATION share/scsl/cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/scsl.pc DESTINATION lib/pkgconfig)
include(CMakePack.txt)
include(CMakeDocs.txt)

View File

@ -2,17 +2,17 @@
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_VENDOR "Shimmering Clarity")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Common C++ functionality.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The Shimmering Clarity standard C++ library.")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
# Debian settings
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "K. Isom")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The Shimmering Clarity C++ library")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Shimmering Clarity")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The Shimmering Clarity standard C++ library")
set(CPACK_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc++1 (>= 3.7.0-1)")
set(CPACK_DEBIAN_PACKAGE_SECTION devel)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
if(LINUX)
set(CPACK_GENERATOR "DEB;STGZ;TGZ")
@ -32,5 +32,5 @@ set(CPACK_SOURCE_IGNORE_FILES
/.*build.*)
include (CPack)
add_custom_target(package_docs DEPENDS klib_docs package package_source)
add_custom_target(package_docs DEPENDS SCSL_docs package package_source)

View File

@ -1,5 +1,5 @@
///
/// \file Commander.cpp
/// \file Commander.cc
/// \author kyle
/// \date 2023-10-10
///
@ -7,7 +7,7 @@
#include <iostream>
#include "Commander.h"
namespace klib {
namespace scsl {
Subcommand::Status
@ -57,4 +57,4 @@ Commander::Run(std::string command, int argc, char **argv)
}
} // klib
} // scsl

View File

@ -19,10 +19,10 @@
#include <vector>
#ifndef KLIB_COMMANDER_H
#define KLIB_COMMANDER_H
#ifndef SCSL_COMMANDER_H
#define SCSL_COMMANDER_H
namespace klib {
namespace scsl {
/// CommanderFunc describes a function that can be run in Commander.
@ -104,7 +104,7 @@ private:
std::map<std::string, Subcommand *> cmap;
};
} // klib
} // scsl
#endif //KLIB_COMMANDER_H
#endif //SCSL_COMMANDER_H

View File

@ -2,12 +2,12 @@
#include <cstdlib>
#include "Dictionary.h"
#if defined(KLIB_DESKTOP_BUILD)
#if defined(SCSL_DESKTOP_BUILD)
#include <iostream>
#endif
namespace klib {
namespace scsl {
bool
@ -124,7 +124,7 @@ Dictionary::spaceAvailable(uint8_t klen, uint8_t vlen)
required += klen + 2;
required += vlen + 2;
remaining = (uintptr_t)cursor - (uintptr_t)arena.NewCursor();
remaining = (uintptr_t)cursor - (uintptr_t) arena.Start();
remaining = arena.Size() - remaining;
return ((size_t)remaining >= required);
}
@ -133,8 +133,8 @@ Dictionary::spaceAvailable(uint8_t klen, uint8_t vlen)
std::ostream &
operator<<(std::ostream &os, const Dictionary &dictionary)
{
#if defined(KLIB_DESKTOP_BUILD)
uint8_t *cursor = (dictionary.arena).NewCursor();
#if defined(SCSL_DESKTOP_BUILD)
uint8_t *cursor = (dictionary.arena).Start();
TLV::Record rec;
TLV::ReadFromMemory(rec, cursor);
@ -164,4 +164,4 @@ Dictionary::DumpToFile(const char *path)
}
} // namespace klib
} // namespace scsl

View File

@ -1,12 +1,12 @@
///
/// \file klib.h
/// \file scsl.h
/// \author kyle
/// \date 2023-10-06
///
#ifndef KLIB_DICTIONARY_H
#define KLIB_DICTIONARY_H
#ifndef SCSL_DICTIONARY_H
#define SCSL_DICTIONARY_H
#include "Arena.h"
@ -17,7 +17,7 @@ static constexpr uint8_t DICTIONARY_TAG_KEY = 1;
static constexpr uint8_t DICTIONARY_TAG_VAL = 2;
namespace klib {
namespace scsl {
/*
@ -124,6 +124,6 @@ private:
};
} // namespace klib
} // namespace scsl
#endif

View File

@ -5,7 +5,7 @@
#include "Exceptions.h"
namespace klib {
namespace scsl {
AssertionFailed::AssertionFailed(std::string message) : msg(message)

View File

@ -2,14 +2,14 @@
// Created by kyle on 2023-10-10.
//
#ifndef KLIB_EXCEPTIONS_H
#define KLIB_EXCEPTIONS_H
#ifndef SCSL_EXCEPTIONS_H
#define SCSL_EXCEPTIONS_H
#include <exception>
#include <string>
namespace klib {
namespace scsl {
/// NotImplemented is an exception reserved for unsupported platforms.
@ -45,7 +45,7 @@ private:
};
} // namespace klib
} // namespace scsl
#endif //KLIB_EXCEPTIONS_H
#endif //SCSL_EXCEPTIONS_H

View File

@ -5,7 +5,7 @@ SOURCES := $(wildcard *.cc)
OBJS := Arena.o Dictionary.o TLV.o
CXX := clang++
CXXFLAGS := -g -std=c++14 -Werror -Wall -DKLIB_DESKTOP_BUILD
CXXFLAGS := -g -std=c++14 -Werror -Wall -DSCSL_DESKTOP_BUILD
.PHONY: all
all: $(TARGET) $(TESTS) tags run-tests

View File

@ -4,7 +4,7 @@
#include "StringUtil.h"
namespace klib {
namespace scsl {
/// namespace U contains utilities.
namespace U {
@ -162,4 +162,4 @@ VectorToString(const std::vector<std::string> &svec)
} // namespace S
} // namespace U
} // namespace klib
} // namespace scsl

View File

@ -31,9 +31,9 @@
#define STRINGUTIL_H
namespace klib {
/// namespace U contains utilities.
namespace scsl {
/// namespace U contains utilities.
namespace U {
/// namespace S contains string-related functions.
@ -83,21 +83,25 @@ std::vector<std::string> SplitKeyValuePair(std::string line, std::string delimit
/// \return The key and value.
std::vector<std::string> SplitKeyValuePair(std::string line, char delimiter);
std::vector<std::string> Split(std::string, std::string delimiter);
std::vector<std::string> Split(std::string, char delimiter);
/// Split a string into parts based on the delimiter.
///
/// \param delimiter The string that delimits the parts of the string.
/// \param maxCount The maximum number of parts to split. If 0, there is no limit
/// to the number of parts.
/// \return A vector containing all the parts of the string.
std::vector<std::string> SplitN(std::string, std::string delimiter, size_t maxCount=0);
//std::vector<std::string> SplitN(std::string, char delimiter, size_t size_t maxCount=0);
/// Return a string represention of a string vector in the form [size]{"foo", "bar", ...}.
std::ostream &VectorToString(std::ostream &os, const std::vector<std::string> &svec);
std::string VectorToString(const std::vector<std::string> &svec);
} // namespace S
} // namespace U
} // namespace klib
} // namespace scsl
#endif // STRINGUTIL_H

10
TLV.cc
View File

@ -1,13 +1,13 @@
#include <cstring>
#include "TLV.h"
using namespace klib;
using namespace scsl;
#define REC_SIZE(x) ((std::size_t)x.Len + 2)
namespace klib {
namespace scsl {
namespace TLV {
@ -103,7 +103,7 @@ LocateTag(Arena &arena, uint8_t *cursor, Record &rec)
uint8_t tag, len;
if (cursor == nullptr) {
cursor = arena.NewCursor();
cursor = arena.Start();
}
while ((tag = cursor[0]) != rec.Tag) {
@ -155,7 +155,7 @@ DeleteRecord(Arena &arena, uint8_t *cursor)
}
uint8_t len = cursor[1] + 2;
uint8_t *stop = arena.NewCursor() + arena.Size();
uint8_t *stop = arena.Start() + arena.Size();
stop -= len;
@ -173,4 +173,4 @@ DeleteRecord(Arena &arena, uint8_t *cursor)
} // namespace TLV
} // namespace klib
} // namespace scsl

4
TLV.h
View File

@ -20,7 +20,7 @@
#include "Arena.h"
namespace klib {
namespace scsl {
namespace TLV {
#ifndef TLV_MAX_LEN
@ -123,7 +123,7 @@ uint8_t *SkipRecord(Record &rec, uint8_t *cursor);
} // namespace TLV
} // namespace klib
} // namespace scsl
#endif

View File

@ -10,12 +10,12 @@
#include <sstream>
namespace klib {
namespace scsl {
void
TestAssert(bool condition, std::string message)
{
#if defined(NDEBUG) || defined(KLIB_NO_ASSERT)
#if defined(NDEBUG) || defined(SCSL_NO_ASSERT)
if (!condition) {
throw AssertionFailed(message);
}
@ -35,7 +35,7 @@ TestAssert(bool condition)
if (condition) {
return;
}
#if defined(KLIB_NO_ASSERT)
#if defined(SCSL_NO_ASSERT)
std::cerr << "Assertion failed!\n";
#else
std::stringstream msg;
@ -49,4 +49,4 @@ TestAssert(bool condition)
}
} // namespace klib
} // namespace scsl

12
Test.h
View File

@ -4,13 +4,13 @@
/// \date 2023-10-09
/// \brief Test.h implements basic testing tools.
///
#ifndef KLIB_TEST_H
#define KLIB_TEST_H
#ifndef SCSL_TEST_H
#define SCSL_TEST_H
#include <string>
namespace klib {
namespace scsl {
/// TestAssert is a variant on the assert macro. This variant is intended to be
@ -29,7 +29,7 @@ void TestAssert(bool condition);
/// If NDEBUG is set, TestAssert will throw an exception if condition is false.
/// Otherwise, it calls assert after printing the message.
///
/// In addition to NDEBUG, KLIB_NO_ASSERT will suppress assertions.
/// In addition to NDEBUG, SCSL_NO_ASSERT will suppress assertions.
///
/// \throws AssertionFailed
///
@ -38,6 +38,6 @@ void TestAssert(bool condition);
void TestAssert(bool condition, std::string message);
} // namespace klib
} // namespace scsl
#endif //KLIB_TEST_H
#endif //SCSL_TEST_H

View File

@ -7,7 +7,7 @@
#include "WinHelpers.h"
namespace klib {
namespace scsl {
namespace Windows {
@ -136,7 +136,7 @@ CreateFixedSizeFile(const char *path, size_t size)
} // namespace Windows
} // namespace klib
} // namespace scsl
#endif

View File

@ -2,8 +2,8 @@
// Created by kyle on 2023-10-10.
//
#ifndef KLIB_WINHELPERS_H
#define KLIB_WINHELPERS_H
#ifndef SCSL_WINHELPERS_H
#define SCSL_WINHELPERS_H
#if defined(__WIN64__) || defined(__WIN32__) || defined(WIN32)
@ -12,7 +12,7 @@
#include <fileapi.h>
#include <strsafe.h>
namespace klib {
namespace scsl {
namespace Windows {
@ -32,8 +32,8 @@ int CreateFixedSizeFile(const char *path, size_t size);
} // namespace Windows
} // namespace klib
} // namespace scsl
#endif // Windows-only guards.
#endif //KLIB_WINHELPERS_H
#endif //SCSL_WINHELPERS_H

View File

@ -2,7 +2,7 @@
#include <iostream>
#include "Buffer.h"
using namespace klib;
using namespace scsl;
int

View File

@ -6,7 +6,7 @@
#include "testFixtures.h"
using namespace klib;
using namespace scsl;
constexpr char TEST_KVSTR1[] = "foo";

View File

@ -1,2 +0,0 @@
set(KLIB_INCLUDE_DIRS include/klib)
set(KLIB_LIBRARIES libklib.a)

View File

@ -9,7 +9,7 @@ using namespace std;
#include "Arena.h"
#include "Commander.h"
#include "Dictionary.h"
using namespace klib;
using namespace scsl;
static const char *defaultPhonebook = "pb.dat";
static char *pbFile = (char *)defaultPhonebook;

View File

@ -1,8 +1,8 @@
///
/// \file klib.h
/// \file scsl.h
/// \author kyle
/// \created 2023-10-10
/// \brief klib is my collection of C++ data structures and code.
/// \brief scsl is my collection of C++ data structures and code.
///
/// \section COPYRIGHT
/// Copyright 2023 K. Isom <kyle@imap.cc>
@ -21,8 +21,8 @@
/// SOFTWARE.
///
#ifndef KLIB_KLIB_H
#define KLIB_KLIB_H
#ifndef SCSL_SCSL_H
#define SCSL_SCSL_H
#include <klib/Arena.h>
@ -33,10 +33,10 @@
#include <klib/Test.h>
/// klib is the top-level namespace containing all the code in this library.
namespace klib {
/// scsl is the top-level namespace containing all the code in this library.
namespace scsl {
/// \mainpage klib documentation
/// \mainpage scsl documentation
///
/// \section Introduction
///
@ -71,4 +71,4 @@ namespace klib {
}
#endif // KLIB_KLIB_H
#endif // SCSL_SCSL_H

2
scslConfig.cmake Normal file
View File

@ -0,0 +1,2 @@
set(SCSL_INCLUDE_DIRS include/scsl)
set(SCSL_LIBRARIES libscsl.a)

View File

@ -27,7 +27,7 @@
#include "StringUtil.h"
#include "Test.h"
using namespace klib;
using namespace scsl;
static void
@ -114,4 +114,6 @@ main()
std::vector<std::string>{"abc", "def:ghij:klm"});
TestSplit("abc:def:ghij:klm", ":", 1,
std::vector<std::string>{"abc:def:ghij:klm"});
TestSplit("abc::def:ghi", ":", 0,
std::vector<std::string>{"abc", "", "def", "ghi"});
}

View File

@ -1,5 +1,5 @@
#ifndef KLIB_TESTFIXTURES_H
#define KLIB_TESTFIXTURES_H
#ifndef SCSL_TESTFIXTURES_H
#define SCSL_TESTFIXTURES_H
#include <string.h>
@ -22,7 +22,7 @@
#define TEST_STRLEN4 35
namespace klib {
namespace scsl {
static bool
@ -44,7 +44,7 @@ cmpRecord(TLV::Record &a, TLV::Record &b)
}
} // namespace klib
} // namespace scsl
#endif // KLIB_TESTFIXTURES_H
#endif // SCSL_TESTFIXTURES_H

View File

@ -9,7 +9,7 @@
#include "testFixtures.h"
using namespace klib;
using namespace scsl;
static uint8_t arenaBuffer[ARENA_SIZE];
@ -40,7 +40,7 @@ tlvTestSuite(Arena &backend)
std::cout << "\tFindTag 1" << "\n";
cursor = TLV::FindTag(backend, cursor, rec4);
assert(cursor != nullptr);
assert(cursor != backend.NewCursor());
assert(cursor != backend.Start());
assert(cmpRecord(rec1, rec4));
std::cout << "\tFindTag 2" << "\n";