Skip to content

Commit

Permalink
Add strategy and system journals in JournalFinder
Browse files Browse the repository at this point in the history
  • Loading branch information
dongkeren committed Mar 9, 2018
1 parent 886e230 commit c0d8677
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
29 changes: 29 additions & 0 deletions yijinjing/journal/JournalFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@

USING_YJJ_NAMESPACE

JournalPair getSystemJournalPair(short source) {
return {PAGED_JOURNAL_FOLDER, PAGED_JOURNAL_NAME};
}

void JournalFinder::addJournalInfo(std::string name, std::string folder) {
all_journal[name] = folder;
all_journal_names.push_back(name);

vector<short> pageNums = PageUtil::GetPageNums(folder, name);
if (!pageNums.empty()) {
avaliable_journal_names.push_back(name);
avaliable_journal_folders.push_back(folder);
}
}

void JournalFinder::loadJournalInfo(short source, JournalPair (*getJournalPair)(short)) {
JournalPair pair = getJournalPair(source);
if (pair.first.length() > 0) {
Expand Down Expand Up @@ -60,4 +75,18 @@ void JournalFinder::loadJournalInfo(short source) {
JournalFinder::JournalFinder() {
loadJournalInfo(SOURCE_CTP);
loadJournalInfo(SOURCE_XTP);

loadJournalInfo(0, getSystemJournalPair);

boost::filesystem::path bl_journal_folder(BL_BASE_FOLDER);
boost::regex pattern(JOURNAL_NAME_PATTERN);
vector<short> res;
for (auto &file : boost::filesystem::directory_iterator(bl_journal_folder)) {
std::string filename = file.path().filename().string();
boost::smatch result;
if (boost::regex_match(filename, result, pattern)) {
std::string journal_name(result[1].first, result[1].second);
addJournalInfo(journal_name, BL_BASE_FOLDER);
}
}
}
6 changes: 6 additions & 0 deletions yijinjing/journal/JournalFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@

#include "YJJ_DECLARE.h"

#include "StrategyUtil.h"
#include "longfist/LFUtils.h"

#include <string>
#include <boost/regex.hpp>
#include <boost/filesystem.hpp>

YJJ_NAMESPACE_START

#define JOURNAL_NAME_PATTERN JOURNAL_PREFIX + "\\.(\\w+)\\.[0-9]+\\." + JOURNAL_SUFFIX

class JournalFinder {
private:
void addJournalInfo(std::string name, std::string folder);
void loadJournalInfo(short source, JournalPair (*getJournalPair)(short));
void loadJournalInfo(short source);
protected:
Expand Down
3 changes: 0 additions & 3 deletions yijinjing/journal/StrategyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

USING_YJJ_NAMESPACE

#define BL_BASE_FOLDER KUNGFU_JOURNAL_FOLDER "strategy/"
#define BL_REPLAY_FOLDER KUNGFU_JOURNAL_FOLDER "strategy_replay/"

StrategyUtil::StrategyUtil(const string& strategyName, bool isReplay)
{
if (isReplay)
Expand Down
3 changes: 3 additions & 0 deletions yijinjing/journal/StrategyUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

YJJ_NAMESPACE_START

#define BL_BASE_FOLDER KUNGFU_JOURNAL_FOLDER "strategy/"
#define BL_REPLAY_FOLDER KUNGFU_JOURNAL_FOLDER "strategy_replay/"

FORWARD_DECLARE_PTR(StrategySocketHandler);
FORWARD_DECLARE_PTR(JournalWriter);
FORWARD_DECLARE_PTR(StrategyUtil);
Expand Down

0 comments on commit c0d8677

Please sign in to comment.