[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: implementation language [was: library for unicode collation in C for
From: |
Per Bothner |
Subject: |
Re: implementation language [was: library for unicode collation in C for texi2any?] |
Date: |
Sun, 15 Oct 2023 12:00:51 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 |
On 10/15/23 05:41, Gavin Smith wrote:
texi2any is full of code like this:
if ($target_element->{'extra'}
and $target_element->{'extra'}->{'unit_command'}) {
if ($target_element->{'extra'}->{'unit_command'}->{'cmdname'} eq
'node') {
$command = $target_element->{'extra'}->{'unit_command'};
} elsif ($target_element->{'extra'}->{'unit_command'}->{'extra'}
and $target_element->{'extra'}->{'unit_command'}
->{'extra'}->{'associated_node'}) {
$command = $target_element->{'extra'}->{'unit_command'}
->{'extra'}->{'associated_node'};
}
}
I'm far from a C++ expert these days, but some ideas:
* First of course you can define some helper methods:
class TargetElement {
Extra *extra;
Command *unit_command() { return extra ? extra->init_command() : nullptr; }
}
* Declarations in 'if' statement:
if (auto unit_command = target_elememt->unit_command()) {
if (unit_command->cmdname() == "node") ...
}
* Some kind of smart pointer may be useful.
However, I don't really have a good handle on smart pointer,
and I don't know if this further than you want to go in terms of C++-isms.
I can do some research, though.
* Perhaps use a subclass for the "extra" fields:
class TargetElementWithExtra :: TargetElement {
Command *unit_command;
}
if (auto te = dynamic_cast<TargetElementWithExtra*>(target_element)) {
// te is target_element safely cast to TargetElementWithExtra*.
}
--
--Per Bothner
per@bothner.com http://per.bothner.com/
- implementation language [was: library for unicode collation in C for texi2any?], (continued)
- Re: implementation language [was: library for unicode collation in C for texi2any?], Patrice Dumas, 2023/10/14
- Re: implementation language [was: library for unicode collation in C for texi2any?], Per Bothner, 2023/10/14
- Re: implementation language [was: library for unicode collation in C for texi2any?], Per Bothner, 2023/10/14
- Re: implementation language [was: library for unicode collation in C for texi2any?], Gavin Smith, 2023/10/15
- Re: implementation language [was: library for unicode collation in C for texi2any?],
Per Bothner <=
- Re: implementation language [was: library for unicode collation in C for texi2any?], Gavin Smith, 2023/10/16
- Re: implementation language [was: library for unicode collation in C for texi2any?], Per Bothner, 2023/10/16
- Re: implementation language [was: library for unicode collation in C for texi2any?], Leo Butler, 2023/10/16
Re: library for unicode collation in C for texi2any?, Gavin Smith, 2023/10/14