CHANGED: #1471 Moved CProcedure code to it's own files, and also moved the procedure handling code from CInterfaceManager to CWidgetManager.
--HG-- branch : gui-refactoringhg/feature/sse2
parent
530b542e4a
commit
11d2efb96f
@ -0,0 +1,77 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef PROC_H
|
||||
#define PROC_H
|
||||
|
||||
#include "nel/misc/types_nl.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
class CParamBlock
|
||||
{
|
||||
public:
|
||||
// -1 if not a param id, but a string
|
||||
sint32 NumParam;
|
||||
std::string String;
|
||||
|
||||
CParamBlock()
|
||||
{
|
||||
NumParam = -1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CProcAction
|
||||
{
|
||||
public:
|
||||
// a condition to launch this action handler (is an expression)
|
||||
std::vector< CParamBlock > CondBlocks;
|
||||
|
||||
// the action handler (may be proc!!)
|
||||
std::string Action;
|
||||
// A list of string/or param number => to build the final params at execution
|
||||
std::vector< CParamBlock > ParamBlocks;
|
||||
|
||||
// build a paramBlock from a string
|
||||
void buildParamBlock( const std::string ¶ms );
|
||||
// from ParamBlock, and a paramList (skip the 0th), build params.
|
||||
void buildParams( const std::vector< std::string > ¶mList, std::string ¶ms ) const;
|
||||
|
||||
void buildCondBlock( const std::string ¶ms );
|
||||
|
||||
void buildCond( const std::vector< std::string > ¶mList, std::string &cond ) const;
|
||||
|
||||
static void buildBlocks( const std::string &in, std::vector< CParamBlock > &out );
|
||||
|
||||
static void eval( const std::vector< std::string > &inArgs, const std::vector< CParamBlock > &inBlocks, std::string &out );
|
||||
|
||||
};
|
||||
|
||||
|
||||
class CProcedure
|
||||
{
|
||||
public:
|
||||
// List of the actions
|
||||
std::vector< CProcAction > Actions;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,167 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "nel/gui/proc.h"
|
||||
#include "nel/misc/algo.h"
|
||||
|
||||
using namespace NLMISC;
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
|
||||
#define PROC_PARAM_IDENT '@'
|
||||
|
||||
// ***************************************************************************
|
||||
void CProcAction::buildParamBlock( const std::string ¶ms )
|
||||
{
|
||||
buildBlocks( params, ParamBlocks );
|
||||
}
|
||||
|
||||
void CProcAction::buildParams( const std::vector< std::string > ¶mList, std::string ¶ms ) const
|
||||
{
|
||||
eval( paramList, ParamBlocks, params );
|
||||
}
|
||||
|
||||
void CProcAction::buildCondBlock( const std::string ¶ms )
|
||||
{
|
||||
buildBlocks( params, CondBlocks );
|
||||
}
|
||||
|
||||
void CProcAction::buildCond( const std::vector< std::string > ¶mList, std::string ¶ms ) const
|
||||
{
|
||||
eval( paramList, CondBlocks, params );
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CProcAction::buildBlocks( const std::string &in, std::vector< CParamBlock > &out )
|
||||
{
|
||||
out.clear();
|
||||
|
||||
if(in.empty())
|
||||
return;
|
||||
|
||||
std::string lastString;
|
||||
std::string::size_type curPos= 0;
|
||||
std::string::size_type lastPos= 0;
|
||||
|
||||
//if it has some @ then solve proc value
|
||||
while( (curPos=in.find(PROC_PARAM_IDENT, curPos)) != std::string::npos)
|
||||
{
|
||||
// If it is end of line
|
||||
if(curPos==in.size()-1)
|
||||
{
|
||||
// then skip
|
||||
curPos= in.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Skip all @
|
||||
uint countNbIdent = 0;
|
||||
while (curPos<in.size() && in[curPos]==PROC_PARAM_IDENT)
|
||||
{
|
||||
curPos++;
|
||||
countNbIdent++;
|
||||
}
|
||||
|
||||
// get the id pos
|
||||
uint countNbDigit = 0;
|
||||
uint startIdPos= (uint)curPos;
|
||||
while (curPos<in.size() && in[curPos]>='0' && in[curPos]<='9')
|
||||
{
|
||||
curPos++;
|
||||
countNbDigit++;
|
||||
}
|
||||
|
||||
if (curPos == startIdPos)
|
||||
{
|
||||
// No digit so it is a normal db entry
|
||||
lastString+= in.substr (lastPos, curPos-(countNbIdent-1)-lastPos);
|
||||
// all @ are skipped
|
||||
}
|
||||
else
|
||||
{
|
||||
// There is some digit it is an argument
|
||||
|
||||
// copy the last not param sub string.
|
||||
sint nbToCopy = (sint)(curPos-countNbIdent-countNbDigit-lastPos);
|
||||
if (nbToCopy > 0)
|
||||
lastString += in.substr(lastPos, nbToCopy);
|
||||
|
||||
// if not empty, add to the param block
|
||||
if (!lastString.empty())
|
||||
{
|
||||
CParamBlock pb;
|
||||
pb.String = lastString;
|
||||
out.push_back(pb);
|
||||
// clear it
|
||||
lastString.clear();
|
||||
}
|
||||
|
||||
// get the param id
|
||||
sint paramId;
|
||||
fromString(in.substr(startIdPos, curPos-startIdPos), paramId);
|
||||
// Add it to the param block
|
||||
CParamBlock pb;
|
||||
pb.NumParam = paramId;
|
||||
out.push_back(pb);
|
||||
}
|
||||
|
||||
// valid pos is current pos
|
||||
lastPos= curPos;
|
||||
}
|
||||
}
|
||||
// concat last part
|
||||
lastString+= in.substr(lastPos, in.size()-lastPos);
|
||||
if(!lastString.empty())
|
||||
{
|
||||
CParamBlock pb;
|
||||
pb.String = lastString;
|
||||
out.push_back(pb);
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CProcAction::eval( const std::vector<std::string> &inArgs, const std::vector< CParamBlock > &inBlocks, std::string &out )
|
||||
{
|
||||
// clear the ret string
|
||||
out.clear();
|
||||
|
||||
// for all block
|
||||
for (uint i=0; i < inBlocks.size(); i++)
|
||||
{
|
||||
const CParamBlock &pb = inBlocks[i];
|
||||
// if the block is a raw string
|
||||
if (pb.NumParam < 0)
|
||||
{
|
||||
// concat with the block
|
||||
out += pb.String;
|
||||
}
|
||||
// else get from paramList
|
||||
else
|
||||
{
|
||||
// add 1, because paramList[0] is the name of the procedure
|
||||
sint idInList = pb.NumParam+1;
|
||||
// if param exist
|
||||
if (idInList < (sint)inArgs.size())
|
||||
// concat with the params
|
||||
out += inArgs[idInList];
|
||||
// else skip (should fail)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue