Skip to main content
Question

Evaluate an expression in a C++ plugin


ahuarte47
Contributor
Forum|alt.badge.img+3

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

david_r
Celebrity
  • March 9, 2016

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


ahuarte47
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • March 9, 2016

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


david_r
Celebrity
  • March 9, 2016
ahuarte47 wrote:

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings