调整C++ 代码
This commit is contained in:
parent
de31b79465
commit
1ee0ec29b7
@ -20,7 +20,10 @@ ELSE()
|
|||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
# 添加共享库
|
# 添加共享库
|
||||||
add_library(${PROJECT_NAME} ${STATIC_OR_SHARED} library.cpp)
|
add_library(${PROJECT_NAME} ${STATIC_OR_SHARED}
|
||||||
|
Calculate.cpp
|
||||||
|
CalculateInfo.h
|
||||||
|
)
|
||||||
|
|
||||||
# 解析配置
|
# 解析配置
|
||||||
if(EX_PLATFORM EQUAL 32)
|
if(EX_PLATFORM EQUAL 32)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "library.h"
|
#include "Calculate.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -2,12 +2,7 @@
|
|||||||
#define CPPLIB_LIBRARY_H
|
#define CPPLIB_LIBRARY_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "CalculateInfo.h"
|
||||||
struct CalculateInfo {
|
|
||||||
std::string name;
|
|
||||||
std::string versionName;
|
|
||||||
int versionCode;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Calculate {
|
class Calculate {
|
||||||
public:
|
public:
|
@ -1,11 +1,11 @@
|
|||||||
//
|
//
|
||||||
// Created on 2024/4/22.
|
// Created on 2024/5/28.
|
||||||
//
|
//
|
||||||
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
|
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
|
||||||
// please include "napi/native_api.h".
|
// please include "napi/native_api.h".
|
||||||
|
|
||||||
#ifndef HM4DEMO_CALCULATE_H
|
#ifndef HM4DEMO_CALCULATEINFO_H
|
||||||
#define HM4DEMO_CALCULATE_H
|
#define HM4DEMO_CALCULATEINFO_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
struct CalculateInfo {
|
struct CalculateInfo {
|
||||||
@ -14,10 +14,4 @@ struct CalculateInfo {
|
|||||||
int versionCode;
|
int versionCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Calculate {
|
#endif //HM4DEMO_CALCULATEINFO_H
|
||||||
public:
|
|
||||||
static Calculate& getInstance();
|
|
||||||
int add(int a, int b);
|
|
||||||
CalculateInfo getInfo();
|
|
||||||
};
|
|
||||||
#endif //HM4DEMO_CALCULATE_H
|
|
BIN
cppLib/dist/lib/arm64-v8a/libcalculate.so
vendored
BIN
cppLib/dist/lib/arm64-v8a/libcalculate.so
vendored
Binary file not shown.
@ -1 +1 @@
|
|||||||
export {} from './src/main/cpp/types/libnatvie_lib/index'
|
export { CalculateAdapter } from './src/main/cpp/types/libnatvie_lib/index'
|
@ -11,6 +11,9 @@ endif()
|
|||||||
include_directories(${NATIVERENDER_ROOT_PATH}
|
include_directories(${NATIVERENDER_ROOT_PATH}
|
||||||
${NATIVERENDER_ROOT_PATH}/include)
|
${NATIVERENDER_ROOT_PATH}/include)
|
||||||
|
|
||||||
add_library(native_lib SHARED napi_init.cpp)
|
add_library(native_lib SHARED
|
||||||
|
napi_init.cpp
|
||||||
|
CalculateInfo.h
|
||||||
|
CalculateAdaptor.cpp)
|
||||||
|
|
||||||
target_link_libraries(native_lib PUBLIC ../../../../cppLib/dist/lib/arm64-v8a/libcalculate.so)
|
target_link_libraries(native_lib PUBLIC ../../../../cppLib/dist/lib/arm64-v8a/libcalculate.so)
|
25
native_lib/src/main/cpp/Calculate.h
Normal file
25
native_lib/src/main/cpp/Calculate.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef CPPLIB_LIBRARY_H
|
||||||
|
#define CPPLIB_LIBRARY_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "CalculateInfo.h"
|
||||||
|
|
||||||
|
class Calculate {
|
||||||
|
public:
|
||||||
|
static Calculate& getInstance();
|
||||||
|
int add(int a, int b);
|
||||||
|
CalculateInfo getInfo();
|
||||||
|
|
||||||
|
// 删除拷贝构造函数和赋值运算符
|
||||||
|
Calculate(const Calculate&) = delete;
|
||||||
|
Calculate& operator=(const Calculate&) = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// 构造函数和析构函数私有化
|
||||||
|
Calculate() {}
|
||||||
|
~Calculate() {}
|
||||||
|
};
|
||||||
|
#endif //CPPLIB_LIBRARY_H
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -5,7 +5,8 @@
|
|||||||
// please include "napi/native_api.h".
|
// please include "napi/native_api.h".
|
||||||
|
|
||||||
#include "CalculateAdaptor.h"
|
#include "CalculateAdaptor.h"
|
||||||
#include "library.h"
|
#include "Calculate.h"
|
||||||
|
#include "CalculateInfo.h"
|
||||||
|
|
||||||
CalculateAdaptor::CalculateAdaptor() {
|
CalculateAdaptor::CalculateAdaptor() {
|
||||||
_calculate = &Calculate::getInstance();
|
_calculate = &Calculate::getInstance();
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
#ifndef HM4DEMO_CALCULATOR_H
|
#ifndef HM4DEMO_CALCULATOR_H
|
||||||
#define HM4DEMO_CALCULATOR_H
|
#define HM4DEMO_CALCULATOR_H
|
||||||
|
|
||||||
#include "library.h"
|
#include "CalculateInfo.h"
|
||||||
|
#include "Calculate.h"
|
||||||
#include "js_native_api.h"
|
#include "js_native_api.h"
|
||||||
|
|
||||||
class CalculateAdaptor {
|
class CalculateAdaptor {
|
||||||
|
17
native_lib/src/main/cpp/CalculateInfo.h
Normal file
17
native_lib/src/main/cpp/CalculateInfo.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// Created on 2024/5/28.
|
||||||
|
//
|
||||||
|
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
|
||||||
|
// please include "napi/native_api.h".
|
||||||
|
|
||||||
|
#ifndef HM4DEMO_CALCULATEINFO_H
|
||||||
|
#define HM4DEMO_CALCULATEINFO_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
struct CalculateInfo {
|
||||||
|
std::string name;
|
||||||
|
std::string versionName;
|
||||||
|
int versionCode;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //HM4DEMO_CALCULATEINFO_H
|
@ -1,5 +1,5 @@
|
|||||||
import { CalculateAdapter } from 'native_lib.so'
|
import { CalculateAdapter } from 'native_lib.so'
|
||||||
import { CalculateInfo } from './CalculateDefine'
|
import { CalculateInfo } from './CalculateInfo'
|
||||||
|
|
||||||
export class Calculator {
|
export class Calculator {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user