Random Vector Manipulation - c++11

I would like to use MFC with a combination of std::remove/remove_if with std:erase to manipulate a vector of <std::shared_ptr<CString> > containing a list of file names from a recursively searched root. Imagine the following:
A dialog box containing:
two radio buttons (Keep and Delete)
a number of check boxes with image file
extensions as labels (JPG, TIF, GIF, etc.)
a button to do the action
If I select Keep, I want to keep all the files with the checked extensions and delete everything else or delete them directly if I select Delete. As an example, I thought I could use something similar to
void CPicsDlg::FilterFiles(void)
{
auto end = std::remove_if(g_vFiles.begin(), g_vFiles.end(), [&](std::shared_ptr<CString> const &strFile) { return strFile->Right(3) == "JPG" || strFile->Right(3) == "TIF" });
g_vFiles.erase(end, g_vFiles.end());
}
if I wanted to keep or delete files with just those 2 extensions. But I'll never know which checkboxes are selected, so I'm not sure how to build my condition and I think if I try to use remove_if for one at a time, then files I want to keep or delete in addition to the first one will already be removed from the vector! I don't think remove can be used because it wants a specific value and obviously all the files and paths will be unique. I probably could iterate through the vector and keep or delete each one that meets my condition at that index, but that seems like overkill. So how do I go about accomplishing this?
I hope this makes sense and if something similar has been covered elsewhere, please direct me there. TIA

If I understand the uestion correct it is just a simple XOR
Keep Match ToDelete
0 0 0
0 1 1
1 0 1
1 1 0
The code is
bool bKeep = IsDlgButtonChecked(IDC_KEEP)!=0;
bool bTypeJPG = IsDlgButtonChecked(IDC_JPG)!=0;
bool bTypeTIF = IsDlgButtonChecked(IDC_TIF)!=0;
...
auto end = std::remove_if(g_vFiles.begin(), g_vFiles.end(),
[&](std::shared_ptr<CString> const &strFile)
{
return bKeep ^
((bTypeJPG && strFile->Right(4)==".JPG") ||
(bTypeTIF && strFile->Right(4)==".TIF") ||
(bType... && strFile->Right(4)=="...."))
}
);

Related

Can an array of strings of size 1 be used like a string?

I'm translating a program from asp to asp.net. The creator has a few function that I'm scratching my head over. It seems to be passing back arrays but the results of the function are used as if they're strings in some situations and arrays in others.
Mostly it operates as if it returns a string but sometimes it'll do for each on the result which indicates that it's actually an array of strings. I've searched the web to see if there's some weird corner case logic but nothing specific to this comes up.
function textvalue(myPar)
{
eval("var anotherArray=" + myPar);
anotherArray.sort();
if (eval("datatype" + myPar)=="datetime")
{
//if (eval(myPar)==null || eval(myPar)=="null" || eval(myPar)=="")
if (anotherArray.toString()==null || anotherArray.toString()=="null" || anotherArray.toString()=="")
{
return anotherArray;
}
else
{
return new Array(convertFromAODdatetime(anotherArray.toString()));
}
}
else
{
return anotherArray;
}
}
USE 1
Response.Write(...existing status: " & theStructure.textvalue("structureItemStatus") & "....")
USE 2
For Each datum In fileData.textValue("fileNomenclature")
Response.Write(...
I'm ultimately wondering if I need to do something unique w/ these functions or maybe the resulting datatype to replicate the logic of the function properly.
I don't believe that an array works that way. You might be able to replace the array with a list and it work more in the way you are expecting.
Another option is to just run an if statement to see if the array length is greater than 1 then run a foreach loop otherwise just grab arry[0].

FILTER values from one sheet when not present on another

I'm trying to compare Items in "projectEstimate!D2:D & projectEstimate!E2:E" to Items in 'itemsAssociations!C3:C & itemsAssociations!D3:D" for matches.
If there is a match, confirm that the associated item (itemsAssociations!G3:G & itemsAssociations!H3:H) is not already listed in "projectEstimate".
If it is not listed, print that item. If it IS listed, do nothing.
I put together the following code which seems like it should work, but the item prints whether it's present on projectEstimate or not.
=ArrayFormula({itemsAssociations!I2:J2;FILTER(itemsAssociations!I3:J,
{projectEstimate!D2:D&IF(LEN(projectEstimate!E2:E),projectEstimate!E2:E,)=itemsAssociations!C3:C&IF(LEN(itemsAssociations!D3:D),itemsAssociations!D3:D,)},
{projectEstimate!D2:D&IF(LEN(projectEstimate!E2:E),projectEstimate!E2:E,)<>itemsAssociations!G3:G&IF(LEN(itemsAssociations!H3:H),itemsAssociations!H3:H,)}
)})
I also tried this QUERY, but not sure how to include the entire ranges
=QUERY(itemsAssociations!C3:J,"SELECT I,J WHERE C = '"&projectEstimate!D2:D&"' AND D = '"&projectEstimate!E2:E&"' AND J != '"&projectEstimate!D2:D&"'",0)
This is close, but the opposite result:
=FILTER(projectEstimate!D2:D,COUNTIF(FILTER(itemsAssociations!J3:J,COUNTIF(itemsAssociations!C3:C&itemsAssociations!D3:D,itemsAssociations!C3:C&itemsAssociations!D3:D)),projectEstimate!D2:D))
My sheet
it would be something amongst theses lines:
=ARRAYFORMULA(REGEXREPLACE(QUERY(FILTER(projectEstimate!D2:D&":"&projectEstimate!E2:E,
NOT(COUNTIF(itemsAssociations!C3:C&":"&itemsAssociations!D2:D,projectEstimate!D2:D&":"&projectEstimate!E2:E))),
"where Col1 is not null", 0), ":$", ))
This is what I came up with...
=IFERROR(FILTER(FILTER(itemsAssociations!J3:J,NOT(COUNTIF(projectEstimate!D3:D,itemsAssociations!C3:C))),NOT(COUNTIF(FILTER(projectEstimate!D2:E,NOT(COUNTIF(itemsAssociations!C3:C&itemsAssociations!D3:D,projectEstimate!D2:D&projectEstimate!E2:E))),FILTER(itemsAssociations!J3:J,NOT(COUNTIF(projectEstimate!D3:D,itemsAssociations!C3:C)))))),"No suggested items!")

Get all pixels location

I using PixelSearch function, I know how to find 1 pixel that match to my criteria, but the problem is that I would like to find all pixels of specific color and add this to array, so after I can use it to rand one and click on it.
Source code:
Local $aCoord = PixelSearch(0, 0, $clientSize[0], $clientSize[1], 0x09126C, 10, 1, $hWnd)
If Not #error Then
; add to array and search next
Else
GUICtrlSetData($someLabel, "Not Found")
EndIf
I want to find ALL PIXELS, not one "the first". How can I do this? Am I missing something?
This can't be done using PixelSearch because it stops executing when a matching pixel is found.
It can be done by looping PixelGetColor over your area. Something like:
For $x = 0 To $clientSize[0] Step 1
For $y = 0 To $clientSize[1] Step 1
If PixelGetColor($x,$y,$hWnd) = 0x09126C Then
;Add $x and $y to Array using _ArrayAdd() (or whatever you prefer)
EndIf
Next
Next
This might feel slower than PixelSearch because it now has to scan the entire area, instead of stopping at the first match, but it shouldn't be, since PixelSearch is based on the same principle.

How can i set mark for textView?

i am doing "find and repleace button" for my application. I am using gtk and ruby. And i can find that how many word, if there is. Also i want to get selection word that searched word, and i should mark them. My some code:
def search(ent, txtvu)
start = txtvu.buffer.start_iter
first, last = start.forward_search(ent.text, Gtk::TextIter::SEARCH_TEXT_ONLY, nil)
count = 0
while (first)
mark = start.buffer.create_mark(nil, first, false)
txtvu.scroll_mark_onscreen(mark)
txtvu.buffer.delete_mark(mark)
txtvu.buffer.select_range(first, last)
start.forward_char
first, last = start.forward_search(ent.text, Gtk::TextIter::SEARCH_TEXT_ONLY, nil)
start = first
count += 1
end
count says me how many words involve My code does't work. :( Why? I want to mark all searched words.
If I understand you correctly, you want to highlight all found words, not just one. In that case, select_range is not the function to call, because it will change the selection to the current word, and GtkTextView selection is single and contiguous.
Instead, create a highlight tag and apply it to all searches. For example:
# create the "highlight" tag (run this only once)
textvu.buffer.create_tag("highlight", {background => "yellow"})
# ... later, in the loop:
textvu.buffer.apply_tag("highlight", first, last)
Your matches will all appear highlighted.

QTP narrow a list of ChildObjects

[The description is a bit fudged to obfuscate my real work for confidentiality reasons]
I'm working on a QTP test for a web page where there are multiple HTML tables of items. Items that are available have a clickable item#, while those that aren't active have an item# as plain text.
So if I have a set of ChildObjects like this:
//This is the set of table rows that contain item numbers, active or not.
objItemRows = Browser("browserX").Page("pageY").ChildObjects("class:=ItemRow")
What is the simplest way in QTP land to select only the clickable link-ized item #s?
UPDATE: The point here isn't to select the rows themselves, it's to select only the rows that have items in them (as opposed to header/footer rows in each table). If I understand this correctly, I could then use objItemRows.Count to count how many items (available and unavailable) there are. Could I then use something like
desItemLink = Description.Create
desItemLink("micclass").value = "Link"
objItemLinks = objItemRows.ChildObjects(desItemLink)
To get the links within only the item rows?
Hope that clarifies things, and thanks for the help.
I think I have this figured out.
Set desItemLink = description.create
desItemLink("micclass").value = "Link"
desItemLink("text").RegularExpression = True
//True, Regex isn't really required in this example, but I just wanted to show it could be used this way
//This next part depends on the format of the item numbers, in my case, it's [0-9]0000[0-9]00[0-9]
For x = 0 to 9
For y = 0 to 9
For z = 0 to 9
strItemLink = x & "0000" & y & "00" & z
desItemLink("text").value = strItemLink
Set objItemLink = Browser("browser").Page("page").Link(desItemLink)
If objItemLink.Exist(0) Then
//Do stuff
End If
Next
Next
Next
Thanks for your help anyways, but the code above will iterate through links with names in a given incrementing format.

Resources