FormatStatement and maxon DataTypes...



  • Is there any information available on how the Maxon DataTypes implement ToString()'s FormatStatement?
    And secondly, a maxon::Data with nullptr as argument gives a different result than an unconfigured FormatStatement argument. Is this intended behaviour?

    // Store values
    	template <typename T>
    	void CreateAttribute(maxon::String name, T value)
    	{
    		_attributes.Set(name, value);
    	}
    
    // ........
    
    myElement->CreateAttribute("MyAttributeName"_s, 23.0);
    
    // To print them:
    maxon::String buf;
    maxon::FormatStatement fs;
    buf += " "_s + attrib.first.ToString(nullptr) + "=\""_s + attrib.second.ToString(nullptr) + "\""_s; // This gives another result than
    //buf += " "_s + attrib.first.ToString(nullptr) + "=\""_s + attrib.second.ToString(fs) + "\""_s
    
    DiagnosticOutput("@", buf);
    


  • Hello,

    there is no information available on how a specific data type implements ToString(). You can find the implementation of some data type's ToString() function in the corresponding header for source file in the framework.

    Could you explain your second question a bit more? What data exactly is stored in maxon::Data? What is stored in attrib.second?

    General information on data types and FormatStatement is available in these manuals:

    If you want to combine strings as show in your code you can also use FormatString(). See String Manual.

    best wishes,
    Sebastian



  • Hey Sebastian,

    thanks for
    @s_bach said in FormatStatement and maxon DataTypes...:

    Could you explain your second question a bit more? What data exactly is stored in maxon::Data? What is stored in attrib.second?

    Sure. I'm storing a key value pair of maxon::String and a variable type (Float, String, Int, Vector, etc.).
    for example:

    maxon::DataDictionary dict;
    dict.Set("MyKey"_s, maxon::Float(3.0)); // or simply dict.Set("MyKey"_s, 3.0)
    // and so on...
    

    After that I'm iterating the dictionary and use DiagnosticOutput for printing to IDE console:

    for (const auto& data: dict)
    {
        DiagnosticOutput("Key: @ / Value: @"_s, data.first.ToString(nullptr), 
            data.second.ToString(nullptr) // If I replace the nullptr here with a dummy FormatStatement, the output changes from `3` to `3.000`
    }
    
    

    I don't understand why the nullptr gives a different result than with given an empty FormatStatement?

    By the way, thanks for pointing me to FormatString (didn't know about that one), that's very helpful. :)

    edit: One of the reasons I'm asking this, is because in case of a vector, ToString outputs something like (3.0, 2.5, 11.6) - note the braces.
    I wanted to know if there are some identifiers available that change the output, therefore my initial question. Searched the headers already, no success. :)



  • Hello,

    I can only assume that somewhere deep inside Cinema there is a switch that formats the output depending on the given FormatStatement argument.

    If you want to format a value manually, there are many conversion functions: Conversion

    You can use maxon::String::FloatToString() to define how a float value is formatted.

    The implementation of a vector's ToString() function can be found in the vec.h header file:

    String ToString(const FormatStatement* formatStatement) const
    {
      return "("_s + maxon::ToString(x, formatStatement) + ","_s + maxon::ToString(y, formatStatement) + ","_s + maxon::ToString(z, formatStatement) + ")"_s;
    }
    

    best wishes,
    Sebastian



  • Ah, thank you. I didn't take a look at vec.h.
    Meanwhile, I already wrote a conversion unit to handle all sorts of formatting. Thought, it was possible to modify the intern string conversions somehow. But nevermind, all works pretty well. :)

    Cheers,
    Robert