Exemplo n.º 1
0
	void set(const char * key, int val){
		if(keys->isIn(key)){
			valarray->get(keys->indexofVal(key))->add(val);
		}
		else{
			keys->add(key);
			DynArray<int> *vala = new DynArray<int>();
			vala->add(val);
			valarray->add(vala);
		}
			
	}
Exemplo n.º 2
0
  // ---------------------------------------------------------------- //
  bool CommandInterpreter::parse( CommandProcessor& cp, const char* command )
  {
    if (!command)
      return false;
    if(command[0] == '#') //Comment
      return true;
    
    // Split the command into full command name and parameter list
    DynArray<string> split;
    { FOREACH_TOKEN( token, command, "()" ) split.add( token ); }
    if( split.size() < 1 || split.size() > 2 ) return false;

    const char* strFullCommandName = "EMPTY";
    const char* strParams          = "EMPTY";
    if(split.size() >= 1) {
      strFullCommandName = split[0].c_str();
      if(split.size() == 2)
        strParams = split[1].c_str();
    }

    // Request the command
    CommandRef commandRef = cp.requestCommand( strFullCommandName );
    if( commandRef && commandRef->object )
    {
      CommandParameters* cmdParams;
      parseParams( cp, commandRef, strParams, cmdParams );

      // Call the command
      commandRef->action->call( commandRef->object, *cmdParams );

      delete cmdParams;
      return true;
    }

    parseErrors.add("Command not found.");
    return false;
  }
Exemplo n.º 3
0
  // ---------------------------------------------------------------- //
  bool CommandInterpreter::parseParams( CommandProcessor&            cp
                                      , CommandCached const * const  cmd
                                      , const char*                  strParams
                                      , CommandParameters*&          out )
  {
    // Now split the parameter list
    DynArray<const char*> params;
    { FOREACH_TOKEN( token, strParams, "," ) params.add( token ); }

    // Make sure the parameter list is the expected size
    if( params.size() < cmd->input.size() )
    {
      parseErrors.add("Not enough parameters.");
      return false;
    }

    // Loop through the signature and pack all of the parameters into the command parameters class
    out = new CommandParameters( cmd->getSignatureSize( cp, params ) );
    int offset = 0;
    for( int i=0; i<cmd->input.size(); ++i )
      parseAndPack( cp, cmd->input[i], params[i], *out, offset );

    return true;
  }