• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nasa / trick / 25456501308

06 May 2026 07:29PM UTC coverage: 55.935% (-0.8%) from 56.7%
25456501308

Pull #2011

github

web-flow
Merge 7ad262960 into 7054e405e
Pull Request #2011: Single-file CI and code style adoption

14612 of 26123 relevant lines covered (55.94%)

462107.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/trick_source/sim_services/Sie/AttributesMap.cpp
1
#include <iostream>
2
#include <fstream>
3
#include <algorithm>
4
#include "trick/AttributesMap.hh"
5
#include "trick/attributes.h"
6
#include "trick/command_line_protos.h"
7

8
// Instantiate static variables for template types for ATTRIBUTES * and ENUM_ATTR *
9
namespace Trick {
10
AttributesMap * AttributesMap::pInstance = NULL ;
11
}
12

13
std::string & Trick::AttributesMap::replace_special_chars( std::string & str) {
×
14

15
    // escape &
16
    size_t index = 0;
×
17
    while (index != std::string::npos) {
×
18
        index = str.find("&" , index) ;
×
19
        if ( index != std::string::npos ) {
×
20
            str.replace(index, 1, "&amp;") ;
×
21
            index += 5;
×
22
        }
23
    }
24

25
    // escape "
26
    index = 0;
×
27
    while (index != std::string::npos) {
×
28
        index = str.find("\"" , index) ;
×
29
        if ( index != std::string::npos ) {
×
30
            str.replace(index, 1, "&quot;") ;
×
31
        }
32
    }
33

34
    // escape <
35
    index = 0;
×
36
    while (index != std::string::npos) {
×
37
        index = str.find("<" , index) ;
×
38
        if ( index != std::string::npos ) {
×
39
            str.replace(index, 1, "&lt;") ;
×
40
        }
41
    }
42

43
    return str;
×
44
}
45

46
std::string & Trick::AttributesMap::type_remove_dims( std::string & type ) {
×
47
    size_t index = type.find_first_of("*[");
×
48
    if (index != std::string::npos) {
×
49
        type.erase(index);
×
50
    }
51
    index = type.find_last_not_of(" ");
×
52
    if (index != std::string::npos) {
×
53
        type.erase(index + 1);
×
54
    }
55

56
    return replace_special_chars(type) ;
×
57
}
58

59
void Trick::AttributesMap::print_xml(std::ofstream & sie_out ) {
×
60
    std::map<std::string, ATTRIBUTES *>::iterator it ;
×
61
    int jj ;
62

63
    for ( it = name_to_attr_map.begin() ; it != name_to_attr_map.end() ; ++it ) {
×
64
        ATTRIBUTES * attr = (*it).second ;
×
65
        std::string class_name = (*it).first;
×
66
        std::replace(class_name.begin(), class_name.end(), ':', '_');
×
67
        sie_out << "  <class name=\"" <<  class_name << "\">\n" ;
×
68
        while ( attr->name[0] != '\0' and (attr->type_name != NULL)) {
×
69
            sie_out << "    <member" ;
×
70
            sie_out << "\n      name=\"" << attr->name << "\"" ;
×
71
            std::string type_name = attr->type_name;
×
72
            std::replace(type_name.begin(), type_name.end(), ':', '_');
×
73
            sie_out << "\n      type=\"" << type_remove_dims(type_name) << "\"" ;
×
74
            sie_out << "\n      io_attributes=\"" << attr->io << "\"" ;
×
75
            sie_out << "\n      units=\"" ;
×
76
            // If the mods bit is set for using -- as the units
77
            if ( attr->mods & TRICK_MODS_UNITSDASHDASH ) {
×
78
                sie_out << "--" ;
×
79
            } else {
80
                sie_out << attr->units ;
×
81
            }
82
            sie_out << "\"" ;
×
83

84
            std::string description = attr->des;
×
85
            if ( ! description.empty() ) {
×
86
                sie_out << "\n      description=\"" << replace_special_chars(description) << "\"" ;
×
87
            }
88
            sie_out << ">\n" ;
×
89
            if ( attr->num_index > 0 ) {
×
90
                for (jj = 0; jj < attr->num_index; jj++) {
×
91
                    sie_out << "      <dimension>" << attr->index[jj].size << "</dimension>\n" ;
×
92
                }
93
            }
94
            sie_out << "    </member>\n" ;
×
95
            attr++ ;
×
96
        }
×
97
        sie_out << "  </class>\n\n" ;
×
98
    }
×
99
}
×
100

101
void Trick::AttributesMap::print_json(std::ofstream & sie_out ) {
×
102
    std::map<std::string, ATTRIBUTES *>::iterator it ;
×
103
    int jj ;
104
    sie_out << "  \"classes\": [\n" ;
×
105
    for ( it = name_to_attr_map.begin() ; it != name_to_attr_map.end() ; ++it ) {
×
106
        ATTRIBUTES * attr = (*it).second ;
×
107
        std::string class_name = (*it).first;
×
108
        std::replace(class_name.begin(), class_name.end(), ':', '_');
×
109
        sie_out << "    {\n";
×
110
        sie_out << "      \"name\": \"" <<  class_name << "\",\n" ;
×
111
        if(attr->name[0] == '\0' || (attr->type_name == NULL)) {
×
112
            sie_out << "      \"members\": []\n" ;
×
113
        } else {
114
            sie_out << "      \"members\": [\n" ;
×
115
            while ( attr->name[0] != '\0' and (attr->type_name != NULL)) {
×
116
                sie_out << "        {\n";
×
117
                sie_out << "          \"name\": \"" << attr->name << "\",\n" ;
×
118
                std::string type_name = attr->type_name;
×
119
                std::replace(type_name.begin(), type_name.end(), ':', '_');
×
120
                sie_out << "          \"type\": \"" << type_remove_dims(type_name) << "\",\n" ;
×
121
                sie_out << "          \"io_attributes\": \"" << attr->io << "\",\n" ;
×
122
                sie_out << "          \"units\": \"" ;
×
123
                // If the mods bit is set for using -- as the units
124
                if ( attr->mods & TRICK_MODS_UNITSDASHDASH ) {
×
125
                    sie_out << "--" ;
×
126
                } else {
127
                    sie_out << attr->units ;
×
128
                }
129
                sie_out << "\"" ;
×
130

131
                std::string description = attr->des;
×
132
                if ( ! description.empty() ) {
×
133
                    sie_out << ",\n          \"description\": \"" << replace_special_chars(description) << "\"" ;
×
134
                }
135
                if ( attr->num_index > 0 ) {
×
136
                    sie_out << ",\n          \"dimensions\": [" ;
×
137
                    for (jj = 0; jj < attr->num_index - 1; jj++) {
×
138
                        sie_out << " \"" << attr->index[jj].size << "\"," ;
×
139
                    }
140
                    sie_out << " \"" << attr->index[attr->num_index - 1].size << "\" " ;
×
141
                    sie_out << "]\n" ;
×
142
                } else {
143
                    sie_out << '\n' ;
×
144
                }
145
                sie_out << "        }" ;
×
146
                if((attr + 1)->name[0] != '\0') {
×
147
                    sie_out << ',';
×
148
                }
149
                sie_out << '\n';
×
150
                attr++ ;
×
151
            }
×
152
            sie_out << "      ]\n" ;
×
153
        }
154
        sie_out << "    }" ;
×
155
        if(std::next(it, 1) != name_to_attr_map.end()) {
×
156
            sie_out << ',' ;
×
157
        }
158
        sie_out << "\n" ;
×
159
    }
×
160
    sie_out << "  ],\n" ;
×
161
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc