Skip to content

Commit

Permalink
remove stdafx in windows, and add new files
Browse files Browse the repository at this point in the history
  • Loading branch information
vintagewang committed Jun 9, 2012
1 parent 8efac09 commit 8ecdcd8
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 55 deletions.
8 changes: 3 additions & 5 deletions bin/jwrapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
<javahome>C:\myapp\jdk1.6.0_26</javahome>
<mainclass>Hello</mainclass>
<classpaths>
<classpath>cp1</classpath>
<classpath>cp2</classpath>
<classpath>cp3</classpath>
<classpath></classpath>
<a>haha</a>
<cp>cp1</cp>
<cp>cp2</cp>
<cp>cp3</cp>
</classpaths>
</java>
1 change: 1 addition & 0 deletions project/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setx BOOST_HOME D:\opensrc\boost_1_49_0
Empty file added project/build.sh
Empty file.
34 changes: 13 additions & 21 deletions project/jwrapper.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="D:\opensrc\boost_1_49_0;&quot;$(SolutionDir)..\include&quot;"
AdditionalIncludeDirectories="&quot;$(BOOST_HOME)&quot;;&quot;$(SolutionDir)..\include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
Expand Down Expand Up @@ -175,29 +175,17 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\src\JavaConfig.cpp"
>
</File>
<File
RelativePath="..\src\jwrapper.cpp"
>
</File>
<File
RelativePath=".\stdafx.cpp"
RelativePath="..\src\JWUtil.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Expand All @@ -206,11 +194,15 @@
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\resource.h"
RelativePath="..\src\JavaConfig.h"
>
</File>
<File
RelativePath=".\stdafx.h"
RelativePath="..\src\JWUtil.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
</Filter>
Expand Down
18 changes: 18 additions & 0 deletions src/JWUtil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "JWUtil.h"
#include <Windows.h>

namespace JWUtil
{
std::string getCurrentExeFilePath()
{
std::string result;
#ifdef WIN32
char bufFileName[512 + 1] = {0};
GetModuleFileNameA(NULL, bufFileName, sizeof(bufFileName) - 1);
result = bufFileName;
#else
#endif

return result;
}
}
10 changes: 10 additions & 0 deletions src/JWUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _JW_JWUTIL_H__
#define _JW_JWUTIL_H__
#include <string>

namespace JWUtil
{
std::string getCurrentExeFilePath();
};

#endif // end of _JW_JWUTIL_H__
54 changes: 54 additions & 0 deletions src/JavaConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "JavaConfig.h"
#include "JWUtil.h"
#include <string>
#include <stdio.h>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/typeof/std/utility.hpp>

using namespace boost::property_tree;
using std::string;

JavaConfig::JavaConfig()
{
}

JavaConfig::~JavaConfig()
{
}

JavaConfig* JavaConfig::getInstance()
{
static JavaConfig *singleton = new JavaConfig();
return singleton;
}

bool JavaConfig::load()
{
ptree pt;
read_xml("jwrapper.xml", pt);
this->javaHome = pt.get<string>("java.javahome");
this->mainClass = pt.get<string>("java.mainclass");

BOOST_AUTO(child, pt.get_child("java.classpaths"));
for(BOOST_AUTO(pos, child.begin());
pos != child.end();
++pos) {
this->classPathList.push_back(pos->second.data());
}
return true;
}

void JavaConfig::printAll()
{
printf("JAVA_HOME = [%s]\n", this->javaHome.c_str());
printf("MAIN CLASS = [%s]\n", this->mainClass.c_str());
for(size_t i = 0; i < this->classPathList.size(); i++) {
printf("CLASS PATH %2d = [%s]\n", i, this->classPathList[i].c_str());
}
}

std::string JavaConfig::getConfigFile()
{
return JWUtil::getCurrentExeFilePath() + ".xml";
}
30 changes: 30 additions & 0 deletions src/JavaConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef _JW_JAVA_CONFIG_H__
#define _JW_JAVA_CONFIG_H__
#include <string>
#include <map>
#include <vector>

typedef std::vector<std::string> ClassPathList;

class JavaConfig
{
public:

JavaConfig();
~JavaConfig();
static JavaConfig* getInstance();

bool load();

void printAll();

private:
static std::string getConfigFile();

private:
std::string javaHome;
std::string mainClass;
ClassPathList classPathList;
};

#endif // end of _JW_JAVA_CONFIG_H__
47 changes: 20 additions & 27 deletions src/jwrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
#include "stdafx.h"
#include <iostream>
#include <string>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/typeof/std/utility.hpp>
using namespace boost::property_tree;
using std::cout;
using std::endl;
using std::string;
#include "JavaConfig.h"

void test_ptree()
{
ptree pt;
read_xml("jwrapper.xml", pt);
cout << pt.get<string>("java.javahome") << endl;
cout << pt.get<string>("java.mainclass") << endl;

BOOST_AUTO(child, pt.get_child("java.classpaths"));
for (BOOST_AUTO(pos, child.begin());
pos != child.end();
++pos)
{
cout << pos->second.data()<< ",";
}
}
//void test_ptree()
//{
// ptree pt;
// read_xml("jwrapper.xml", pt);
// cout << pt.get<string>("java.javahome") << endl;
// cout << pt.get<string>("java.mainclass") << endl;
//
// BOOST_AUTO(child, pt.get_child("java.classpaths"));
// for(BOOST_AUTO(pos, child.begin());
// pos != child.end();
// ++pos)
// {
// cout << pos->second.data() << ",";
// }
//}

int main(int argc, char** argv)
{
printf("Hello World.\n");
test_ptree();
bool result = JavaConfig::getInstance()->load();
if(result) {
JavaConfig::getInstance()->printAll();
}
return 0;
}

File renamed without changes.
4 changes: 2 additions & 2 deletions project/stdafx.h → src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//

#ifdef WIN32
#pragma once

#ifndef _WIN32_WINNT // 允许使用特定于 Windows XP 或更高版本的功能。
Expand All @@ -11,7 +11,7 @@

#include <stdio.h>
#include <tchar.h>

#endif


// TODO: 在此处引用程序需要的其他头文件

0 comments on commit 8ecdcd8

Please sign in to comment.