I'm having some trouble converting an object returned by a q query to a string. I was using c.java
Does anyone have any sample code to do this?
Thanks!
There is nothing provided in c.java. You would need to write your recursive object printer or similar. Studio for KDB+ has some functionality like this.
Good starting poing will be https://github.com/CharlesSkelton/studio/blob/master/src/studio/kdb/K.java
Related
I am fairly new to UE4 development so apologies if I am missing something obvious.
I am trying to convert a system from blueprints to C++. In an attempt to convert the SpawnActor node, I found that I am unable to provide input parameters like in the image below where ‘Index’ is a custom input.
In other places, to resolve this issue, I have used BeginDeferredActorSpawnFromClass, used an initialise function to provide parameters, then call FinishSpawningActor. This has worked where I am calling a C++ class.
In this case however, the actor I want to spawn is a blueprint class which is a child based on a C++ class. I am unable to implement BeginDeferredActorSpawnFromClass for this, and therefore am not sure how to pass my parameter to this.
For extra context, in the project there can be multiple characters spawned in the world. I want to pass the index of the character in order to set the material colour of each individual character using the nodes shown below.
I am able to achieve this by spawning the BP character using:
Character = GetWorld()->SpawnActor(...)
Character->Index = Index
And then using EventTick instead of EventBeginPlay but feel this is a bad solution. I would appreciate if someone could advise how to initialise the spawned actor with the required parameter.
Thanks in advance.
I was being stupid. SpawnActorDeferred is the function which serves the purpose required.
I'm using MongoDB C++ driver (version 3.4.0 for reference). I need to get the _id of a given document. First, I grab the document:
bsoncxx::stdx::optional<bsoncxx::document::value> sub = conn["mydb"]["csubs"].find_one(...);
so I can access to the _id this way:
sub->view()["_id"].get_oid();
So far, so good.
As far as I have read in driver API this object is of type types::b_oid. However, I would need to get it as std::string.
Surprisingly, I haven't found any method in the types::b_oid class documentation for string conversion. I mean, the typical to_string() method so I can call something like:
sub->view()["_id"].get_oid().to_string();
Probably I'm missing something (because the use case seems to be too obvious :), but after a while checking documentation I haven't find the solution. Any help is welcome!
I think you can call to_string() from the value field:
sub->view()["_id"].get_oid().value.to_string();
Here's an example from the mongocxx github repo
I am using openpyxl to read an excel file that will have changing values over time. The following function will take string inputs from the excel sheets to make frames for Tkinter.
def make_new_frame(strng, frame_location, frame_name, frame_list):
if not(frame_name in frame_list):
frame_list.append(frame_name)
exec("global %s" %(frame_name)) in globals()
exec("%s = Frame(%s)"%(frame_name, frame_location))
.... etc.
The code itself is quite long but I think this is enough of a snapshot to address my problem.
Now this results in the following error while parsing:
SyntaxError: function 'make_new_frame' uses import * and bare exec, which are illegal because it is a nested function
Everything in the code I included parsed and executed just fine several times, but after I added a few more lines in later versions in this function, it keeps spitting out the above error before executing the code. The error references the third line in the function, (which, I repeat, has been cleared in the past).
I added "in globals()" as recommended in another SO post, so that solution is not working.
There is a solution online here that uses setattr, which I have no idea how to use to create a widget without eventually using exec.
I would really appreciate if someone could tell me how to bypass the error while parsing or provide an alternative means for a dynamically changing set of frame names.
Quick Note:
I am aware that setting a variable as global in python is generally warned against, but I am quite certain that it will serve useful for my code
Edit 1: I have no idea why this was downvoted. If I have done something incorrectly, please let me know what it is so I can avoid doing so in the future.
I think this is an X/Y problem. You are asking for help with solution Y instead of asking for help on problem X.
If your goal is to create an unknown number of Frame objects based on external data, you can store references to the frame in a list or dictionary without having to resort to using exec and dynamically created variable names.
exec is a perfectly fine function, but is one of those things that you should never use until you fully understand why you should never use it.
Here's how to solve your actual problem without using exec:
frames = {}
def make_new_frame(strng, frame_location, frame_name, frames):
if not(frame_name in frames):
frames[frame_name] = Frame(frame_location)
return frames[frame_name]
With that, you now have a dictionary (frames) that includes a reference for every new frame by name. If you had a frame named "foo", for example, you could configure and pack it like this:
frames["foo"].configure(background="red", ...)
frames["foo"].pack(...)
If preserving the order of the frames is important you can use an OrderedDict.
I'm sorry, I'm showing too many lines of code but I just have a small problem.
Take a look at the code file, you'll see two areas which I marked via comment [1] and [2] (Maybe you'll need [3]).
When I run the program, because this is a console program so the screen will have something like:
Befor callback: 0
After callback: 0
It should be After callback: 99 that is what I need.
My question is Why doesn't iResult variable change after I modify it?
Update 1
The 1st agrument of callback function points to where (this) pointer (in [3])points to.
Thank you guys.
When you call run_query to execute your query, it assigned the result of the sqlite3_exec call to iResult. This overwrites the 99 with the result of the query, which is 0.
It's just about everything not optimal about this code. If you're doing something simple, sonsider using an available wrapper, such as hiberlite. There are more low level ones as well.
Try to read about clean code first and about SOLID principles and then about patterns in enterprise software
This is also not what "modern" C++ is good for. Do you really want to do it in C++?
Then, you're doing something dangerous as well - you're assembling a query from a string by not using value binding.
I'm a bit desperate here... I'm trying to access one parameter of a light in Softimage.
First, when we do this:
light.GetParameterValue(L"LightExponent")
it works!
But when we try:
light.GetParameterValue(L"soft_light.atten")
it fails completely!
I tried to find documentation, but the only code that I could find is in Python and no indication for the equivalent in C++. In python, they manage to do something like:
xsi = Application
test = xsi.GetValue("LightName.point.soft_light.atten")
But I cannot figure out what is Application, and it's not the same as XSI::Application in the API.
So, any idea how to access this value ? Also, if I could found the equivalent to Application.GetValue (in the script, you can see Application.SetValue... so I imagine that GetValue exists in some form!) in C++, that would be nice... I could simply use the name of the light and then add the information that I need to access that value like:
SomeUnknownClassForNow::GetValue(light.GetName() + ".point.soft_light.atten");
Any idea ?
With the help of a client of ours, I finally managed to find a proper solution to this.
First, there's some direct parameters, like "LightExponent". But there's other parameters associated with an object, like a light, in other categories called Shaders.
With a light, or a least a point light, there's only one Shader, called "soft_light". It's possible to access it by:
light.GetShaders()[0]
It's possible to verify its name to with GetName(). Which, in this case, would be "LightName.point.soft_light".
Finally, to access the "soft_light.atten" parameter:
light.GetShaders()[0].GetParameterValue("atten")
So, in Softimage, there's sort of Hierarchy in objects and all these a separated as shaders. For more complex object, just find the right shader and extract its parameter.