I have a file like this:
[data.json]
{
"electron": {
"pos": [0,0,0],
"vel": [0,0,0]
},
"proton": {
"pos": [1,0,0],
"vel": [0,0.1,0]
},
"proton": {
"pos": [-1,0,0],
"vel": [0,-0.1,-0.1]
}
}
How do I create a vector of particles from parsing this file. As I understand it I need to read the file using boost and read the strings (lines) into a vector, and then parse the contents of the vector.
The class particle is something like this:
class Particle
{
private:
particle_type mtype; // particle_type is an enum
vector<double> mPos;
vector<double> mVel;
};
Other methods for get/set have been omitted in the class.
Basically I would like help creating a vector<Particle>
with the correct position and velocity data and particle_type data parsed into it. Thanks in advance.
Code in main:
int main(){
boost::property_tree::ptree pt;
boost::property_tree::read_json("data.json", pt);
}