Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
# Google C++ Style Guide
# https://google.github.io/styleguide/cppguide.html
BasedOnStyle: Google
IndentWidth: 2
ColumnLimit: 80
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
# Other adjustments
AccessModifierOffset: -1
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakTemplateDeclarations: true
BinPackParameters: false
BreakBeforeBraces: Attach
BreakConstructorInitializers: BeforeColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: true
IncludeBlocks: Regroup
IncludeCategories:
# Standard library headers
- Regex: '^<[^/]+>$'
Priority: 1
# Other library headers
- Regex: '^<.+>$'
Priority: 2
# Project headers with quotes
- Regex: '^"mcp/.+"$'
Priority: 3
# Other project headers
- Regex: '^".+"$'
Priority: 4
IndentCaseLabels: true
KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: None
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++11
UseTab: Never
# Remove trailing whitespace
InsertTrailingCommas: None
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,20 @@ FetchContent_MakeAvailable(googletest)
enable_testing()

# Add test subdirectory
add_subdirectory(tests)
add_subdirectory(tests)

# Add custom target for formatting
add_custom_target(format
COMMAND find ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/tests
-name "*.h" -o -name "*.cpp" | xargs clang-format -i
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Formatting all source files with clang-format"
)

# Add custom target to check formatting without modifying files
add_custom_target(check-format
COMMAND find ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/tests
-name "*.h" -o -name "*.cpp" | xargs clang-format --dry-run --Werror
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Checking source file formatting with clang-format"
)
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for MCP C++ SDK

.PHONY: all build test clean release debug help
.PHONY: all build test clean release debug help format check-format

# Default target
all: build test
Expand Down Expand Up @@ -32,6 +32,17 @@ rebuild: clean all
verbose:
@./build.sh --verbose

# Format all source files
format:
@echo "Formatting all source files with clang-format..."
@find include tests -name "*.h" -o -name "*.cpp" | xargs clang-format -i
@echo "Formatting complete."

# Check formatting without modifying files
check-format:
@echo "Checking source file formatting..."
@find include tests -name "*.h" -o -name "*.cpp" | xargs clang-format --dry-run --Werror

# Help
help:
@echo "MCP C++ SDK Makefile"
Expand All @@ -45,6 +56,8 @@ help:
@echo " make clean - Clean build directory"
@echo " make rebuild - Clean and rebuild everything"
@echo " make verbose - Build with verbose output"
@echo " make format - Format all source files with clang-format"
@echo " make check-format - Check formatting without modifying files"
@echo " make help - Show this help message"
@echo ""
@echo "Examples:"
Expand Down
23 changes: 12 additions & 11 deletions include/mcp/memory_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@
namespace mcp {

// C++11 compatible make_unique implementation
template<typename T, typename... Args>
template <typename T, typename... Args>
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

// Array version for make_unique
template<typename T>
typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0, std::unique_ptr<T>>::type
template <typename T>
typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0,
std::unique_ptr<T>>::type
make_unique(std::size_t size) {
typedef typename std::remove_extent<T>::type element_type;
return std::unique_ptr<T>(new element_type[size]());
typedef typename std::remove_extent<T>::type element_type;
return std::unique_ptr<T>(new element_type[size]());
}

// Disable make_unique for arrays with known bounds
template<typename T, typename... Args>
typename std::enable_if<std::extent<T>::value != 0, void>::type
make_unique(Args&&...) = delete;
template <typename T, typename... Args>
typename std::enable_if<std::extent<T>::value != 0, void>::type make_unique(
Args&&...) = delete;

} // namespace mcp
} // namespace mcp

#endif // MCP_MEMORY_UTILS_H
#endif // MCP_MEMORY_UTILS_H
Loading