wrapper

Wrapping an API to support dependency injection

老子叫甜甜 提交于 2019-12-07 16:05:37
问题 I am interacting with an API that just has static functions, and cannot be opened up and changed. public class WindowsNativeGraphAPI { public static IEnumerable<IGraphData> GetGraphData(); public static bool DeleteGraphData(IGraphData data); } I would like to be able to pass the API into a function or constructor and comply with dependency injection (just in case we were to swap out the API later). public void GatherGraphData(IGraphAPI api) {...} To allow this API to be passed in as a

Is having a wrapper for your IoC a good idea?

瘦欲@ 提交于 2019-12-07 13:36:44
问题 I have been using StructureMap for more than a year now. And all this time I used to have a wrapper class called IoC which looked like this class IoC { public static T GetInstance<T>() { return (T)GetInstance(typeof(T)); } public static IEnumerable<T> GetAllInstances<T>() { return ObjectFactory.GetAllInstances<T>(); } public static IEnumerable GetAllInstances(Type type) { return ObjectFactory.GetAllInstances(type); } public static object GetInstance(Type type) { return ObjectFactory

C++/CLI Wrapping a Function that Returns a std::shared_ptr

坚强是说给别人听的谎言 提交于 2019-12-07 11:55:19
问题 I'm currently wrapping a C++ class with C++/CLI for .NET interoperability following the standard process of holding a native pointer in a managed class. In one instance, I have a native class that has a function like: std::shared_ptr<BaseChannel> channelData(const int RunNumber); I have already begun creating a wrapper class for BaseChannel . However, if I pass the raw pointer to the constructor of the managed class, there are no guarantees on the lifetime of the object being pointed to by

Why don't the wrapper classes for Primitives have a setter?

痞子三分冷 提交于 2019-12-07 10:54:30
问题 What is the reason why Wrapper classes (like Integer, Double, etc.) don't have a setter for their inner primitive value ? I am asking this because that kind of functionality would have simplified calculus, and have made the Java language a little more flexible . Let me give you some examples. 1) Let's take the following example: Integer x = new Integer(5); x++; The previous code behind the scenes is performing autoboxing . Something like: int x_tmp = x.intValue(); x_tmp++; x = new Integer(x

Pass a C++/CLI wrapper of a native type to another C++/CLI assembly

两盒软妹~` 提交于 2019-12-07 07:10:07
问题 Suppose I have the following simple wrapper of a NativeClassInstance. public ref class Wrapper { private: NativeClass *_wrapped; public: Renderer() { _wrapped = new NativeClass(); } ~Renderer() { delete _wrapped; } operator NativeClass*() { return _wrapped; } } Now, I want to create an instance of Wrapper from C# with Wrapper wrapper = new Wrapper() and use it in another native functionalities wrapper that resides in another assembly with Helper.Foo(wrapper) (nothing strange having other

Pass a c++ lambda to old c function pointer

喜你入骨 提交于 2019-12-07 06:59:55
问题 I have to create a c++ wrapper to a old c library. In a class method I must call a c function that takes with other stuff also a function pointer(it is a event handler and the function takes a function that is fired when a event happens). A simple example of it is this: void myclass::add_handler(std::function<void()> handler, otherstuff...) { /* * Many things. */ type_of_function_pointer_accepted_by_old_c_library_add_handler nameofvariable = [handler](same_arguments_as_in_definition_of_the

Avoid 'nothing known about [parent] class…' error in swig

十年热恋 提交于 2019-12-07 06:42:14
问题 Let's say I have two classes A in header file A.h // A.h class A { public: void foo(); }; and B in header file B.h // B.h class B : public A { public: void bar() }; I want to generate a Swig wrapper for class B. The interface file looks like this. B.i %{ #include "B.h" %} %include B.h When running swig, it quits with an error message 'nothing known about A', which is clear, since B inherits from A and thus swig must know about A to generate the interface. Lets further assume there is some

C# Ghostscript Wrapper

扶醉桌前 提交于 2019-12-07 05:45:21
问题 Has anyone encountered a nice wrapper for GhostScript in C#. My specific use is to take postscript and turn it into a pdf 回答1: Open-source PDFSharp has a namespace for using GhostScript. Even if you can't directly use it, you can probably graft whatever you need out of the source. 回答2: Matthew Ephraim has created a pretty simple C# wrapper called GhostScriptSharp that uses P/Invoke to access the unmanaged Ghostscript DLL in your C# application: http://mattephraim.com/blog/2009/01/06/a-simple

C# InputSimulator wrapper - how to use it?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 05:43:53
问题 I want to simulate keyboard click for a external program.I've tried SendMessage, PostMessage, SendKeys but they do not send the key to one specific program. So i wanted to try SendInput and i have downloaded a good wrapper for SendInput - http://inputsimulator.codeplex.com/ i have added the assembly to my project but i cannot yet start using any of the functions... What i have to do? What "Using" should i add? 回答1: I believe you need a Using WindowsInput; If that's not it, you can view it in

Using value wrapper and operator() overloading to simplify getter/setter design : a dangerous practice?

心已入冬 提交于 2019-12-07 03:23:46
问题 Consider the following class: class MyClass1 { public: double x() const {return _x;} // getter double y() const {return _y;} // getter double z() const {return _x*_y;} // getter void x(const double var) {_x = var;} // setter void y(const double var) {_y = var;} // setter void z(const double var) {_x = var; _y = 1;} // setter protected: double _x; double _y; }; As the actual contents of MyClass1 is an implementation detail, the getters and setters provide a unified way to get and set the class