|
honey the codewitch wrote: there was a cleaner way to do this stuff
I give up...why is this specific bit of code better as a template versus a method?
To me a method would be cleaner. And it would allow you to do what you want.
|
|
|
|
|
A method would precompute the arbitrary bitshifts needed to craft a bitmap with the appropriate binary footprint, set individual arbitrary color channels, etc, at compile time? AFAIK a method cannot define a type.
constexpr won't do that. It must be some C++20 or beyond feature I'm not aware of, but to solve this problem in C++17 requires a template.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
honey the codewitch wrote: It must be some C++20 or beyond feature I'm not aware of
Not at all.
So you want to use certain fixed values in your code, but you don't want to compute them (presumably manually.)
So write an executable that outputs those values as code statements. I suspect
1. That executable (the code) is more obvious in its purpose
2. It can be modified to do the part that you claim is missing.
3. It will make the target code less confusing.
You can even make the execution of that executable part of your build process.
|
|
|
|
|
I'm not using a code generator. C++ already has one built in. It's called template and that's literally what it's designed to do.
Anyway, I'd rather deal with it's weirdness than write code generators for everything, at which point I'd just use C because template and constexpr are the only reason I care about C++ over C.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
honey the codewitch wrote: I'm not using a code generator. C++ already has one built in. It's called template and that's literally what it's designed to do.
Rather certain that is not why they were specifically added to the language.
The fact that you can do that is ok. Just not what they exist for.
Following agrees with my understanding of the addition.
Template (C++) - Wikipedia[^]
"Major inspirations for C++ templates were the parameterized module"
honey the codewitch wrote: I'd rather deal with it's weirdness than write code generators for everything
One case doesn't mean you would need to to it for all.
And your lament is that it does not have all the functionality you would like for this specific situation. So you can hack around it or find another solution.
honey the codewitch wrote: Anyway, I'd rather deal
Again this is another difference in domain spaces. Maintenance for you is based on what you do because that is the business model that you have created.
For me I must consider how others will maintain what I have created. So for complex solutions I must consider the totality of what some future developer might be dealing with when they look at my code. So I would consider a one off module as being more understandable rather than perhaps several different code paths to work around to a potential solution.
|
|
|
|
|
I do use code generation where template won't suffice, like generating state machines, but it complicates the build process.
In the end metaprogramming evolved from simple GP without intrinsic language support for it and that is ultimately what I'm complaining about.
Newer iterations of C++ post say 20 are starting to rectify this, and make the concepts more "first class"
That will improve readability without complicating the build.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
Forgive the multiple replies but I think maybe I'm not explaining the above.
That is user code in the OP. That defines a pixel type that DirectX can consume.
There are others. I've pasted a swath of additional definitions for other types of pixels that are commonly used in my library.
You can then take a pixel type and do like this
using fb_t = bitmap<bgrx_pixel<32>>;<br />
uint8_t fb_buffer[fb_t::sizeof_buffer(screen_size)];<br />
fb_t fb(screen_size,fb_buffer);
Then when you proceed to draw to fb it's begin() method (pointing to fb_buffer in this case) contains bitmap data of that format based on the definition in the OP.
If it was an 18 bit pixel, as some weird graphics devices support, it would do that too. They aren't necessarily even on clean byte boundaries.
Forgive the following, but hopefully it provides useful context
template<size_t BitDepth>
using rgb_pixel = pixel<
channel_traits<channel_name::R,(BitDepth/3)>,
channel_traits<channel_name::G,((BitDepth/3)+(BitDepth%3))>,
channel_traits<channel_name::B,(BitDepth/3)>
>;
template<size_t BitDepth>
using rgba_pixel = pixel<
channel_traits<channel_name::R,(BitDepth/4)>,
channel_traits<channel_name::G,((BitDepth/4)+(BitDepth%4))>,
channel_traits<channel_name::B,(BitDepth/4)>,
channel_traits<channel_name::A,(BitDepth/4),0,(1<<(BitDepth/4))-1,(1<<(BitDepth/4))-1>
>;
template<size_t BitDepth>
using gsc_pixel = pixel<
channel_traits<channel_name::L,BitDepth>
>;
template<size_t BitDepth>
using yuv_pixel = pixel<
channel_traits<channel_name::Y,((BitDepth/3)+(BitDepth%3))>,
channel_traits<channel_name::U,(BitDepth/3)>,
channel_traits<channel_name::V,(BitDepth/3)>
>;
template<size_t BitDepth>
using yuva_pixel = pixel<
channel_traits<channel_name::Y,((BitDepth/4)+(BitDepth%4))>,
channel_traits<channel_name::U,(BitDepth/4)>,
channel_traits<channel_name::V,(BitDepth/4)>,
channel_traits<channel_name::A,(BitDepth/4),0,(1<<(BitDepth/4))-1,(1<<(BitDepth/4))-1>
>;
template<size_t BitDepth>
using ycbcr_pixel = pixel<
channel_traits<channel_name::Y,((BitDepth/3)+(BitDepth%3))>,
channel_traits<channel_name::Cb,(BitDepth/3)>,
channel_traits<channel_name::Cr,(BitDepth/3)>
>;
template<size_t BitDepth>
using ycbcra_pixel = pixel<
channel_traits<channel_name::Y,((BitDepth/4)+(BitDepth%4))>,
channel_traits<channel_name::Cb,(BitDepth/4)>,
channel_traits<channel_name::Cr,(BitDepth/4)>,
channel_traits<channel_name::A,(BitDepth/4),0,(1<<(BitDepth/4))-1,(1<<(BitDepth/4))-1>
>;
template<size_t BitDepth>
using indexed_pixel=pixel<channel_traits<channel_name::index,BitDepth>>;
template<size_t BitDepth>
using hsv_pixel = pixel<
channel_traits<channel_name::H,(BitDepth/3)>,
channel_traits<channel_name::S,(BitDepth/3)>,
channel_traits<channel_name::V,((BitDepth/3)+(BitDepth%3))>
>;
template<size_t BitDepth>
using hsva_pixel = pixel<
channel_traits<channel_name::H,(BitDepth/4)>,
channel_traits<channel_name::S,(BitDepth/4)>,
channel_traits<channel_name::V,((BitDepth/4)+(BitDepth%4))>,
channel_traits<channel_name::A,(BitDepth/4),0,(1<<(BitDepth/4))-1,(1<<(BitDepth/4))-1>
>;
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
EDIT
OK using g - as in "global" shoud work , but it does not
result = BTUL->EditLine_RegExp(result, "(\\w+ \g)");
Where is my error ??
I am having mental block - forgot how to add " match all words ":.
Here is my failing attempt to do so
result = BTUL->EditLine_RegExp(result, "(\\w+*)" );
Can somebody help me to modify my regular expression to
match all words
PLEASE
No references to AI regular expression generators
- they do not do well multiple entries.
modified 26-Oct-23 13:23pm.
|
|
|
|
|
Are you sure you want \w That includes 0-9 and underscore (_ ), as well as alphabetic characters, which may not be what you want.
Is your intention to capture a set of all words in the input text? Is that what BTUL->EditLine_RegExp() does? I googled for EditLine_RegExp , and got precisely zero results, so maybe you can explain where that comes from and what it returns?
Keep Calm and Carry On
|
|
|
|
|
Try this:
Match all words[^]
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The following will find all words:
/\w+/g
You can test it quite quickly at RegExr: Learn, Build, & Test RegEx[^].
But it would help if you showed us the actual text you are working with, and the results you get.
And please use <pre> tags around the code parts so your question is clear.
|
|
|
|
|
Many thanks for all the support.
FYI
I did use "[ -~]+" to extract first continuous words. Now I am working on to extract ALL words...
I did try pass "[/\w+/g]+" to my otherwise working function and ended up with [/w+/g]+
- the back slash is missing,
And this is result , part of my debug messages
" instring text \t\n Waiting to connect to bluetoothd..."
" regular expression \t\n [/w+/g]+"
" Has all match g"
You asked for the string I am trying to extract stuff from
here it is
"Waiting to connect to bluetoothd...\r\u001B[0;94m[bluetooth]\u001B[0m# \r\r\u001B[0;94m[bluetooth]\u001B[0m# \r \rAgent registered\n\u001B[0;94m[bluetooth]\u001B[0m# "
As you can see - the extracted "g" is from "Agent". No good...
I suspect Qt is messing with passing the backslash...
result = BTUL->EditLine_RegExp_Ext(result, "[/\w+/g]+",textEditPtr_DEBUG, textEditPtr_DEBUG);
<pre lang="C++">
"Waiting to connect to bluetoothd..."
"Waiting to connect to bluetoothd..."
"START EditLine_RegExp...QString BT_Utility_Library::EditLine_RegExp_Ext(QString, QString, QTextEdit *, QTextEdit *)1321"
" instring text \t\n Waiting to connect to bluetoothd..."
" regular expression \t\n [/w+/g]+"
" Has all match g"
|
|
|
|
|
The backslash character is used as the escape character within strings, so you need to escape it:
"[/\\w+/g]+"
|
|
|
|
|
Salvatore Terress wrote: Where is my error ??
Your question is not specific to regular expressions but also to what is running the regular expression engine. But you did not provide that information.
A 'g' is something that is external to regular expressions. So where you are using it is important and the only clue you provided is 'EditLine_RegExp' which googling for returned no results. But certainly since you didn't escape the backslash for the g that would never work.
Other than that of course there is also the following
- A space is not considered a word. Your capture group includes that.
- There could be more than one space.
- Are you matching on a single line? If not there are other complications.
- If there is ONLY words in your line then it is pointless to use regex at all. Just split it.
- If there are OTHER things besides words then I don't believe what you are doing will work (but again you didn't state what so maybe it is.)
|
|
|
|
|
Your question is not specific to regular expressions but also to what is running the regular expression engine. But you did not provide that information.
Since most of "AI reg expressions" generators are working and Qt SAME expression does not - you have a point.
I guess I will ask in Qt forum about that.
Yes, there are other means to verify that the string contains desired word, (QString "contains" method works peachy )
however, I sure like to learn more about using regular expression - so I like to stick with reg expressions for now.
ADDENDUM
My post is about using regular expression - it is NOT about the function I am using to actually implement regular expression. That function works as expected and there is no need to evacuate that function here.
If it did not work as desired I would say so.
|
|
|
|
|
Here is the actual snippet of the code.
I have "hard coded " the RegExp
RegExp = "[/\\w+/g]+";
text = " validate regular expression ";
text += RegExp;
qDebug() << text;
textDEBUG->append(text);
text = " validate inString ";
text += inString;
qDebug() << text;
textDEBUG->append(text);
QRegularExpression re(RegExp);
QRegularExpressionMatch match = re.match(inString);
if (match.hasMatch()) { text = " Has all match ";
QStringList result = match.capturedTexts();
text += result.at(0);
qDebug() << text;
textDEBUG->append(text);
return result.at(0);
Here is the relevant debug output
"START EditLine_RegExp...QString BT_Utility_Library::EditLine_RegExp_Ext(QString, QString, QTextEdit *, QTextEdit *)1321"
" instring text \t\n Waiting to connect to bluetoothd...\r\u001B[0;94m[bluetooth]\u001B[0m# \r\r\u001B[0;94m[bluetooth]\u001B[0m# \r \rAgent registered\n\u001B[0;94m[bluetooth]\u001B[0m# "
" regular expression \t\n (\\w+\\s:?)"
" validate regular expression [/\\w+/g]+"
" validate inString Waiting to connect to bluetoothd...\r\u001B[0;94m[bluetooth]\u001B[0m# \r\r\u001B[0;94m[bluetooth]\u001B[0m# \r \rAgent registered\n\u001B[0;94m[bluetooth]\u001B[0m# "
" Has all match Waiting"
10:12:17: /mnt/RAID_124/BT/BT_Oct23_BASE_/mdi/MDI exited with code 0
The expression matches ONLY the first word it finds.
My goal is to match ALL the words in the inString.
I am going to try one of the AI reg exp generators, but from experience
using them this RegExp MAY work....
|
|
|
|
|
|
Salvatore Terress wrote: learn more about using regular expression....RegExp = "[/\\w+/g]+";
Keep in mind that that form of a regular expression will be unlikely to work in any other regular expression interpreter.
Perl, javascript, C# and Java (perhaps others) all use the same rules for most of the basics for regex and that will not work with any of them.
For those that means the following
- Match A-Za-z0-9.
- Match a forward slash (redundant twice)
- Match a 'g'. Redundant with the word class match.
|
|
|
|
|
After some "RTFM" I came up with this code
if(inString.contains("Agent") & inString.contains("registered") )
{
text = "Match ";
}else
{
text = " No match ";
}
qDebug() << text;
textDEBUG->append(text);
The " contains " actually accepts reg expression and string too , so I am not sure how
to tell the difference.
But it does what I want it to do.
|
|
|
|
|
SOLVED
Thanks to all contributors who help to find the issue.
modified 29-Oct-23 10:49am.
|
|
|
|
|
At a guess, I would bet that textEditPtr_DEBUG may not be a valid object. In brief:
QTextEdit *textEditPtr_DEBUG = MWCCF->centralWidget()->findChild<QTextEdit *>("textEdit_2");
if (textEditPtr_DEBUG) {
} else {
}
textEditPtr_DEBUG->append(text);
Keep Calm and Carry On
|
|
|
|
|
Well, it's pretty obvious this call:
QTextEdit *textEditPtr_DEBUG = MWCCF->centralWidget()->findChild<QTextEdit *>("textEdit_2");
didn't find and return the object you thought it did.
Whatever "textEdit_2" is either doesn't exist or it's not in the container you think it is and are telling the code it's in.
I know you're saying "OK here", but is it really? Put a breakpoint on the if statement right above that and run the code under the debugger. When it breaks, hover the mouse over textEditptr_DEBUG and see if it actually has a value that isn't a bunch of zeros and points to the actual object you think it does.
|
|
|
|
|
Message Closed
modified 26-Oct-23 12:36pm.
|
|
|
|
|
Hell if I know. I haven't C++'d in about 15 years and I don't do Qt.
The process of checking return values for exactly what you expect them to be is just universal.
|
|
|
|
|
The code, and the problem, is quite clear.
1 QTextEdit *textEditPtr_DEBUG = MWCCF->centralWidget()->findChild<QTextEdit *>("textEdit_2");
2 if (textEditPtr_DEBUG)
3 {
4 text = " Found textEdit "; OK here
5 qDebug() << text;
6 textEditPtr_DEBUG->append(text);
7
8 text = " DEBUG START DEBUG trace with textEdit_2" ;
9 qDebug() << text;
10 textEditPtr_DEBUG->append(text);
11 }
12 else
13 {
14 text = "Did not find any QTextEdit";
15 qDebug() << text;
16 }
17 text = " DEBUG START DEBUG trace with textEdit_2" ;
19 textEditPtr_DEBUG->append(text); crash - null pointer here ??
At line 1 you (try to) create a pointer to some object.
At line 2 you test if that object is NULL, and if it is not, then you execute lines 4 to 10
If the object is NULL, then you skip to line 14
But then at line 19 you try to use a pointer which you may already have determined is NULL.
Unfortunately the debug output you have shown above does not match that code, so I am making some assumptions here.
[edit]
Also it does not help you to have the same debug message in two different places.
[/edit]
modified 25-Oct-23 5:13am.
|
|
|
|
|