@@ -42,47 +42,29 @@ namespace js
4242using namespace mfem ;
4343
4444// / Display a new stream
45- void display (std::stringstream & commands , const int w, const int h)
45+ void display (StreamCollection streams , const int w, const int h)
4646{
4747 // reset antialiasing
4848 if (win.wnd )
4949 {
5050 win.wnd ->getRenderer ().setAntialiasing (0 );
5151 }
5252
53- std::string word, keys;
54- double minv = 0.0 , maxv = 0.0 ;
55- while (commands >> word)
56- {
57- if (word == " keys" )
58- {
59- std::cout << " parsing 'keys'" << std::endl;
60- commands >> keys;
61- }
62- else if (word == " valuerange" )
63- {
64- std::cout << " parsing 'valuerange'" << std::endl;
65- commands >> minv >> maxv;
66- }
67- else
68- {
69- std::cout << " unknown command '" << word << " '" << std::endl;
70- }
71- }
72-
7353 win.window_title = " glvis" ;
7454 win.window_x = 0 .;
7555 win.window_y = 0 .;
7656 win.window_w = w;
7757 win.window_h = h;
7858
79- if (!win.GLVisInitVis ({} )) { return ; }
59+ if (!win.GLVisInitVis (std::move (streams) )) { return ; }
8060
81- CallKeySequence (keys.c_str ());
82-
83- if (minv || maxv)
61+ while (win.comm_thread ->process_one ())
8462 {
85- win.vs ->SetValueRange (minv, maxv);
63+ if (win.glvis_command ->Execute () < 0 )
64+ {
65+ // GLVisCommand signalled exit!
66+ break ;
67+ }
8668 }
8769
8870 SendExposeEvent ();
@@ -96,61 +78,48 @@ void display(std::stringstream & commands, const int w, const int h)
9678// each string in streams must start with `parallel <nproc> <rank>'
9779//
9880using StringArray = std::vector<std::string>;
99- void processParallelStreams (DataState & state,
100- const StringArray & streams,
101- std::stringstream * commands = nullptr )
81+ StreamCollection processParallelStreams (DataState & state,
82+ const StringArray & streams)
10283{
10384 // std::cerr << "got " << streams.size() << " streams" << std::endl;
104- // HACK: match unique_ptr<istream> interface for ReadStreams:
105- std::vector<std::stringstream> sstreams (streams.size ());
10685 StreamCollection istreams (streams.size ());
10786 for (int i = 0 ; i < streams.size (); ++i)
10887 {
109- sstreams [i] = std::stringstream (streams[i]);
88+ istreams [i] = std::unique_ptr<std::istream>( new std:: stringstream (streams[i]) );
11089 // pull off the first list
11190 std::string word;
11291 int nproc, rank;
113- sstreams[i] >> word >> nproc >> rank;
114- // std::cerr << "packing " << rank+1 << "/" << nproc << std::endl;
115- istreams[i] = std::unique_ptr<std::istream>(&sstreams[i]);
92+ *istreams[i] >> word >> nproc >> rank;
11693 }
11794
11895 StreamReader reader (state);
11996 reader.ReadStreams (istreams);
12097
121- if (commands)
122- {
123- commands->seekg (istreams[0 ]->tellg ());
124- }
125-
126- // HACK: don't let unique_ptr free the data
127- for (int i = 0 ; i < streams.size (); ++i)
128- {
129- istreams[i].release ();
130- }
131-
13298 last_stream_nproc = streams.size ();
99+
100+ return istreams;
133101}
134102
135103void displayParallelStreams (const StringArray & streams, const int w,
136104 const int h)
137105{
138- std::stringstream commands (streams[0 ]);
139- processParallelStreams (win.data_state , streams, &commands);
106+ StreamCollection sc = processParallelStreams (win.data_state , streams);
140107
141- display (commands , w, h);
108+ display (std::move (sc) , w, h);
142109}
143110
144111void displayStream (const std::string & stream, const int w, const int h)
145112{
146- std::stringstream ss (stream);
113+ std::unique_ptr<std::istream> ss (new std::istringstream ( stream) );
147114 std::string data_type;
148- ss >> data_type;
115+ * ss >> data_type;
149116
150117 StreamReader reader (win.data_state );
151- reader.ReadStream (ss, data_type);
118+ reader.ReadStream (* ss, data_type);
152119
153- display (ss, w, h);
120+ StreamCollection sc;
121+ sc.emplace_back (std::move (ss));
122+ display (std::move (sc), w, h);
154123}
155124
156125//
0 commit comments