wrapper

Java — Primitive Counterpart of Byte, Integer, Long, etc. in template

时光怂恿深爱的人放手 提交于 2019-12-04 20:38:24
BACKGROUND : I am trying to implement a tiny template, i.e. generic class, which would allow me to achieve a pass-by-reference functionality as follows. public static class Ref<T> { T value; public Ref(T InitValue) { this.set(InitValue); } public void set(T Value) { this.value = Value; } public T get() { return this.value; } } So, I could define a function that takes a 'Ref' where the value can actually be changed, e.g. public static void function(Ref<Byte> x) { x.set((byte)0x7E); } The initialization of the variable to be passed by reference looks not so elegant. Ref<Byte> to_be_changed = new

Difference between int and Integer

瘦欲@ 提交于 2019-12-04 20:30:45
What is the difference between int and Integer . Yes, one is primitive and another one is wrapper , what is the situation to use them correctly. Also what is the difference between : int i=0; ++i and i++ part 1 One example .. you can use Integer as the key of HashMap but you can't use int. Because an Object is needed. So where you need an int value as an object there you need to use Integer class. part 2 ++i is pre increment i++ is post increment for example i = 0; System.out.println(i++) //will print 0 then the i will be 1. and i = 0; System.out.println(++i) // here i wil be incremented first

How to cut/crop/trim a video in respect with time or percentage and save output in different file

痴心易碎 提交于 2019-12-04 17:39:48
问题 Is there any tutorial or a c# library which which help me to accomplish the following Chose a file to edit Ask user to select cut/crop/trim method :- by time or by percentage cut/crop/trim the video by time or percentage as chosen ( say I wish to reduce a 5 minute video to 4 minute video, or reduce the video by 80%) Save the video as requested in required path now steps 1) and 4) I have implemented but could not find a good c# library to accomplish 3) and 4) I looked up the ffmpeg library but

How to wrap C library callbacks in C++/CLI

北慕城南 提交于 2019-12-04 16:39:11
Given the following C library with a callback event that ask to set a buffer, how to write a proper C++/CLI wrapper in a type safe manner? // The callback signature typedef void (__cdecl *BUFFERALLOCATOR)(void *opaque, void **buffer); // A struct that contains the context of the library struct lib_context_base_s { // The stored callback function pointer BUFFERALLOCATOR buffer_allocator; // Opaque pointer that contain the local context. Needed in C because // C doesn't have closures (functions that knows the context where // they are defined) void* opaque; }; typedef struct lib_context_base_s

Why I can't use Comparator to sort primitives?

北城余情 提交于 2019-12-04 15:25:39
As Java 5 have autoboxing, why I can't use Comparator to sort primitives? An int wouldn't be wrapped into a Integer ? Arrays.sort(..) have dedicated overloadings for sorting primitive arrays. If you need any special sorting rules apart from the standard ones, I'm afraid you'd have to use autoboxing. In addition to that, you'd have to transform your array to Integer[] , because int[] is not autoboxed. And if you are not talking about arrays, but about collections - then you have no choice - collections can hold only objects. Because you cannot parameterise a Comparator<T> -- or any other

How to implement a stdin, stdout wrapper?

拥有回忆 提交于 2019-12-04 14:13:09
问题 I have an interactive program that runs stdin and stdout. I need to create wrapper that will send X to it's stdin, check that it prints Y and then redirects wrapper's stdin and stdout to program's stdin and stdout just like program would be executed directly. How to implement this ? X and Y can be hardcoded. Bash? Python? Edit: I can't run the program twice. It has to be one instance. Here is the pseudocode: def wrap(cmd, in, expected_out): p = exec(cmd) p.writeToStdin(in) out = p.readBytes

Windows API Wrapper for .Net?

老子叫甜甜 提交于 2019-12-04 13:58:42
Windows API So i know that the WinForms touches on the Windows API a little, but frankly its horrible. ESPECIALLY with the layered windows and flickering. So i was wondering if anyone has wrote partial, or full wrappers for the Windows API.Im particularly interested in the Layered Window aspect, but really any part of the API is a good place to start. Update : I found the Windows API Code Pack here: http://code.msdn.microsoft.com/WindowsAPICodePack but it seems that it doesnt wrap Layered Windows? Am i correct in assuming this? Native API (Windows) Ive heard a little bit about the Native API,

Using a php://memory wrapper causes errors

泪湿孤枕 提交于 2019-12-04 13:33:20
问题 I'm trying to extend the PHP mailer class from Worx by adding a method which allows me to add attachments using string data rather than path to the file. I came up with something like this: public function addAttachmentString($string, $name='', $encoding = 'base64', $type = 'application/octet-stream') { $path = 'php://memory/' . md5(microtime()); $file = fopen($path, 'w'); fwrite($file, $string); fclose($file); $this->AddAttachment($path, $name, $encoding, $type); } However, all I get is a

Wrapper routine for write() with unistd.h included results in error

北城以北 提交于 2019-12-04 12:51:05
I am writing a wrapper routine for write() to override the original system function and within it i need to execute another program through execve() ; for which I include the header file unistd.h . I get the error conflicting types for 'write' /usr/include/unistd.h:363:16: note: previous declaration of 'write'was here . I would be very gratefull if someone could help me out as I need to call another program from inside the wrapper and also send arguments to it from inside the wrapper routine. jschmier An alternative to using the GNU liner --wrap symbol option as suggested by Matthew Slattery

Can't add perfect forwarding to wrapper function

妖精的绣舞 提交于 2019-12-04 12:23:00
While answering this question I wrote this working code, wrapping function passed in template arguments: template<typename Fn, Fn fn, typename... Args> auto wrapper(Args... args)->decltype(fn(args...)){ return fn(args...); } #define WRAPPER(FUNC) wrapper<decltype(&FUNC), &FUNC> Example usage (I use this code for testing): int min(int a, int b){ return (a<b)?a:b; } #include<iostream> using std::cout; int main(){ cout<<WRAPPER(min)(10, 20)<<'\n'; } Two people told me to use perfect forwarding . When I asked how to do this, one of them redirected me here . I read question, carefully read best