How can I use generics type with Infragistics XamDataTree - infragistics

I would like to use generic data structure say "INode" as the underlying data source for XamDataTree, how can I specify the generic type wiht TargetTypeName attribute of NodeLayout? As long as I can specify non-generic type, the XamDataTree works ok, but not with generic type?
I have tried setting TargetTypeName as below, but didn't help.

As suggested by Infragistics Support, XamDataTree does not support generics

Related

How to programmatically replace a type with another type

I would like to test the performance of a custom string and map implementation in my code. I would like to replace all objects of types std::string and std::map with custom::string and custom::map. Is there a reasonably scriptable way of doing this?
I am more interested in a methodology that would work for any given source and target types. Ideally a method that would also support different API names, i.e. replace std::map::insert() with custom::map::custom_insert().
I don't/can't trust a search/replace/regex or any solution that solely depends on textual representation of the types. Providing a tutorial or working example would also be amazing.

How to store get a correct Glib::RefPtr to a non-widget using Gtk::Builder

It is rather simple to get a Glib::RefPtr to any widget by using get_widget function of Gtk::Builder, but when it comes to getting other objects the corresponding get_object function returns Glib::Object, which is not easily convertable to the needed class (such as Gtk::TreeView).
What is the appropriate way of doing that?
It would be best to use Glib::RefPtr<TheDerivedype>::cast_dynamic(object) .
However, Gtk::TreeView (which you mention in your question) is a Gtk::Widget, so you would use get_widget() instead of get_object().
If you meant, Gtk::TreeModel, well, defining GtkTreeModels in Glade, for use in gtkmm C++ code, is something that might work since we added some fixes for that in gtkmm recently:
https://bugzilla.gnome.org/show_bug.cgi?id=742637
But it's not something that we generally expect to work - many C++ developers would prefer the static type safety of defining the DataModel structure completely in code, and not relying on a translation between C and C++ types. For instance: https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview-model.html.en#treeview-model-liststore
Glib::RefPtr has a static template function which allows one to do what is needed. This function is logically called cast_static.
The sample code can be:
treeStore =
Glib::RefPtr< Gtk::TreeStore >::cast_static( builder->get_object("treestore1") );

OCaml serialization with types

Is there any OCaml library that would serialize my data along with type information? For example: serialize [1;2;3] may give me <int list: (1,2,3)> or similar?
I want to store the type information with the data. Is it possible?
I tried looking at Sexplib, but I cannot figure out if they support this.
Thanks!
If all that you need is to store typenames, then you can use typerep library, to retrieve them, and then adapt sexp converters to handle this information.
Another option is to store data actually as a valid OCaml string, and to load it using compiler libs, i.e. actually parse and evaluate. In that case you can store types or whatever you want. You may find odn library useful for dumping data as OCaml.
I think sexplib or bin_prot are the current best bet. Sexplib does not attach type names to the data and I guess bin_prot does not either, but type safety is assured at the reader side.
If you really want "type information" attached to the serialized data, you can write your own serializer using ppx_deriving. It is rather new but much easier than writing CamlP4 based serializer like sexplib, bin_prot and meta_conv.

exposing boost::tuple part of class to boost python

I've been trying to figure out how to expose a property in my class that is a boost::tuple. The tuple is defined as follows:
typedef boost::shared_ptr<Action> action_ptr;
typedef boost::tuple<BattleCharacter*, action_ptr > ActionTargetTuple;
It's contained with a class defined as follows:
class Action : public Cloneable<Action>
{
public:
//Irrelevant Code Omitted
std::vector<ActionTargetTuple> Targets;
}
I've seen numerous articles while I was searching about how to convert a boost::tuple into a python tuple, but that's not what I'm looking to do. I want to be able to access the tuple as it exists on the Action class. (I know how to do the vector part).
class_<Action, std::auto_ptr<ActionWrapper> >("Action")
.def("Targets", &Action::Targets)
;
I expose it simply as above. I figured I might be able to expose it by some variation on the below:
class_<ActionTargetTuple>("ActionTargetTuple")
.def("get", &ActionTargetTuple::get<int>, return_value_policy<reference_existing_object>())
;
then use get from python, but if it is doable in this way, I'm not sure what the set up needs to be. Does anyone know how to do this/could suggest an alternative?
Thanks
You can use:
...
.add_property("Targets", & ActionTargetTuple::get, &ActionTargetTuple::set)
to make a read-write property using getter/setter methods in c++
If you want to control ownership:
namespace bp = boost::python;
...
.add_property("Targets",
bp::make_function(&ActionTargetTuple::get, bp::return_value_policy<...>()),
bp::make_function(&ActionTargetTuple::set, bp::return_value_policy<...>())
)
Besides using add_property as explained in the previous answer, and writing accessor functions, you can consider writing converters for your tuple (between boost::tuple and boost::python::tuple) and exposing those attributes directly with def_readonly or def_readwrite. It is worth it if you have many such attributes to expose.
This has a template you adapt can for c++→python conversion (use boost::tuple instead of std::pair), though unless you go c++0x, you have to write out templates for different number of arguments.
If your property is read-write, additionaly define from-python converter, you find examples on the web. Here is my code I use to define generic sequence-std::vector converter. In your case, you have to check that the python object is a sequence, that it has the right number of items, that you can extract required types from each of them; and then return new boost::tuple object.
HTH, edx.
P.S. I found ackward has the converters ready, perhaps you could just reuse it. Doc here

What is the typical usage of boost any library?

What are the advantages of using boost.any library ? Could you please give me some real life examples ? Why the same functionality couldn't be achieved by having some generic type in the root of object's hierarchy and creating containers with that base type ?
boost::any will happily store ints and floats, types that clearly have no base classes. A real-life example where you can use it is a virtual machine for a high-level interpreted language. Your "function" objects will need an array of arguments. This can easily be implemented with a std::list<boost::any> behind the scenes.
I consider that Boost.Variant should always be preferred as it's non-intrusive and still calls for very structured programming.
But i guess the main idea behind boost.any is to provide the equivalent of java and c# object types. It's a way of saying "yes we can" ! :-)
We've used it in a property map, (std::map<std::string, boost::any>), to store a lot of things dynamically in a simple, flat dataspace.
Mostly we either stored smart-ptr-to-scriptable-objects or strings, but some entries where other types (floats, vec3f, matrices, and other non-standard objects).
It works pretty well for adding more dynamic capabilities to c++, or wherever you want some type-erasure to just add any type of data to an object.
Why the same functionality couldn't be achieved by having some generic type in the root of object's hierarchy and creating containers with that base type ?
That calls an object hierarchy -- a construct you are injecting in artificially in to the design for solving a peripheral problem. Further, such a construct is easy to get wrong and a wrong implementation can wreak havoc. Boost.Any is a community reviewed safe, well-tested alternative.
Could you please give me some real life examples ?
TinyJSON uses boost.Any.
What are the advantages of using boost.any library ?
I refer the introductory documentation.
We use boost.any as the carrier type for a type-safe tagged variadic container. Here's what that means:
We have a "raft" object, which travels through a set of filters. When a filter wants to add data to the raft, it can do something like this:
raft.addTaggedData<ETag1>(3.0);
raft.addTaggedData<ETag2>("a string")`;
std::string str = raft.getTaggedData<ETag2>();
int a = raft.getTaggedData<ETag1>(); // <-- Compile error
Where ETag1 and ETag2 are members of an enum, and we use a traits template to map tags to types.
The raft class is using a list of pair<ETagType, boost::any> as a backing store. Boost.any saved us the pain of managing raw buffers for various types.