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

icsm-au / DynAdjust / 5021344802

pending completion
5021344802

push

github

GitHub
Merge pull request #222 from rogerfraser/master

159 of 159 new or added lines in 7 files covered. (100.0%)

30774 of 38869 relevant lines covered (79.17%)

3959.78 hits per line

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

69.33
/dynadjust/dynadjust/dnasegmentwrapper/dnasegmentwrapper.hpp
1
//============================================================================
2
// Name         : dnasegmentwrapper.hpp
3
// Author       : Roger Fraser
4
// Contributors :
5
// Version      : 1.00
6
// Copyright    : Copyright 2017 Geoscience Australia
7
//
8
//                Licensed under the Apache License, Version 2.0 (the "License");
9
//                you may not use this file except in compliance with the License.
10
//                You may obtain a copy of the License at
11
//               
12
//                http ://www.apache.org/licenses/LICENSE-2.0
13
//               
14
//                Unless required by applicable law or agreed to in writing, software
15
//                distributed under the License is distributed on an "AS IS" BASIS,
16
//                WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
//                See the License for the specific language governing permissions and
18
//                limitations under the License.
19
//
20
// Description  : DynAdjust Network Segmentation Executable
21
//============================================================================
22

23
#ifndef DNASEGMENTWRAPPER_H_
24
#define DNASEGMENTWRAPPER_H_
25

26
#if defined(_MSC_VER)
27
        #if defined(LIST_INCLUDES_ON_BUILD) 
28
                #pragma message("  " __FILE__) 
29
        #endif
30
#endif
31

32
#include <iostream>
33
#include <vector>
34
#include <algorithm>
35
#include <iomanip>
36
#include <sstream>
37
#include <string>
38
#include <time.h>
39
#include <string.h>
40
#include <set>
41

42
#include <boost/timer/timer.hpp>
43
#include <boost/date_time/posix_time/posix_time.hpp>
44
#include <boost/thread.hpp>
45
#include <boost/thread/mutex.hpp>
46
#include <boost/shared_ptr.hpp>
47
#include <boost/program_options/options_description.hpp>
48
#include <boost/program_options/parsers.hpp>
49
#include <boost/program_options/variables_map.hpp>
50
#include <boost/filesystem.hpp>
51

52
using namespace std;
53
using namespace boost;
54
using namespace boost::filesystem;
55
using namespace boost::posix_time;
56
using namespace boost::program_options;
57
namespace po = boost::program_options;
58

59
#include <include/config/dnaversion.hpp>
60
#include <include/config/dnaconsts.hpp>
61
#include <include/config/dnaoptions-interface.hpp>
62
#include <include/config/dnaconsts-interface.hpp>
63
#include <include/config/dnaprojectfile.hpp>
64

65
#include <include/functions/dnastringfuncs.hpp>
66
#include <include/functions/dnafilepathfuncs.hpp>
67
#include <include/functions/dnastrmanipfuncs.hpp>
68

69
#include <dynadjust/dnasegment/dnasegment.hpp>
70

71
using namespace dynadjust::networksegment;
72
using namespace dynadjust::exception;
73

74
extern bool running;
75
extern boost::mutex cout_mutex;
76

77
class dna_segment_thread
78
{
79
public:
80
        dna_segment_thread(dna_segment* dnaSeg, project_settings* p, _SEGMENT_STATUS_* segmentStatus, milliseconds* s, string* status_msg)
17✔
81
                : _dnaSeg(dnaSeg)
17✔
82
                , _p(p)
17✔
83
                , _segmentStatus(segmentStatus)
17✔
84
                , _s(s)
17✔
85
                , _status_msg(status_msg) {};
17✔
86
        void operator()()
17✔
87
        {
88
                running = true;
17✔
89
                
90
                if (!_p->g.quiet)
17✔
91
                {
92
                        cout_mutex.lock();
17✔
93
                        cout << "+ Loading binary files...";
17✔
94
                        cout_mutex.unlock();
17✔
95
                }
96
                
97
                try {
17✔
98
                        // prepare the segmentation
99
                        _dnaSeg->PrepareSegmentation(_p);
17✔
100
                } 
101
                catch (const NetSegmentException& e) {
1✔
102
                        cout_mutex.lock();
1✔
103
                        cout << endl << "- Error: " << e.what() << endl;
1✔
104
                        cout_mutex.unlock();
1✔
105
                        running = false;
1✔
106
                        return;
1✔
107
                }
1✔
108

109
                if (!_p->g.quiet)
16✔
110
                {
111
                        cout_mutex.lock();
16✔
112
                        cout << " done." << endl;
16✔
113

114
                        if (_dnaSeg->StartingStations().empty())
16✔
115
                        {
116
                                string startStn(_dnaSeg->DefaultStartingStation());
11✔
117
                                if (startStn == "")
11✔
118
                                        startStn = "the first station";
×
119
                                cout << "+ Adopting " << _dnaSeg->DefaultStartingStation() << " as the initial station in the first block." << endl;
22✔
120
                        }
11✔
121
                        cout << "+ Creating block " << setw(PROGRESS_PAD_39) << " ";
16✔
122
                        cout_mutex.unlock();
16✔
123
                }
124
                cpu_timer time;
16✔
125
                try {
16✔
126
                        *_segmentStatus = SEGMENT_EXCEPTION_RAISED;
16✔
127
                        *_segmentStatus = _dnaSeg->SegmentNetwork(_p);
16✔
128
                } 
129
                catch (const NetSegmentException& e) {
×
130
                        running = false;
×
131
                        cout_mutex.lock();
×
132
                        cout << endl << "- Error: " << e.what() << endl;
×
133
                        cout_mutex.unlock();
×
134
                        return;
×
135
                }
×
136
                catch (const runtime_error& e) {
×
137
                        running = false;
×
138
                        boost::this_thread::sleep(milliseconds(250));
×
139
                        cout_mutex.lock();
×
140
                        cout << endl << "- Error: " << e.what() << endl;
×
141
                        cout_mutex.unlock();
×
142
                        return;
×
143
                }
×
144

145
                *_s = milliseconds(time.elapsed().wall/MILLI_TO_NANO);
16✔
146
                running = false;
16✔
147
                
148
                if (!_p->g.quiet)
16✔
149
                {
150
                        cout_mutex.lock();
16✔
151
                        cout << PROGRESS_BACKSPACE_39 << "\b" << setw(PROGRESS_PAD_39+3) << left << "s... done.   " << endl;
16✔
152
                        cout_mutex.unlock();
16✔
153
                }                
154
        }
155
private:
156
        dna_segment*                _dnaSeg;
157
        project_settings*        _p;
158
        _SEGMENT_STATUS_*        _segmentStatus;
159
        milliseconds*                _s;
160
        string*                                _status_msg;
161
};
162

163
class dna_segment_progress_thread
164
{
165
public:
166
        dna_segment_progress_thread(dna_segment* dnaSeg, project_settings* p)
17✔
167
                : _dnaSeg(dnaSeg), _p(p) {};
17✔
168
        void operator()()
17✔
169
        {
170
                UINT32 block, currentBlock(0);
17✔
171
                ostringstream ss;
17✔
172
                
173
                while (running)
34✔
174
                {
175
                        block = _dnaSeg->currentBlock();
17✔
176
                        if (!_p->g.quiet)
17✔
177
                        {
178
                                if (block != currentBlock)
17✔
179
                                {
180
                                        ss.str("");
×
181
                                        ss << "(" << fixed << setw(2) << right << setprecision(0) << _dnaSeg->GetProgress() << "% stations used)";
×
182
                                        cout_mutex.lock();
×
183
                                        cout << PROGRESS_BACKSPACE_39 << setw(PROGRESS_BLOCK) << left << block << setw(PROGRESS_PERCENT_29) << right << ss.str();
×
184
                                        cout.flush();
×
185
                                        cout_mutex.unlock();
×
186
                                        currentBlock = block;
×
187
                                }
188
                        }
189
                        boost::this_thread::sleep(milliseconds(75));
17✔
190
                }        
191
        }
17✔
192

193
private:
194
        dna_segment*                _dnaSeg;
195
        project_settings*        _p;
196
};
197

198
#endif
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