Java转换成C++的Eclipse插件 J2cpp
J2cpp 是一个 Eclipse 的插件,可以将 Java 类转为 C++11 类。需要注意的是生成的 C++ 代码在进行转换处理之前是没法编译的,你必须对生成的代码进行二次处理。
安装地址:http://tsug.github.com/j2cpp/update/
下面是转换示例:BlockSituationEx.java:import java.util.HashMap; import java.util.Map; import me.pixodro.furiousblocks.core.panel.BlockState; import me.pixodro.furiousblocks.core.panel.BlockType; import me.pixodro.furiousblocks.core.situations.BlockSituation; import me.pixodro.furiousblocks.core.tools.Point; public class BlockSituationEx extends BlockSituation { private final Map<Integer, Integer> targetColumnCosts; private Point origin = null; private boolean chainReplacement = false; public BlockSituationEx(final BlockSituation bs) { super(bs.getId(), bs.getType(), bs.getState(), bs.getStateTick(), bs.getGarbageBlockType(), bs.getGarbageOwner(), bs.isCombo(), bs.hasJustLand(), bs.isFallingFromClearing(), bs.getPoppingIndex()); targetColumnCosts = new HashMap<Integer, Integer>(); chainReplacement = false; } public BlockSituationEx(final BlockSituationEx bsEx) { super(bsEx.getId(), bsEx.getType(), bsEx.getState(), bsEx.getStateTick(), bsEx.getGarbageBlockType(), bsEx.getGarbageOwner(), bsEx.isCombo(), bsEx.hasJustLand(), bsEx.isFallingFromClearing(), bsEx.getPoppingIndex()); origin = bsEx.getOrigin(); targetColumnCosts = bsEx.targetColumnCosts; chainReplacement = bsEx.chainReplacement; } private BlockSituationEx() { super(0, BlockType.INVISIBLE, BlockState.IDLE, 0, (byte) 0, 0, false, false, false, 0); targetColumnCosts = new HashMap<Integer, Integer>(); } public final int getTargetColumnCost(final int targetColumn) { // TODO: this is a bug, target cost should never be null // return targetColumnCosts.get(targetColumn); final Integer cost = targetColumnCosts.get(targetColumn); return cost == null ? ComboProcessor.INFINITY : cost; } public final void addTargetCost(final int targetColumn, final int cost) { targetColumnCosts.put(targetColumn, cost); } public final Point getOrigin() { return origin; } public final void setOrigin(final Point position) { origin = position; } public final void reset() { origin = null; targetColumnCosts.clear(); chainReplacement = false; } public static BlockSituationEx newInvisibleBlock() { return new BlockSituationEx(); } @Override public String toString() { return "BlockSituationEx [origin=[" + (origin == null ? "null" : (origin.x + ":" + origin.y)) + "], isChainReplacement = " + isChainReplacement() + ", costs=" + targetColumnCosts + "]"; } public void setChainReplacement(final boolean comboReplacement) { chainReplacement = comboReplacement; } public final boolean isChainReplacement() { return chainReplacement; } public final boolean isReplacement() { return !targetColumnCosts.isEmpty(); } }
生以下两个文件:
BlockSituationEx.h:#ifndef __BlockSituationEx_H_ #define __BlockSituationEx_H_ #include <cstdint> #include <map> #include "BlockSituation.h" #include "String.h" #include "BlockSituationEx.h" #include "Point.h" using namespace std; class BlockSituationEx : BlockSituation { private: map<int32_t,int32_t> targetColumnCosts; Point* origin = nullptr; bool chainReplacement = false; BlockSituationEx(); protected: public: BlockSituationEx(BlockSituation* bs); BlockSituationEx(BlockSituationEx* bsEx); int32_t getTargetColumnCost(int32_t targetColumn); void addTargetCost(int32_t targetColumn, int32_t cost); Point* getOrigin(); void setOrigin(Point* position); void reset(); static BlockSituationEx* newInvisibleBlock(); void setChainReplacement(bool comboReplacement); bool isChainReplacement(); bool isReplacement(); }; #endif //__BlockSituationEx_H_
#ifndef __BlockSituationEx_H_ #define __BlockSituationEx_H_ #include <cstdint> #include <map> #include "BlockSituation.h" #include "String.h" #include "BlockSituationEx.h" #include "Point.h" using namespace std; class BlockSituationEx : BlockSituation { private: map<int32_t,int32_t> targetColumnCosts; Point* origin = nullptr; bool chainReplacement = false; BlockSituationEx(); protected: public: BlockSituationEx(BlockSituation* bs); BlockSituationEx(BlockSituationEx* bsEx); int32_t getTargetColumnCost(int32_t targetColumn); void addTargetCost(int32_t targetColumn, int32_t cost); Point* getOrigin(); void setOrigin(Point* position); void reset(); static BlockSituationEx* newInvisibleBlock(); void setChainReplacement(bool comboReplacement); bool isChainReplacement(); bool isReplacement(); }; #endif //__BlockSituationEx_H_
BlockSituationEx.cpp:#include <cstdint> #include <map> #include "BlockSituation.h" #include "String.h" #include "BlockSituationEx.h" #include "Point.h" #include "BlockSituationEx.h" using namespace std; BlockSituationEx::BlockSituationEx(BlockSituation* bs) { targetColumnCosts = new map<int32_t,int32_t>(); chainReplacement = false; } BlockSituationEx::BlockSituationEx(BlockSituationEx* bsEx) { origin = bsEx->getOrigin(); targetColumnCosts = bsEx->targetColumnCosts; chainReplacement = bsEx->chainReplacement; } BlockSituationEx::BlockSituationEx() { targetColumnCosts = new map<int32_t,int32_t>(); } int32_t BlockSituationEx::getTargetColumnCost(int32_t targetColumn) { int32_t cost = targetColumnCosts->get(targetColumn); return cost == nullptr ? ComboProcessor::INFINITY : cost; } void BlockSituationEx::addTargetCost(int32_t targetColumn, int32_t cost) { targetColumnCosts->put(targetColumn, cost); } Point* BlockSituationEx::getOrigin() { return origin; } void BlockSituationEx::setOrigin(Point* position) { origin = position; } void BlockSituationEx::reset() { origin = nullptr; targetColumnCosts->clear(); chainReplacement = false; } BlockSituationEx* BlockSituationEx::newInvisibleBlock() { return new BlockSituationEx(); } void BlockSituationEx::setChainReplacement(bool comboReplacement) { chainReplacement = comboReplacement; } bool BlockSituationEx::isChainReplacement() { return chainReplacement; } bool BlockSituationEx::isReplacement() { return !targetColumnCosts->isEmpty(); }
本文由用户 openkk 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!