Search Results

Search found 7418 results on 297 pages for 'argument passing'.

Page 128/297 | < Previous Page | 124 125 126 127 128 129 130 131 132 133 134 135  | Next Page >

  • WinForm-style Invoke() in unmanaged C++

    - by Matt Green
    I've been playing with a DataBus-type design for a hobby project, and I ran into an issue. Back-end components need to notify the UI that something has happened. My implementation of the bus delivers the messages synchronously with respect to the sender. In other words, when you call Send(), the method blocks until all the handlers have called. (This allows callers to use stack memory management for event objects.) However, consider the case where an event handler updates the GUI in response to an event. If the handler is called, and the message sender lives on another thread, then the handler cannot update the GUI due to Win32's GUI elements having thread affinity. More dynamic platforms such as .NET allow you to handle this by calling a special Invoke() method to move the method call (and the arguments) to the UI thread. I'm guessing they use the .NET parking window or the like for these sorts of things. A morbid curiosity was born: can we do this in C++, even if we limit the scope of the problem? Can we make it nicer than existing solutions? I know Qt does something similar with the moveToThread() function. By nicer, I'll mention that I'm specifically trying to avoid code of the following form: if(! this->IsUIThread()) { Invoke(MainWindowPresenter::OnTracksAdded, e); return; } being at the top of every UI method. This dance was common in WinForms when dealing with this issue. I think this sort of concern should be isolated from the domain-specific code and a wrapper object made to deal with it. My implementation consists of: DeferredFunction - functor that stores the target method in a FastDelegate, and deep copies the single event argument. This is the object that is sent across thread boundaries. UIEventHandler - responsible for dispatching a single event from the bus. When the Execute() method is called, it checks the thread ID. If it does not match the UI thread ID (set at construction time), a DeferredFunction is allocated on the heap with the instance, method, and event argument. A pointer to it is sent to the UI thread via PostThreadMessage(). Finally, a hook function for the thread's message pump is used to call the DeferredFunction and de-allocate it. Alternatively, I can use a message loop filter, since my UI framework (WTL) supports them. Ultimately, is this a good idea? The whole message hooking thing makes me leery. The intent is certainly noble, but are there are any pitfalls I should know about? Or is there an easier way to do this?

    Read the article

  • converting bash script to .bat

    - by Robokop
    #!/bin/bash function usage(){ cat <<EOF USAGE: $0 [strategylist] valid strategies are: ALLD ALLC TitForTat JOSS WeightedRandom Tester EOF exit 1 } [ -z $1 ] && usage javac robsAgents/*.java robsAgents/behaviours/*.java agentlist='leader:robsAgents.TournamentLeader' agentlist=$agentlist";$1:robsAgents.Contestant" while shift; do agentlist=$agentlist";$1:robsAgents.Contestant" done java jade.Boot -gui -host 127.0.0.1 "$agentlist" i have above bash script and have no access to a windows computer and i need to convert it to a .bat file, but don't even know how to do the shift and argument parsing

    Read the article

  • Common Lisp's equivalent of \r inside the format function?

    - by liszt
    Basically, I'd like to do the following, only using Common Lisp instead of Python: print("Hello world.\r\n") I can do this, but it only outputs the #\newline character and skips #\return: (format t "Hello world.~%") I believe I could accomplish this using an outside argument, like this: (format t "Hello world.~C~%" #\return) But is seems awkward to me. Surely I can somehow embed #\return into the very format string, like I can #\newline? Yeah ehh, I'm nitpicking. Thanks for any help!

    Read the article

  • Equivalent of IllegalArgumentException of Java in C++

    - by vito
    In Java if an input argument to a method is invalid, we can throw an IllegalArgumentException (which is of type RuntimeException). In C++, there is no notion of checked and unchecked exceptions. Is there a similar exception in standard C++ which can be used to indicate a runtime exception? Or is there a common style not in the standard but everyone follows in practice for a situation like this? Or, should I just create my own custom exception and throw it?

    Read the article

  • Can class of linux device be NULL?

    - by Basilevs
    Can I pass NULL pointer to the first argument of device_create function? I'm using device_create() to create character device file in sysfs. This file don't represent any physical device (it is used to provide an access to a set of devices connected to various buses). What class should I use with device_create() to create such a file?

    Read the article

  • Why do we have so many programming-languages?

    - by ntsbjctve
    Most people would probably answer with "You won't build a house using only a hammer", but my argument against this is: There is also only one real mathematical language used for everything from chemical to architectural calculations, and as programming-languages are in many ways similar to maths, why should it be so different with them?

    Read the article

  • C newbie malloc question

    - by roufamatic
    Why doesn't this print 5? void writeValue(int* value) { value = malloc(sizeof(int)); *value = 5; } int main(int argc, char * argv) { int* value = NULL; writeValue(value); printf("value = %d\n", *value); // error trying to access 0x00000000 } and how can I modify this so it would work while still using a pointer as an argument to writeValue?

    Read the article

  • Grails UnitTest

    - by Tomáš
    Hi (it is propably stupid question) how can acquire Domain class from database in test? class PollServiceTests extends GrailsUnitTestCase { Integer id = 1 void testSomething() { Teacher teacher1 = Teacher.get(id) assert teacher1 != null } } I always get null or No signature of method: cz.jak.Teacher.get() is applicable for argument types: (java.lang.Integer) values: [1] thanks a lot Tom

    Read the article

  • How to return something in Matlab?

    - by Ben Fossen
    I have a simple function function increase(percent, number) low = number- number*percent; end I want to return low so I can use it as an argument for another function mitoGen(asp, arg, increase(.2,234), glu) Is there a way to do this?

    Read the article

  • How to const declare the this pointer sent as parameter

    - by Tomas
    Hi, I want to const declare the this pointer received as an argument. static void Class::func(const OtherClass *otherClass) { // use otherClass pointer to read, but not write to it. } It is being called like this: void OtherClass::func() { Class::func(this); } This does not compile nad if i dont const declare the OtherClass pointer, I can change it. Thanks.

    Read the article

  • Ninject: Syntax for dependency arguments?

    - by Rosarch
    I have a class with a public constructor: public MasterEngine(IInputReader inputReader) { this.inputReader = inputReader; graphicsDeviceManager = new GraphicsDeviceManager(this); Components.Add(new GamerServicesComponent(this)); } How can I inject dependencies like graphicsDeviceManager and new GamerServicesComponent while still supplying the argument this?

    Read the article

  • How can I show the contents of a file at a specific state of a git repo?

    - by richcollins
    I want to show the contents of a file given by a path at a specific state of a git repo. I unsuccessfully tried this: git show f825334150cd4bc8f46656b2daa8fa1e92f7796d:Katana/source/Git/GitLocalBranch.h fatal: ambiguous argument 'f825334150cd4bc8f46656b2daa8fa1e92f7796d:Katana/source/Git/GitLocalBranch.h': unknown revision or path not in the working tree. Use '--' to separate paths from revisions The commit in question didn't modify the file specified. How can I show the contents of a file at a given state (specified by a commit hash) regardless of the involvement of the file in the commit?

    Read the article

  • Python required variable style

    - by Adam Nelson
    What is the best style for a Python method that requires the keyword argument 'required_arg': def test_method(required_arg, *args, **kwargs: def test_method(*args, **kwargs): required_arg = kwargs.pop('required_arg') if kwargs: raise ValueError('Unexpected keyword arguments: %s' % kwargs) Or something else? I want to use this for all my methods in the future so I'm kind of looking for the best practices way to deal with required keyword arguments in Python methods.

    Read the article

  • Which of these queries is preferable?

    - by bread
    I've written the same query as a subquery and a self-join. Is there any obvious argument for one over the other here? SUBQUERY: SELECT prod_id, prod_name FROM products WHERE vend_id = (SELECT vend_id FROM products WHERE prod_id = ‘DTNTR’); SELF-JOIN: SELECT p1.prod_id, p1.prod_name FROM products p1, products p2 WHERE p1.vend_id = p2.vend_id AND p2.prod_id = ‘DTNTR’;

    Read the article

  • warning about data loss c++/c

    - by Dr Deo
    i am getting a benign warning about possible data loss warning C4244: 'argument' : conversion from 'const int' to 'float', possible loss of data question i remember as if float has a larger precision than int. So how can data be lost if i convert from a smaller data type (int) to a larger data type (float)

    Read the article

  • C++: get const or non-const reference type from trait

    - by maciekp
    I am writing a functor F which takes function of type void (*func)(T) and func's argument arg. Then functor F calls func with arg. I would like F not to copy arg, just to pass it as reference. But then I cannot simply write "void F(void (*func)(T), T&)" because T could be a reference. So I am trying to write a trait, which allows to get proper reference type of T: T -> T& T& -> T& const T -> const T& const T& -> const T& I come up with something like this: template<typename T> struct type_op { typedef T& valid_ref_type; }; template<typename T> struct type_op<T&> { typedef typename type_op<T>::valid_ref_type valid_ref_type; }; template<typename T> struct type_op<const T> { typedef const T& valid_ref_type; }; template<typename T> struct type_op<const T&> { typedef const T& valid_ref_type; }; Which doesn't work for example for void a(int x) { std::cout << x << std::endl; } F(&a, 7); Giving error: invalid initialization of non-const reference of type ‘int&’ from a temporary of type ‘int’ in passing argument 2 of ‘void f(void (*)(T), typename type_op::valid_ref_type) [with T = int]’ How to get this trait to work?

    Read the article

  • Does my function right on python?

    - by Ali Ismayilov
    Write a function which takes a string argument, and creates and returns an Employee object containing details of the employee specified by the string. The string should be assumed to have the format 12345 25000 Consultant Bart Simpson The first three items in the line will be the payroll number, salary and job title and the rest of the line will be the name. There will be no spaces in the job title but there may be one or more spaces in the name. My function: def __str__(self): return format(self.payroll, "d") + format(self.salary, "d") + ' ' \ + self.jobtitle + self.name

    Read the article

  • More trivia than really important: Why no new() constraint on Activator.CreateInstance<T>() ?

    - by flq
    I think there are people who may be able to answer this, this is a question out of curiosity: The generic CreateInstance method from System.Activator, introduced in .NET v2 has no type constraints on the generic argument but does require a default constructor on the activated type, otherwise a MissingMethodException is thrown. To me it seems obvious that this method should have a type constraint like Activator.CreateInstance<T>() where T : new() { ... } Just an omission or some anecdote lurking here?

    Read the article

< Previous Page | 124 125 126 127 128 129 130 131 132 133 134 135  | Next Page >