Giter Club home page Giter Club logo

Comments (11)

brdandu avatar brdandu commented on June 19, 2024
<struct name="SimpleStruct">
        <cluster code="0x050F"/>
        <item name="a" type="UINT8U" optional="false"/>
        <item name="b" type="BOOLEAN" optional="false"/>
        <item name="c" define="SimpleEnum" type="ENUM8" optional="false"/>
DROP TABLE IF EXISTS "STRUCT_ITEM";
CREATE TABLE IF NOT EXISTS "STRUCT_ITEM" (
  "STRUCT_REF" integer,
  "FIELD_IDENTIFIER" integer,
  "NAME" text,
  "TYPE" text,
  "IS_ARRAY" integer,
  "MIN_LENGTH" integer,
  "MAX_LENGTH" integer,
  "IS_WRITABLE" integer,
  foreign key (STRUCT_REF) references STRUCT(STRUCT_ID)
);

looks like currently zap don't support struct item with define ?

for enum type, we would like to get "define"

then I can write {{asType label}} = static_cast<{{define}}>(v);

An alternate way to do this with the existing version can be {{asType label}} = static_cast<{{as_delimited_macro name}}>(v);

from zap.

yunhanw-google avatar yunhanw-google commented on June 19, 2024

it does not work as expected if using {{asType label}} = static_cast<{{as_delimited_macro name}}>(v), which returns c = static_cast(v);

from zap.

brdandu avatar brdandu commented on June 19, 2024

Could you give me the example template on how you are using this?

from zap.

tecimovic avatar tecimovic commented on June 19, 2024

I'm a bit confused with this, @yunhanw-google :
why would we not simply do:

<item name="c"  type="SimpleEnum" optional="false"/>

instead of:

<item name="c" define="SimpleEnum" type="ENUM8" optional="false"/>

from zap.

yunhanw-google avatar yunhanw-google commented on June 19, 2024

If I define this way,

how can I check SimpleEnum is enum type?

{{#if (isEnum type) }}
uint8_t v;
ReturnErrorOnFailure(ClusterObjectUtils::Decode(reader, v));
//zap issue 231 to return right enum type
{{asType label}} = static_cast<{{asUnderlyingZclType type}}>(v);
break;

i need to write this kind of code
check if it is enum type, then generate some code

from zap.

yunhanw-google avatar yunhanw-google commented on June 19, 2024

Could you give me the example template on how you are using this?

        {{#zcl_struct_items}}
        case k{{asType label}}FieldId:
            {{#if (isEnum type) }}
            uint8_t v;
            ReturnErrorOnFailure(ClusterObjectUtils::Decode(reader, v));
            //zap issue 231 to return right enum type
            {{asType label}} = static_cast<{{define}}>(v);
            break;
            {{else if isArray}}
            return CHIP_ERROR_NOT_IMPLEMENTED;
            {{else}}
            ReturnErrorOnFailure(ClusterObjectUtils::Decode(reader, {{asType label}}));
            break;
            {{/if}}
        {{/zcl_struct_items}}

from zap.

yunhanw-google avatar yunhanw-google commented on June 19, 2024

another alternative is that, we add one additional flag, isEnum similar to isArray for struct item(#229)

from zap.

brdandu avatar brdandu commented on June 19, 2024

There is this helper which may be helpful.
{{#if_is_enum type}}
type is enum
{{else}}
type is not enum
{{/if_is_enum}}

Regarding "static_cast<{{as_delimited_macro name}}>(v), which returns c = static_cast(v);" I am not sure why this happened. Is this for a particular struct item or all of them?

from zap.

yunhanw-google avatar yunhanw-google commented on June 19, 2024

There is this helper which may be helpful.
{{#if_is_enum type}}
type is enum
{{else}}
type is not enum
{{/if_is_enum}}

Just tried, it cannot detect SimpleEnum is enum.
The issue here is that the internal zap don't have knowledge about the customized enum type currently. Either zap know how to parse define, or parse isEnum or some other way zap get knowledge from xml to know it is enum

from zap.

tecimovic avatar tecimovic commented on June 19, 2024

So if I do this, does this meet your meeds:
1.) Add the IS_ENUM field in the DB.
2.) Allow for isEnum="true" in the XML.
3.) load and populate these flags.
4.) Give you a helper is_enum_type or something like that that will allow to modify how these types are generated.

from zap.

tecimovic avatar tecimovic commented on June 19, 2024

Closed in PR 235

from zap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.