Recently I want use all new features of c++(<=c++17) in MQL5 , Or using c++ stl containers , like std::map , std::vector.
I can do something like this:
creating a wrapper on them and compile them , hence using dll in mql5
But it's so bad idea , Can anyone suggest better way? thx for answer.
I know that features like template overloading and more features should be suppoerted by meta trader code base , but they are so slow in this way , I wanna use new features in indirect way now, if it's possible.
Related
I'm looking for a data structure which behaves similar to boost::property_tree but (optionally) leaves the get/set implementation for each value item to the developer.
You should be able to do something like this:
std::function<int(void)> f_foo = ...;
my_property_tree tree;
tree.register<int>("some.path.to.key", f_foo);
auto v1 = tree.get<int>("some.path.to.key"); // <-- calls f_foo
auto v2 = tree.get<int>("some.other.path"); // <-- some fallback or throws exception
I guess you could abuse property_tree for this but I haven't looked into the implementation yet and I would have a bad feeling about this unless I knew that this is an intended use case.
Writing a class that handles requests like val = tree.get("some.path.to.key") by calling a provided function doesn't look too hard in the first place but I can imagine a lot of special cases which would make this quite a bulky library.
Some extra features might be:
subtree-handling: not only handle terminal keys but forward certain subtrees to separate implementations. E.g.
tree.register("some.path.config", some_handler);
// calls some_handler.get<int>("network.hostname")
v = tree.get<int>("some.path.config.network.hostname");
search among values / keys
automatic type casting (like in boost::property_tree)
"path overloading", e.g. defaulting to a property_tree-implementation for paths without registered callback.
Is there a library that comes close to what I'm looking for? Has anyone made experiences with using boost::property_tree for this purpose? (E.g. by subclassing or putting special objects into the tree like described here)
After years of coding my own container classes I ended up just adopting QVariantMap. This way it pretty much behaves (and is as flexible as) python. Just one interface. Not for performance code though.
If you care to know, I really caved in for Qt as my de facto STL because:
Industry standard - used even in avionics and satellite software
It has been around for decades with little interface change (think about long term support)
It has excellent performance, awesome documentation and enormous user base.
Extensive feature set, way beyond the STL
Would an std::map do the job you are interested in?
Have you tried this approach?
I don't quite understand what you are trying to do. So please provide a domain example.
Cheers.
I have some home-cooked code that lets you register custom callbacks for each type in GitHub. It is quite basic and still missing most of the features you would like to have. I'm working on the second version, though. I'm finishing a helper structure that will do most of the job of making callbacks. Tell me if you're interested. Also, you could implement some of those features yourself, as the code to register callbacks is already done. It shouldn't be so difficult.
Using only provided data structures:
First, getters and setters are not native features to c++ you need to call the method one way or another. To make such behaviour occur you can overload assignment operator. I assume you also want to store POD data in your data structure as well.
So without knowing the type of the data you're "get"ting, the only option I can think of is to use boost::variant. But still, you have some overloading to do, and you need at least one assignment.
You can check out the documentation. It's pretty straight-forward and easy to understand.
http://www.boost.org/doc/libs/1_61_0/doc/html/variant/tutorial.html
Making your own data structures:
Alternatively, as Dani mentioned, you can come up with your own implementation and keep a register of overloaded methods and so on.
Best
I am thinking to create a Linq library in C++ to do things like theVector.select( ... ), theVector.where(...).
I am wondering if there is a way to extend a C++ class that have already been declared ( like std::vector ) I would like to be able to do :
theVector.select(...)
instead of
myClass( theVector ).select(...)
Is there anyway way to accomplish this like in C# ?
Thanks,
The C++ community seems to be moving towards non-member functions for this type of "utility thing not directly related to the class at hand". e.g. if you have a std::vector v; you could always v.begin(), but now you can also std::begin(v). This would imply something like select(theVector)....
But, you might want to support joins at some point, so I would consider
select(...).from(theVector).join(theMap, ...).where(...)
// or
select(...).from(theVector).order_by(...)
// etc.
I'm using the libjson for parsing a JSON file in C++. I was wondering if you could do something like a PHP style notation for a map:
Just some pseudo code:
mapObj["id"] = 4;
mapObj["tags"] = vector {"Foo", "Bar"};
structMapObj = {
{"name", "FooBar"},
{"size", 1234567},
{"date", "2014-12-24"}
};
mapObj["file"] = anotherMapObject;
// for the vector
mapObj["tags"][0];
mapObj["tags"][1];
mapObj["tags"].size();
mapObj["tags"].pushBack("Foo");
// for the map
mapObj["file"]["name"]
...
Is it possible to receive a result like this?
Maybe an enum for the current type in the BaseClass?
myObj["key"].getType; // returns a 1 for example an INT
I tried to make it with a BaseClass and a template class, but I wasn't able to iterate through the object. Or should I even overload the operators for my BaseClass? Or is it necessary to inherit the BaseClass for each case (a class for the map-type object, a class for the int-type, for string and so on)?
I'm a a little bit desperate right now. Just need someone who leads me into the right direction :-P
PS: I don't want to use boost :-/
Thank you very much,
Daniel
I appreciate that you don't want to use boost. However, this problem has been solved in boost.
You are essentially wanting a map of strings to variants.
Have a look at the source code for boost::variant and boost::any. Take particular note of how boost gets round the problem of recursive definitions, for example when you want to store a map inside an element of another map.
This will teach you more than you ever wanted to know on this subject :-)
There is an open source project for C++Builder programmer called JSonCBB library. This library provides a semantic like to your need: http://www.cbuilderblog.com/jsoncbuilderblog-class-library/
In a started project, I would to start using my own wrapper class pointer instead of raw pointers.
My idea was rewrite the existent code for translate declarations like "Object *a" to "MyPointerObject a", but this rewrite does not seems trivial.
What is the simplest way to perform this?
I've looked clang, elsa, gccxml and doxygen, but none of these tools seems to be either simple enough or powerful enough for my task.
I know that isn't exactly possible in C++, but maybe a toolchain that can generate code which has a function, which when called gives me a list of all those classes. For example, across multiple files I have stuff like:
class MyClass : public ParticularClass {
....
}
class MyClass2 : public ParticularClass {
....
}
Then, during runtime, I just want a pointer to single instances of the class. Let's say my generated code looks something like this:
void __populate_classes() {
superList.append(new MyClass());
superList.append(new MyClass2());
}
Also, superList would be of type List<ParticularClass*>. Plus, I'll be using Qt and ParticularClass will be QObject derived, so I can fetch the name of the class anyways. I need to basically introspect the class, so my internal code doesn't really bother much about the newly defined type.
So, is there a way to generate this code with some toolchain? If it is possible with qmake alone, that'd be like icing on the freaking cake :)
Thanks a lot for your time.
Doxygen does a nice job at doing this -- offline. Various IDEs do a nice job at this -- offline. The compiler does not do this. Such knowledge is not needed or used by the compiler.
Here at work I use a tool called Understand 4 C++. It is a tool that helps you analyze your code. It will do this quite easily.
But my favorite part is it comes with a C and Perl API which allows you to take advantage of the abstract syntax tree that 'understand' encapsulates and write your own static analysis tools. I have written tons of tools using this API.
Anyways, it's written by SciTools. http://scitools.com and I don't work for them. I just wholeheartedly like their product. In fact I wrote a C# API that wraps their C API and posted it on CodePlex a few years ago. Sure beats using C or Perl to write static analysis tools.
I don't think what you're trying to do is a good idea. Those who will maintain code after you will have hard times to understand it.
Maybe instead of it you'll try see how you can do it in plan C++. One possible solution which comes to mind i to implement factory design pattern. Than you can iterate over all data types in factory and add then to superList.
Any way, using ack (simple grep replacement) can do the job if you always declare the inheritence in one line:
ack ": *public ParticularClass" *.h