wrapper

Wrapper Classes for Primitive Data Types

这一生的挚爱 提交于 2019-12-04 01:26:44
问题 In designing a solution, sometimes it may be convenient to provide wrapper classes for primitive data types. Consider a class that represents a numeric value, be it a double , a float , or an int . class Number { private: double val; public: Number(int n) : val(n) { } Number(float n) : val(n) { } Number(double n) : val(n) { } // Assume copy constructors and assignment operators exist Number& add(const Number& other) { val += other.val; return *this; } int to_int() const { return (int) val; }

What does boost::thread sleep() do?

半腔热情 提交于 2019-12-04 01:06:47
I am currently working on a small wrapper class for boost thread but I dont really get how the sleep function works, this is what I have got so far: BaseThread::BaseThread(){ thread = boost::thread(); bIsActive = true; } BaseThread::~BaseThread(){ join(); } void BaseThread::join(){ thread.join(); } void BaseThread::sleep(uint32 _msecs){ if(bIsActive) boost::this_thread::sleep(boost::posix_time::milliseconds(_msecs)); } This is how I implemented it so far but I dont really understand how the static this_thread::sleep method knows which thread to sleep if for example multiple instances of my

How to check if php://input is set?

我只是一个虾纸丫 提交于 2019-12-04 00:28:06
I need to check if php://input exists/isset. Does it work with php isset() ? What is the proper way to check it? Try to test it with file_get_contents() (for reading) + empty() or boolean conversion (for testing): <?php $input = file_get_contents('php://input'); if ($input) { // exists } else { // not exists } From php.net : Note: Prior to PHP 5.6 , a stream opened with php://input could only be read once; the stream did not support seek operations. However, depending on the SAPI implementation, it may be possible to open another php://input stream and restart reading. This is only possible if

Block all other input to an application and control it from a wrapper in Java

╄→гoц情女王★ 提交于 2019-12-03 23:07:15
I have a windows application which has a complex GUI that I would like to hide from users. In order to do this, I would like to create a wrapper with an extremely simple interface that overlays this application and automates a number of actions when a user clicks a single button on the wrapper. (I hope "wrapper" is the proper term.) Is it possible to use Java to block input to the underlying application so that users cannot inadvertently mess up the automation? How would I go about this? Also, how can I automate key presses and clicks to the application without hijacking the mouse? Is this

Can't get SFTP to work in PHP

妖精的绣舞 提交于 2019-12-03 23:00:24
I am writing a simple SFTP client in PHP because we have the need to programatically retrieve files via n remote servers. I am using the PECL SSH2 extension. I have run up against a road block, though. The documentation on php.net suggests that you can do this: $stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r'); However, I have an ls method that attempts to something similar public function ls($dir) { $rd = "ssh2.sftp://{$this->sftp}/$dir"; $handle = opendir($rd); if (!is_resource($handle)) { throw new SFTPException("Could not open directory."); } while (false !== ($file = readdir($handle)

Wrapping a C Library with Objective-C - Function Pointers

允我心安 提交于 2019-12-03 20:08:31
I'm writing a wrapper around a C library in Objective-C. The library allows me to register callback functions when certain events occur. The register_callback_handler() function takes a function pointer as one of the parameters. My question to you gurus of programming is this: How can I represent an Objective-C method call / selector as a function pointer? Would NSInvocation be something useful in this situation or too high level? Would I be better off just writing a C function that has the method call written inside it, and then pass the pointer to that function? Any help would be great,

Wrapping all possible method calls of a class in a try/except block

自闭症网瘾萝莉.ら 提交于 2019-12-03 20:07:52
I'm trying to wrap all methods of an existing Class (not of my creation) into a try/except suite. It could be any Class, but I'll use the pandas.DataFrame class here as a practical example. So if the invoked method succeeds, we simply move on. But if it should generate an exception, it is appended to a list for later inspection/discovery (although the below example just issues a print statement for simplicity). (Note that the kinds of data-related exceptions that can occur when a method on the instance is invoked, isn't yet known; and that's the reason for this exercise: discovery). This post

Buffering log messages in NLog and manually flushes them to target

 ̄綄美尐妖づ 提交于 2019-12-03 19:56:00
问题 I am trying to log via the NLog MailTarget. It works just fine, but i wanted to wrap the mailtarget with the BufferedTargetWrapper to buffer the log messages until a predefined codepoint, where i want to manually flush the buffer and send the previusly buffered log messages by an single mail (like defined in the mail target). If I define a FlushTimeout or the BufferSize of the BufferedTargetWrapper everything still works just fine as supposed. But if the FlushTimeout and the BufferSize is not

Python: Exception decorator. How to preserve stacktrace

会有一股神秘感。 提交于 2019-12-03 18:38:09
问题 I am writing a decorator to apply to a function. It should catch any exception, and then raise a custom exception based on the original exception message. (This is because suds throws a generic WebFault exception, from whose message I parse the exception thrown by the web service and raise a Python exception to mirror it.) However, when I raise the custom exception in the wrapper, I want the stacktrace to point to the function that raised the original WebFault exception. What I have so far

Auto wrap c++ dll into c#

不打扰是莪最后的温柔 提交于 2019-12-03 17:33:57
I want to use c++ library in a c# project. Is there any wrapper tool to import all classes automatically? SWIG can help create a wrapper consisting of two parts, one C++ sided, and one C# sided. It needs a bit of work to set up the correct generation files though. An alternative that requires more manual coding is C++/CLI. For pure c apis I prefer p/invoke over either of them. There is a program to automate conversion of c headers. If I recall correctly it's called something like "P/Invoke Interop Assistant" or "Interop Signature Toolkit". There is also mono/cxxi which looks pretty cool. The