Skip to content
Draft
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
8 changes: 6 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
set(SRC_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jaclks-internal)

aux_source_directory(${SRC_ROOT_DIR}/javac-base/java/lang SRC_FILES)
aux_source_directory(${SRC_ROOT_DIR}/javac-base/java/security SRC_FILES)
set(CXX_SRC_ROOT_DIR ${SRC_ROOT_DIR}/cxx-detail)
aux_source_directory(${CXX_SRC_ROOT_DIR}/utils SRC_FILES)

set(JBASE_SRC_ROOT_DIR ${SRC_ROOT_DIR}/javac-base)
aux_source_directory(${JBASE_SRC_ROOT_DIR}/java/lang SRC_FILES)
aux_source_directory(${JBASE_SRC_ROOT_DIR}/java/security SRC_FILES)

if(BUILD_SHARED_LIBS)
add_library(jaclks_shared SHARED ${SRC_FILES})
Expand Down
62 changes: 62 additions & 0 deletions src/jaclks-internal/cxx-detail/utils/string_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "jaclks-internal/cxx-detail/utils/string_utils.h"

namespace jaclks::cxx_detail {

namespace {
using std::string;

/**
* Steal to access private _M_string_length member
*/
using size_type = string::size_type;

size_type *StealLength(string *str);

template <size_type string::*MEMBER_INT_PTR>
struct LengthMemberAccesser {
friend size_type *StealLength(string *victim_object) {
return &(victim_object->*MEMBER_INT_PTR);
}
};

template struct LengthMemberAccesser<&string::_M_string_length>;

/**
* Steal local capacity
*/
int StealLocalCapacity(const string &str);

template <int Cap>
struct LocalCapacityMemberAccesser {
friend int StealLocalCapacity(const string &victim_object) {
return Cap;
}
};

template struct LocalCapacityMemberAccesser<string::_S_local_capacity>;

/**
* Steal to access private _M_is_local function
*/
bool IsLocalData(const string &str);

template <bool (string::*Func)() const>
struct LocalFunctionAccesser {
friend bool IsLocalData(const string &victim_object) {
return (victim_object.*Func)();
;
}
};

template struct LocalFunctionAccesser<&string::_M_is_local>;

} // namespace

std::string StringUtils::ToStdString(javac_base::String str) {
std::string result;


return "";
}

} // namespace jaclks::cxx_detail
14 changes: 14 additions & 0 deletions src/jaclks-internal/cxx-detail/utils/string_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <string>

#include "jaclks/javac-base/java/lang/string.h"

namespace jaclks::cxx_detail {

class StringUtils {
public:
static std::string ToStdString(javac_base::String str);
};

} // namespace jaclks::cxx_detail
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_executable(jaclks_gtest main.cc ${SRC_FILES} ${TEST_SRC_FILES})

target_link_libraries(jaclks_gtest PRIVATE GTest::gtest)

add_subdirectory(cxx-detail)
add_subdirectory(javac-base)

# Registers googletests
Expand Down
14 changes: 14 additions & 0 deletions tests/cxx-detail/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include_directories(${PROJECT_ROOT_DIR}/src)

# add all test files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/utils JCXX_TEST_SRC_FILES)

add_executable(jcxx_gtest main.cc ${JCXX_TEST_SRC_FILES})

target_link_libraries(jcxx_gtest PRIVATE MyThirdParty::All jaclks_static
GTest::gtest)

add_dependencies(jcxx_gtest jaclks_static)

# Registers googletests
add_test(NAME jcxx_gtest COMMAND $<TARGET_FILE:jcxx_gtest>)
6 changes: 6 additions & 0 deletions tests/cxx-detail/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <gtest/gtest.h>

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
9 changes: 9 additions & 0 deletions tests/cxx-detail/utils/string_utils_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "jaclks-internal/cxx-detail/utils/string_utils.h"

#include <gtest/gtest.h>

namespace jaclks::cxx_detail {

TEST(StringUtils, ToStdString) {}

} // namespace jaclks::cxx_detail
Loading