mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
create S_sie.json
This commit is contained in:
parent
e798fde189
commit
994c8c0684
@ -63,6 +63,7 @@ namespace Trick {
|
||||
#endif
|
||||
|
||||
void print_xml( std::ofstream & outfile ) ;
|
||||
void print_json(std::ofstream & sie_out ) ;
|
||||
|
||||
private:
|
||||
std::map<std::string, ATTRIBUTES *> name_to_attr_map ;
|
||||
|
@ -55,6 +55,7 @@ namespace Trick {
|
||||
}
|
||||
|
||||
void print_xml( std::ofstream & outfile ) ;
|
||||
void print_json(std::ofstream & sie_out ) ;
|
||||
|
||||
private:
|
||||
std::map<std::string, ENUM_ATTR *> name_to_attr_map ;
|
||||
|
@ -40,10 +40,12 @@ namespace Trick {
|
||||
void class_attr_map_print_xml() ;
|
||||
void enum_attr_map_print_xml() ;
|
||||
void top_level_objects_print_xml() ;
|
||||
void sie_print_json() ;
|
||||
|
||||
private:
|
||||
|
||||
void top_level_objects_print(std::ofstream & sie_out) ;
|
||||
void top_level_objects_json(std::ofstream & sie_out) ;
|
||||
|
||||
// These are singleton maps holding all attributes known to the sim
|
||||
Trick::AttributesMap * class_attr_map ; /* ** -- This is be ignored by ICG */
|
||||
|
@ -98,3 +98,64 @@ void Trick::AttributesMap::print_xml(std::ofstream & sie_out ) {
|
||||
}
|
||||
}
|
||||
|
||||
void Trick::AttributesMap::print_json(std::ofstream & sie_out ) {
|
||||
std::map<std::string, ATTRIBUTES *>::iterator it ;
|
||||
int jj ;
|
||||
sie_out << " \"classes\": [\n" ;
|
||||
for ( it = name_to_attr_map.begin() ; it != name_to_attr_map.end() ; it++ ) {
|
||||
ATTRIBUTES * attr = (*it).second ;
|
||||
std::string class_name = (*it).first;
|
||||
std::replace(class_name.begin(), class_name.end(), ':', '_');
|
||||
sie_out << " {\n";
|
||||
sie_out << " \"name\": \"" << class_name << "\",\n" ;
|
||||
if(attr->name[0] == '\0' || (attr->type_name == NULL)) {
|
||||
sie_out << " \"members\": []\n" ;
|
||||
} else {
|
||||
sie_out << " \"members\": [\n" ;
|
||||
while ( attr->name[0] != '\0' and (attr->type_name != NULL)) {
|
||||
sie_out << " {\n";
|
||||
sie_out << " \"name\": \"" << attr->name << "\",\n" ;
|
||||
std::string type_name = attr->type_name;
|
||||
std::replace(type_name.begin(), type_name.end(), ':', '_');
|
||||
sie_out << " \"type\": \"" << type_remove_dims(type_name) << "\",\n" ;
|
||||
sie_out << " \"io_attributes\": \"" << attr->io << "\",\n" ;
|
||||
sie_out << " \"units\": \"" ;
|
||||
// If the mods bit is set for using -- as the units
|
||||
if ( attr->mods & TRICK_MODS_UNITSDASHDASH ) {
|
||||
sie_out << "--" ;
|
||||
} else {
|
||||
sie_out << attr->units ;
|
||||
}
|
||||
sie_out << "\"" ;
|
||||
|
||||
std::string description = attr->des;
|
||||
if ( ! description.empty() ) {
|
||||
sie_out << ",\n \"description\": \"" << replace_special_chars(description) << "\"" ;
|
||||
}
|
||||
if ( attr->num_index > 0 ) {
|
||||
sie_out << ",\n \"dimensions\": [" ;
|
||||
for (jj = 0; jj < attr->num_index - 1; jj++) {
|
||||
sie_out << " \"" << attr->index[jj].size << "\"," ;
|
||||
}
|
||||
sie_out << " \"" << attr->index[attr->num_index - 1].size << "\" " ;
|
||||
sie_out << "]\n" ;
|
||||
} else {
|
||||
sie_out << '\n' ;
|
||||
}
|
||||
sie_out << " }" ;
|
||||
if((attr + 1)->name[0] != '\0') {
|
||||
sie_out << ',';
|
||||
}
|
||||
sie_out << '\n';
|
||||
attr++ ;
|
||||
}
|
||||
sie_out << " ]\n" ;
|
||||
}
|
||||
sie_out << " }" ;
|
||||
if(std::next(it, 1) != name_to_attr_map.end()) {
|
||||
sie_out << ',' ;
|
||||
}
|
||||
sie_out << "\n" ;
|
||||
}
|
||||
sie_out << " ],\n" ;
|
||||
}
|
||||
|
@ -31,3 +31,38 @@ void Trick::EnumAttributesMap::print_xml(std::ofstream & sie_out ) {
|
||||
}
|
||||
}
|
||||
|
||||
void Trick::EnumAttributesMap::print_json(std::ofstream & sie_out ) {
|
||||
std::map<std::string, ENUM_ATTR *>::iterator it ;
|
||||
ENUM_ATTR * enum_attr ;
|
||||
sie_out << " \"enumerations\": [\n" ;
|
||||
for ( it = name_to_attr_map.begin() ; it != name_to_attr_map.end() ; it++ ) {
|
||||
enum_attr = (*it).second ;
|
||||
|
||||
if ( enum_attr != NULL ) {
|
||||
sie_out << " {\n";
|
||||
std::string name = it->first;
|
||||
std::replace(name.begin(), name.end(), ':', '_');
|
||||
sie_out << " \"name\": \"" << name << "\",\n" ;
|
||||
sie_out << " \"pairs\": [\n";
|
||||
while ( enum_attr->label[0] != '\0' ) {
|
||||
sie_out << " {\n" ;
|
||||
sie_out << " \"label\": \"" << enum_attr->label << "\",\n" ;
|
||||
sie_out << " \"value\": \"" << enum_attr->value << "\"\n" ;
|
||||
sie_out << " }" ;
|
||||
if((enum_attr + 1)->label[0] != '\0') {
|
||||
sie_out << ',';
|
||||
}
|
||||
sie_out << "\n";
|
||||
enum_attr++ ;
|
||||
}
|
||||
sie_out << " ]\n" ;
|
||||
sie_out << " }" ;
|
||||
if(std::next(it, 1) != name_to_attr_map.end()) {
|
||||
sie_out << ',' ;
|
||||
}
|
||||
sie_out << '\n';
|
||||
}
|
||||
}
|
||||
sie_out << " ],\n";
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@ int Trick::Sie::process_sim_args() {
|
||||
/* If main is being invoked by the configuration processor (cp) to generate the sie resource file... */
|
||||
/* Generate the sie resource file */
|
||||
sie_print_xml();
|
||||
sie_print_json();
|
||||
|
||||
// Silently exit the sim without printing the termination message
|
||||
exit(0) ;
|
||||
@ -73,6 +74,42 @@ void Trick::Sie::top_level_objects_print(std::ofstream & sie_out) {
|
||||
}
|
||||
}
|
||||
|
||||
void Trick::Sie::top_level_objects_json(std::ofstream & sie_out) {
|
||||
Trick::VARIABLE_MAP_ITER vit ;
|
||||
int jj ;
|
||||
sie_out << " \"top_level_objects\": [\n";
|
||||
for ( vit = trick_MM->variable_map_begin() ; vit != trick_MM->variable_map_end() ; vit++ ) {
|
||||
ALLOC_INFO * alloc_info = (*vit).second ;
|
||||
|
||||
if ( alloc_info != NULL ) {
|
||||
sie_out << " {\n" ;
|
||||
sie_out << " \"name\": \"" << vit->first << "\",\n" ;
|
||||
sie_out << " \"type\": \"" ;
|
||||
std::string type = trickTypeCharString(alloc_info->type, alloc_info->user_type_name );
|
||||
std::replace(type.begin(), type.end(), ':', '_') ;
|
||||
sie_out << type << "\",\n" ;
|
||||
sie_out << " \"alloc_memory_init\": \"" << alloc_info->alloced_in_memory_init << "\"";
|
||||
if ( alloc_info->num_index > 0 ) {
|
||||
sie_out << ",\n \"dimensions\": [" ;
|
||||
for (jj = 0; jj < alloc_info->num_index - 1; jj++) {
|
||||
sie_out << " \"" << alloc_info->index[jj] << "\"," ;
|
||||
}
|
||||
sie_out << " \"" << alloc_info->index[alloc_info->num_index - 1] << "\" " ;
|
||||
sie_out << "]\n" ;
|
||||
} else {
|
||||
sie_out << '\n' ;
|
||||
}
|
||||
sie_out << " }" ;
|
||||
if(std::next(vit, 1) != trick_MM->variable_map_end()) {
|
||||
sie_out << ',' ;
|
||||
}
|
||||
sie_out << '\n';
|
||||
}
|
||||
}
|
||||
sie_out << " ]\n";
|
||||
}
|
||||
|
||||
|
||||
void Trick::Sie::sie_print_xml() {
|
||||
std::ofstream sie_out ;
|
||||
std::string file_name = std::string(command_line_args_get_default_dir()) + "/" + "S_sie.resource" ;
|
||||
@ -86,6 +123,19 @@ void Trick::Sie::sie_print_xml() {
|
||||
sie_out.close() ;
|
||||
}
|
||||
|
||||
void Trick::Sie::sie_print_json() {
|
||||
std::ofstream sie_out ;
|
||||
std::string file_name = std::string(command_line_args_get_default_dir()) + "/" + "S_sie.json" ;
|
||||
sie_out.open(file_name.c_str()) ;
|
||||
sie_out << "{\n" ;
|
||||
class_attr_map->print_json(sie_out) ;
|
||||
enum_attr_map->print_json(sie_out) ;
|
||||
top_level_objects_json(sie_out) ;
|
||||
sie_out << "}\n" ;
|
||||
sie_out.close() ;
|
||||
}
|
||||
|
||||
|
||||
void Trick::Sie::class_attr_map_print_xml() {
|
||||
std::ofstream sie_out ;
|
||||
std::string file_name = std::string(command_line_args_get_default_dir()) + "/" + "S_sie_class.xml" ;
|
||||
|
Loading…
Reference in New Issue
Block a user