logplus/Workflow/WFEngine/Module/src/ModuleMetaData.cpp
2026-01-16 17:18:41 +08:00

670 lines
15 KiB
C++

/*
* ModuleMetaData.cpp
*
* Created on: 2011-8-29
* Author: dev
*/
#include "ModuleMetaData.h"
// #include "json/json.h"
#include <sstream>
// #include "Utils.h"
// #include "Log.h"
using namespace std;
// using namespace pai::utils;
namespace pai {
namespace module {
Port::Port()
:order(-1)
,type(PORT_INPUT)
,connectedModuleType("")
,name("")
,optional(false)
{
}
CModuleMetaData::CModuleMetaData()
:m_vecPorts()
,m_strCategory("")
,m_strID("")
,m_strNameSpace("")
,m_strLibName("")
,m_strName("")
,m_strDescription("")
,m_strAuthor("")
,m_strCreateTime("")
,m_strLastModifyTime("")
,m_strVersion("")
,m_strPaiVersion("")
,m_strSubCategory("")//模块子分类名
,m_strHelpDoc("")//模块帮助文档名
,m_strDimension("")//模块维数
,m_strDomain("")//定义域
,m_strInputDataDomain("")//输入数据定义域
,m_strOuputDataDomain("")//输出数据定义域
,m_strWorkUnit("")//工作单位名
,m_bHasInput(true)
,m_bHasOutput(true)
,m_strIOType("")
,m_bNeedOtherFile(true)
,m_bNeedTmpMemory(true)
,m_bOutputOtherFile(true)
,m_bNeedParameters(true)
,m_bIsInterActive(true)
,m_iCompute(0)
,m_iMemory(0)
,m_strParalleMode("")
,m_bNeedReduce(true)
,m_iOutputTypes(0)
,m_strStageNum("1")
,m_SplitStage("")
{
// TODO Auto-generated constructor stub
}
CModuleMetaData::~CModuleMetaData() {
// TODO Auto-generated destructor stub
}
/**
* @brief 设置模块分类名
* @param strCategory 模块分类名
*/
void CModuleMetaData::SetCategory(const std::string& strCategory)
{
m_strCategory=strCategory;
}
/**
* @brief 获取模块分类名
*/
std::string CModuleMetaData::GetCategory() const
{
return m_strCategory;
}
/**
* @brief 设置模块ID
* @param strID 模块ID
*/
void CModuleMetaData::SetID(const std::string& strID)
{
if(""!=strID)
{
m_strID=strID;
return;
}
}
/**
* @brief 获取模块ID
*/
std::string CModuleMetaData::GetID() const
{
return m_strID;
}
/**
* @brief 设置模块名字
* @param strName 模块名字
*/
void CModuleMetaData::SetName(const std::string& strName)
{
m_strName=strName;
}
/**
* @brief 获取模块名字
*/
std::string CModuleMetaData::GetName() const
{
return m_strName;
}
/**
* @brief 设置模块描述
* @param strDescription 模块描述
*/
void CModuleMetaData::SetDescription(const std::string& strDescription)
{
m_strDescription=strDescription;
}
/**
* @brief 获取模块描述
*/
std::string CModuleMetaData::GetDescription() const
{
return m_strDescription;
}
void CModuleMetaData::GetInputPorts(std::vector<Port>& vecInputPorts)
{
if(vecInputPorts.size()>0){
vecInputPorts.clear();
}
for(std::vector<Port>::iterator it=m_vecPorts.begin();
it!=m_vecPorts.end(); ++it)
{
if(it->type==PORT_INPUT)
{
vecInputPorts.push_back(*it);
}
}
}
void CModuleMetaData::GetOutputPorts(std::vector<Port>& vecOutputPorts)
{
if(vecOutputPorts.size()>0){
vecOutputPorts.clear();
}
for(std::vector<Port>::iterator it=m_vecPorts.begin();
it!=m_vecPorts.end(); ++it)
{
if(it->type==PORT_OUTPUT)
{
vecOutputPorts.push_back(*it);
}
}
}
int CModuleMetaData::GetInputPortCount()
{
std::vector<Port> vct;
this->GetInputPorts(vct);
return int(vct.size());
}
int CModuleMetaData::GetOutputPortCount()
{
std::vector<Port> vct;
this->GetOutputPorts(vct);
return int(vct.size());
}
void CModuleMetaData::AddPort(const Port& port)
{
if(port.order==-1)
{
Port newPort(port);
newPort.order=int(m_vecPorts.size())-1;
m_vecPorts.push_back(newPort);
}
else
{
m_vecPorts.push_back(port);
}
}
void CModuleMetaData::AddPorts(PortType ePortType,int iPortCount)
{
std::stringstream ss;
for(int i=0; i<iPortCount; ++i)
{
Port newPort;
ss.clear();
ss << i;
newPort.name=ss.str();
newPort.order=i;
newPort.type=ePortType;
m_vecPorts.push_back(newPort);
}
}
std::string CModuleMetaData::GetStrLibName() const
{
return m_strLibName;
}
std::string CModuleMetaData::GetStrNameSpace() const
{
return m_strNameSpace;
}
void CModuleMetaData::SetStrLibName(std::string strLibName)
{
this->m_strLibName = strLibName;
}
void CModuleMetaData::SetStrNameSpace(std::string strNameSpace)
{
this->m_strNameSpace = strNameSpace;
}
void CModuleMetaData::SetAuthor(const std::string& strAuthor)
{
m_strAuthor = strAuthor;
}
std::string CModuleMetaData::GetAuthor() const
{
return m_strAuthor;
}
void CModuleMetaData::SetCreateTime(const std::string& strCreateTime)
{
m_strCreateTime = strCreateTime;
}
std::string CModuleMetaData::GetCreateTime() const
{
return m_strCreateTime;
}
void CModuleMetaData::SetLastModifyTime(const std::string& strLastModifyTime)
{
m_strLastModifyTime = strLastModifyTime;
}
std::string CModuleMetaData::GetLastModifyTime() const
{
return m_strLastModifyTime;
}
void CModuleMetaData::SetVersion(const std::string& strVersion)
{
m_strVersion = strVersion;
}
std::string CModuleMetaData::GetVersion() const
{
return m_strVersion;
}
void CModuleMetaData::SetSubCategory(const std::string& strSubCategory)
{
m_strSubCategory = strSubCategory;
}
std::string CModuleMetaData::GetSubCategory() const
{
return m_strSubCategory;
}
void CModuleMetaData::SetHelpDoc(const std::string& strHelpDoc)
{
m_strHelpDoc = strHelpDoc;
}
std::string CModuleMetaData::GetHelpDoc()const
{
return m_strID+"/"+m_strHelpDoc;
}
void CModuleMetaData::SetDimension(const std::string& strDimension)
{
m_strDimension = strDimension;
}
std::string CModuleMetaData::GetDimension() const
{
return m_strDimension;
}
void CModuleMetaData::SetDomain(const std::string& strDomain)
{
m_strDomain = strDomain;
}
std::string CModuleMetaData::GetDomain() const
{
return m_strDomain;
}
void CModuleMetaData::SetInputDomain(const std::string& strInputDomain)
{
m_strInputDataDomain = strInputDomain;
}
std::string CModuleMetaData::GetInputDomain() const
{
return m_strInputDataDomain;
}
void CModuleMetaData::SetOutputDomain(const std::string& strOutputDomain)
{
m_strOuputDataDomain =strOutputDomain;
}
std::string CModuleMetaData::GetOutputDomain() const
{
return m_strOuputDataDomain;
}
void CModuleMetaData::SetWorkUnit(const std::string& strWorkUnit)
{
m_strWorkUnit = strWorkUnit;
}
std::string CModuleMetaData::GetWorkUnit() const
{
return m_strWorkUnit;
}
void CModuleMetaData::SetHasInput(const bool& bHasInput)
{
m_bHasInput = bHasInput;
}
bool CModuleMetaData::GetHasInput() const
{
return m_bHasInput;
}
void CModuleMetaData::SetHasOutput(const bool& bHasOutput)
{
m_bHasOutput = bHasOutput;
}
bool CModuleMetaData::GetHasOutput() const
{
return m_bHasOutput;
}
void CModuleMetaData::SetIOType(const std::string& strIOType)
{
m_strIOType = strIOType;
}
std::string CModuleMetaData::GetIOType() const
{
return m_strIOType;
}
void CModuleMetaData::SetNeedOtherFile(const bool& bNeedOtherFile)
{
m_bNeedOtherFile = bNeedOtherFile;
}
bool CModuleMetaData::GetNeedOtherFile() const
{
return m_bNeedOtherFile;
}
void CModuleMetaData::SetNeedTmpMemory(const bool& bNeedTmpMemory)
{
m_bNeedTmpMemory = bNeedTmpMemory;
}
bool CModuleMetaData::GetNeedTmpMemory() const
{
return m_bNeedTmpMemory;
}
void CModuleMetaData::SetNeedOutputFile(const bool& bNeedOutputFile)
{
m_bOutputOtherFile = bNeedOutputFile;
}
bool CModuleMetaData::GetNeedOutputFile() const
{
return m_bOutputOtherFile;
}
void CModuleMetaData::SetNeedParameters(const bool& bNeedParameters)
{
m_bNeedParameters = bNeedParameters;
}
bool CModuleMetaData::GetNeedParameters() const
{
return m_bNeedParameters;
}
void CModuleMetaData::SetIsInterActive(const bool& bInterActive)
{
m_bIsInterActive = bInterActive;
}
bool CModuleMetaData::GetIsInterActive() const
{
return m_bIsInterActive;
}
void CModuleMetaData::SetComputeLevel(const double& iCompute)
{
m_iCompute = iCompute;
}
double CModuleMetaData::GetComputeLevel() const
{
return m_iCompute;
}
void CModuleMetaData::SetMemoryLevel(const double& iMemory)
{
m_iMemory = iMemory;
}
double CModuleMetaData::GetMemoryLevel() const
{
return m_iMemory;
}
void CModuleMetaData::SetParallelMode(const std::string& strParallelMode)
{
m_strParalleMode = strParallelMode;
}
std::string CModuleMetaData::GetParallelMode() const
{
return m_strParalleMode;
}
void CModuleMetaData::SetNeedReduce(const bool& bReduce)
{
m_bNeedReduce = bReduce;
}
bool CModuleMetaData::GetNeedReduce() const
{
return m_bNeedReduce;
}
// void CModuleMetaData::LoadFromJsonObject(const Json::Value& rMeta)
// {
// if(rMeta["NameSpace"].isString())
// this->SetStrNameSpace(rMeta["NameSpace"].asString());
// if(rMeta["LibName"].isString()){
// if(RemoveSpace(rMeta["LibName"].asString())=="")
// pai::log::Error("LibName of module is null ,please ask module developer to check following json content," + rMeta.toStyledString());
// this->SetStrLibName(rMeta["LibName"].asString());
// }
// if(rMeta["ModuleID"].isString()){
// if(RemoveSpace(rMeta["ModuleID"].asString())=="")
// pai::log::Error("ModuleID of module is null ,please ask module developer to check following json content," + rMeta.toStyledString());
// this->SetID(rMeta["ModuleID"].asString());
// }
// if(rMeta["ModuleName"].isString()){
// this->SetName(rMeta["ModuleName"].asString());
// }
// if(rMeta["ModuleDescription"].isString())
// this->SetDescription(rMeta["ModuleDescription"].asString());
// if(rMeta["Author"].isString())
// this->SetAuthor(rMeta["Author"].asString());
// if(rMeta["CreateTime"].isString())
// this->SetCreateTime(rMeta["CreateTime"].asString());
// if(rMeta["LastModifyTime"].isString())
// this->SetLastModifyTime(rMeta["LastModifyTime"].asString());
// if(rMeta["Version"].isString())
// this->SetVersion(rMeta["Version"].asString());
// if(rMeta["PAIVersion"].isString())
// this->SetPaiVersion(rMeta["PAIVersion"].asString());
// if(rMeta["Category"].isString())
// this->SetCategory(rMeta["Category"].asString());
// if(rMeta["SubCategory"].isString())
// this->SetSubCategory(rMeta["SubCategory"].asString());
// if(rMeta["HelpDoc"].isString())
// this->SetHelpDoc(rMeta["HelpDoc"].asString());
// if(rMeta["Dimension"].isString())
// this->SetDimension(rMeta["Dimension"].asString());
// if(rMeta["Domain"].isString())
// this->SetDomain(rMeta["Domain"].asString());
// if(rMeta["InputDataDomain"].isString())
// this->SetInputDomain(rMeta["InputDataDomain"].asString());
// if(rMeta["OutputDataDomain"].isString())
// this->SetOutputDomain(rMeta["OutputDataDomain"].asString());
// if(rMeta["WorkUnit"].isString())
// this->SetWorkUnit(rMeta["WorkUnit"].asString());
// if(rMeta["HasInput"].isBool())
// this->SetHasInput(rMeta["HasInput"].asBool());
// if(rMeta["HasOutput"].isBool())
// this->SetHasOutput(rMeta["HasOutput"].asBool());
// if(rMeta["IOType"].isString())
// this->SetIOType(rMeta["IOType"].asString());
// if(rMeta["NeedOtherFile"].isBool())
// this->SetNeedOtherFile(rMeta["NeedOtherFile"].asBool());
// if(rMeta["NeedTmpMemory"].isBool())
// this->SetNeedTmpMemory(rMeta["NeedTmpMemory"].asBool());
// if(rMeta["OutputOtherFile"].isBool())
// this->SetNeedOutputFile(rMeta["OutputOtherFile"].asBool());
// if(rMeta["NeedParameters"].isBool())
// this->SetNeedParameters(rMeta["NeedParameters"].asBool());
// if(rMeta["IsInterActive"].isBool())
// this->SetIsInterActive(rMeta["IsInterActive"].asBool());
// if(rMeta["Compute"].isDouble())
// this->SetComputeLevel(rMeta["Compute"].asDouble());
// if(rMeta["Memory"].isDouble())
// this->SetMemoryLevel(rMeta["Memory"].asDouble());
// if(rMeta["ParallelMode"].isString())
// this->SetParallelMode(rMeta["ParallelMode"].asString());
// if(rMeta["NeedReduce"].isBool())
// this->SetNeedReduce(rMeta["NeedReduce"].asBool());
// if(rMeta["StageNum"].isString())
// this->SetStageNum(rMeta["StageNum"].asString());
// if(rMeta["SplitStage"].isString())
// this->SetSplitStage(rMeta["SplitStage"].asString());
// if(rMeta["OutputDataTypes"].isString())
// {
// //把小写全部转化成大写字符串
// std::string strOutputTypes = rMeta["OutputDataTypes"].asString();
// for(std::string::iterator iter=strOutputTypes.begin(); iter!=strOutputTypes.end(); ++iter)
// {
// if(islower(char(*iter))) *iter = char(toupper(char(*iter)));
// }
// if(strOutputTypes.empty())
// {
// AddOutputType(None);
// }
// else
// {
// //设置OutputTypes
// std::vector<std::string> vecOutputTypes;
// SplitByChar(strOutputTypes,';',vecOutputTypes);
// CParameterItem tmpItem;
// for(unsigned int i=0; i<vecOutputTypes.size(); ++i)
// {
// if(!vecOutputTypes[i].empty())
// {
// AddOutputType(tmpItem.GetAcceptDropTypeMap()[vecOutputTypes[i]]);
// }
// }
// }
// }
// }
// void CModuleMetaData::LoadIOFromJsonObject(const PortType pIO, const Json::Value& root)
// {
// Json::Value vIO;
// if(pIO == PORT_INPUT)
// {
// vIO = root["Input"];
// }
// else if(pIO == PORT_OUTPUT)
// {
// vIO = root["Output"];
// }
// if(!vIO.isNull())
// {
// for(unsigned int i=0; i<vIO.size(); i++)
// {
// Port newPort;
// newPort.type = pIO;
// if(vIO[i]["SN"].isInt())
// newPort.order = vIO[i]["SN"].asInt();
// if(vIO[i]["Name"].isString())
// newPort.name = vIO[i]["Name"].asString();
// if(vIO[i]["type"].isString())
// newPort.connectedModuleType = vIO[i]["type"].asString();
// if(vIO[i]["Optional"].isBool())
// newPort.optional = vIO[i]["Optional"].asBool();
// this->AddPort(newPort);
// }
// }
// }
std::string CModuleMetaData::GetPaiVersion() const
{
return m_strPaiVersion;
}
void CModuleMetaData::SetPaiVersion(std::string strPaiVersion)
{
this->m_strPaiVersion = strPaiVersion;
}
void CModuleMetaData::AddOutputType(OutputType outputType)
{
m_iOutputTypes |= outputType;
}
void CModuleMetaData::SetStageNum(std::string stageNum)
{
m_strStageNum = stageNum;
}
std::string CModuleMetaData::GetStageNum() const
{
return m_strStageNum;
}
void CModuleMetaData::SetSplitStage(std::string SplitStage)
{
m_SplitStage = SplitStage;
}
std::string CModuleMetaData::GetSplitStage() const
{
return m_SplitStage;
}
// std::vector<OutputType> CModuleMetaData::GetOutputTypes() const
// {
// std::vector<OutputType> vecResult;
// if(m_iOutputTypes == 0)
// {
// return vecResult;
// }
// CParameterItem tmpItem;
// std::map<std::string,AcceptDropType> mapOutputTypes = tmpItem.GetAcceptDropTypeMap();
// std::map<std::string,AcceptDropType>::const_iterator it;
// for(it = mapOutputTypes.begin(); it != mapOutputTypes.end(); ++it )
// {
// if((m_iOutputTypes & it->second) == it->second )
// {
// vecResult.push_back(it->second);
// }
// }
// return vecResult;
// }
std::string CModuleMetaData::RemoveSpace(std::string str)
{
//去掉前面的空格
size_t pos_value_front_space = str.find_first_not_of(" \t");
if (pos_value_front_space != std::string::npos) {
str.erase(0, pos_value_front_space);
}
//去掉后面的空格
size_t pos_value_end_space = str.find_last_not_of(" \t");
if (pos_value_end_space != std::string::npos) {
str.erase(pos_value_end_space + 1);
}
return str;
}
}
}