Question

Evaluate an expression in a C++ plugin


Badge

Hi all, I am developing a C++ plugin with a new IFMEDevFactory.

The "processClause" method of the factory gets an attribute (TEXT_OR_ATTR-type) as an encoded string:

@EvaluateExpression(FDIV,STRING,<at>Value<openparen>mypath<closeparen>,MyModule)

How do I evaluate this to resolve the real "mypath" value?

Thanks in advance!


3 replies

Userlevel 4

Hi

I do not have first-hand experience with the C++ API, but in Python it could perhaps look something like this:

import fmeobjects
encoded_text = '@EvaluateExpression(FDIV,STRING,<at>Value<openparen>mypath<closeparen>,MyModule)'
decoded_text = fmeobjects.FMESession().decodeFromFMEParsableText(encoded_text)
mypath = my_feature.performFunction(decoded_text)

It seems that the method decodeFromFMEParsableText() is located in IFMEString in the C++ libraries, however.

Hope this gives you some ideas.

David

Badge

Thanks a lot david!!!! It works for me.

My plugin is a mixed CLI/C++ DLL, the code ....

// Expand expressions of Keywords ?
for each (String^ key in gcnew List<String^>(static_cast<IDictionary<String^,String^>^>(_keywords)->Keys))
{
  String^ value = _keywords->default[key];

  if (value->Contains("@"))
  {
    std::string tempString = msclr::interop::marshal_as<std::string>( value );
    IFMEString* v = _fmeSession->createString();
    IFMEString* r = _fmeSession->createString();

    *v = tempString.c_str(); 
    v->decodeFromFMEParsableText();

    FME_MsgNum rs = feature->performFunction(*v, *r);
    if (rs==FME_SUCCESS)
    {
      _keywords->default[key] = gcnew String(r->data());
    }
    _fmeSession->destroyString(v);
    _fmeSession->destroyString(r);
  }
}

Alvaro

Userlevel 4

Thanks a lot david!!!! It works for me.

My plugin is a mixed CLI/C++ DLL, the code ....

// Expand expressions of Keywords ?
for each (String^ key in gcnew List<String^>(static_cast<IDictionary<String^,String^>^>(_keywords)->Keys))
{
  String^ value = _keywords->default[key];

  if (value->Contains("@"))
  {
    std::string tempString = msclr::interop::marshal_as<std::string>( value );
    IFMEString* v = _fmeSession->createString();
    IFMEString* r = _fmeSession->createString();

    *v = tempString.c_str(); 
    v->decodeFromFMEParsableText();

    FME_MsgNum rs = feature->performFunction(*v, *r);
    if (rs==FME_SUCCESS)
    {
      _keywords->default[key] = gcnew String(r->data());
    }
    _fmeSession->destroyString(v);
    _fmeSession->destroyString(r);
  }
}

Alvaro

Glad to hear you found a solution! Thanks for posting the working code as well.

Reply