"dynamische" klassen/structs
-
Hallo,
wie dir Titel schon sagt, suche ich nach einer möglichkeit, klassen oder strukturen mit dynamischen membern zu erstellen. dass das so einfach nicht geht, ist mir schon klar, jedoch bin ich auf dieses beispiel gestoßen, das ungefähr das macht, was ich will. http://www.michael-hammer.at/blog/c++_dynamic_parametrization/
jedoch stört mich an der sache, dass man für die get-methode immer als template-parameter angeben muss, welcher rückgabewert-typ es ist.
gibt es für so was noch andere möglichkeiten, um dies zu machen?danke schon mal
vario-500
Edit:
class foo { private: std::vector<boost::any> variables; public: auto operator[] (int index) -> decltype (variables[index]) { return variables[index]; } template <typename T> void append(T t) { variables.push_back(t); } };so hab ich gerade so als lösung gefunden, aber vielleicht gibt es ja noch bessere

-
Edit²: Seit wann geht das mit auto als Rückgabewert von Funktionen?
-
Ich stell mal eine einfache Frage...
Welche Gemeinsamkeiten haben die Objekte?
-
Hacker schrieb:
Edit²: Seit wann geht das mit auto als Rückgabewert von Funktionen?
... seit C++11

-
Swordfish schrieb:
... seit C++11

Ja, das war mir schon klar. 'S war rethorisch gemeint.

-
pfff. Dann spar's Dir...
-
XSpille schrieb:
Ich stell mal eine einfache Frage...
Welche Gemeinsamkeiten haben die Objekte?ich parse "c-strukturen" (sind da halt wie welche drin gespeichert) aus einer datei. hier http://www.atmind.nl/blender/blender-sdna.html sind die (alle) vermerkt falls es interessiert

-
Du willst boost::variant, nicht boost::any.
-
314159265358979 schrieb:
Du willst boost::variant, nicht boost::any.
sieht in der tat nicht schlecht aus, aber kannst du mir sagen, wie folgendes machen kann:
ich lese typen aus der datei ein, z.B. int, short, irgendeine_struct
so, wie bekomme ich es jetzt daraus ein variant mit diesen typen?
-
boost::variant<int, short, irgendeine_struct> var = /* z.B. */ 5;
-
Hacker schrieb:
boost::variant<int, short, irgendeine_struct> var = /* z.B. */ 5;lustig, wenn ich "int", "short", etc als string vorzuliegen hab, geparst aus der datei
-
Na und?
-
achso jetzt versteh ich erst, worauf hier hinaus wollt, glaub ich zumindest.
http://www.atmind.nl/blender/blender-sdna.html
da ist ein teil der strukturen, die in der datei stehen könnten und ich hab eigentlich nicht vor, für jede ein variant anzulegen. das ist mein problem, deshalb ja auch boost any mit der map vom anfang
-
vario-500 schrieb:
Hacker schrieb:
boost::variant<int, short, irgendeine_struct> var = /* z.B. */ 5;lustig, wenn ich "int", "short", etc als string vorzuliegen hab, geparst aus der datei
Noch lustiger, wenn du in Dateien zwischen short und int unterscheidest und auch keine Stringstreams kennst
-
mir ist schon klar was ein stringstream ist, aber ich glaube du weißt immer noch nicht genau was ich meine. in der datei steht: struktur scene, id 10, int, short, double, etc.
es wird nur beschrieben, WIE die struktur aufgebaut ist, nicht was drin steht
-
vario-500 schrieb:
mir ist schon klar was ein stringstream ist, aber ich glaube du weißt immer noch nicht genau was ich meine. in der datei steht: struktur scene, id 10, int, short, double, etc.
es wird nur beschrieben, WIE die struktur aufgebaut ist, nicht was drin stehtAchsoooooo, na dann! Sry.

Edit: Das ist aber echt komisch! Wofür brauchst du das denn!? Und selbst dann: boost::variant. Einfach etwas mehr template-args, SO viele verschiedene Typen werden es nicht sein, oder? Und vorher fest stehen?
ich hab eigentlich nicht vor, für jede ein variant anzulegen. das ist mein problem,Komisches Problem..
-
http://www.atmind.nl/blender/mystery_ot_blend.html
hierfür. das ist ein format vom programm blender 3d. die strukturen sind da, damit die gespeicherte datei, ab -und aufwärts kompatibel ist
damit man "gut" auf die daten zugreifen, bzw. parsen kann wollt ich die strukturen einfach nachbauenEDIT: Es wären über 400 variants die ich schreiben müsste
-
vario-500 schrieb:
EDIT: Es wären über 400 variants die ich schreiben müsste
Du meinst wohl Klassen. Naja, du brauchst doch sowieso für jede Klasse einen Datentyp. Das einzig hässliche ist dann nur
typedef boost::variant<type1, type2, ..., type399, type400> blender_object;
-
314159265358979 schrieb:
vario-500 schrieb:
EDIT: Es wären über 400 variants die ich schreiben müsste
Du meinst wohl Klassen. Naja, du brauchst doch sowieso für jede Klasse einen Datentyp. Das einzig hässliche ist dann nur
typedef boost::variant<type1, type2, ..., type399, type400> blender_object;Kommt das in einen eigenen Header?

Edit:
typedef boost::variant<type1, type2, type3, type4, type5, type6, type7, type8, type9, type10, type11, t ype12, type13, type14, type15, type16, type17, type18, type19, type20, type21, t ype22, type23, type24, type25, type26, type27, type28, type29, type30, type31, t ype32, type33, type34, type35, type36, type37, type38, type39, type40, type41, t ype42, type43, type44, type45, type46, type47, type48, type49, type50, type51, t ype52, type53, type54, type55, type56, type57, type58, type59, type60, type61, t ype62, type63, type64, type65, type66, type67, type68, type69, type70, type71, t ype72, type73, type74, type75, type76, type77, type78, type79, type80, type81, t ype82, type83, type84, type85, type86, type87, type88, type89, type90, type91, t ype92, type93, type94, type95, type96, type97, type98, type99, type100, type101, type102, type103, type104, type105, type106, type107, type108, type109, type110 , type111, type112, type113, type114, type115, type116, type117, type118, type11 9, type120, type121, type122, type123, type124, type125, type126, type127, type1 28, type129, type130, type131, type132, type133, type134, type135, type136, type 137, type138, type139, type140, type141, type142, type143, type144, type145, typ e146, type147, type148, type149, type150, type151, type152, type153, type154, ty pe155, type156, type157, type158, type159, type160, type161, type162, type163, t ype164, type165, type166, type167, type168, type169, type170, type171, type172, type173, type174, type175, type176, type177, type178, type179, type180, type181, type182, type183, type184, type185, type186, type187, type188, type189, type190 , type191, type192, type193, type194, type195, type196, type197, type198, type19 9, type200, type201, type202, type203, type204, type205, type206, type207, type2 08, type209, type210, type211, type212, type213, type214, type215, type216, type 217, type218, type219, type220, type221, type222, type223, type224, type225, typ e226, type227, type228, type229, type230, type231, type232, type233, type234, ty pe235, type236, type237, type238, type239, type240, type241, type242, type243, t ype244, type245, type246, type247, type248, type249, type250, type251, type252, type253, type254, type255, type256, type257, type258, type259, type260, type261, type262, type263, type264, type265, type266, type267, type268, type269, type270 , type271, type272, type273, type274, type275, type276, type277, type278, type27 9, type280, type281, type282, type283, type284, type285, type286, type287, type2 88, type289, type290, type291, type292, type293, type294, type295, type296, type 297, type298, type299, type300, type301, type302, type303, type304, type305, typ e306, type307, type308, type309, type310, type311, type312, type313, type314, ty pe315, type316, type317, type318, type319, type320, type321, type322, type323, t ype324, type325, type326, type327, type328, type329, type330, type331, type332, type333, type334, type335, type336, type337, type338, type339, type340, type341, type342, type343, type344, type345, type346, type347, type348, type349, type350 , type351, type352, type353, type354, type355, type356, type357, type358, type35 9, type360, type361, type362, type363, type364, type365, type366, type367, type3 68, type369, type370, type371, type372, type373, type374, type375, type376, type 377, type378, type379, type380, type381, type382, type383, type384, type385, typ e386, type387, type388, type389, type390, type391, type392, type393, type394, ty pe395, type396, type397, type398, type399, type400> blender_type;
-
Du musst ja Langeweile haben. Meine Challenge von letztem mal hast du auch nicht gemacht.