/[escript]/trunk/ripley/src/domainhelpers.cpp
ViewVC logotype

Contents of /trunk/ripley/src/domainhelpers.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6141 - (show annotations)
Wed Apr 6 03:51:30 2016 UTC (2 years, 8 months ago) by caltinay
File size: 2326 byte(s)
more namespacing of defines.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17 #include <ripley/domainhelpers.h>
18 #include <ripley/RipleyException.h>
19 #include <cmath>
20
21 #ifdef ESYS_HAVE_BOOST_IO
22 #include <boost/iostreams/filter/gzip.hpp>
23 #include <boost/iostreams/filtering_stream.hpp>
24 #endif
25
26 namespace ripley {
27
28 void factorise(std::vector<int>& factors, int product)
29 {
30 int current = product;
31 for (int p = 2; p <= sqrt(product); p++) {
32 while (current % p == 0) {
33 current /= p;
34 factors.push_back(p);
35 }
36 }
37 if (current != 1) {
38 factors.push_back(current);
39 }
40 }
41
42 #ifdef ESYS_HAVE_BOOST_IO
43 std::vector<char> unzip(const std::vector<char>& compressed)
44 {
45 std::vector<char> decompressed = std::vector<char>();
46
47 boost::iostreams::filtering_ostream os;
48
49 os.push(boost::iostreams::gzip_decompressor());
50 os.push(boost::iostreams::back_inserter(decompressed));
51 try {
52 boost::iostreams::write(os, &compressed[0], compressed.size());
53 } catch (boost::iostreams::gzip_error e) {
54 switch(e.error()) {
55 case boost::iostreams::gzip::zlib_error:
56 throw RipleyException("Decompressing failed with: zlib error");
57 case boost::iostreams::gzip::bad_crc:
58 throw RipleyException("Decompressing failed with: CRC error");
59 case boost::iostreams::gzip::bad_length:
60 throw RipleyException("Decompressing failed with: bad length");
61 case boost::iostreams::gzip::bad_header:
62 throw RipleyException("Decompressing failed with: bad header");
63 case boost::iostreams::gzip::bad_footer:
64 throw RipleyException("Decompressing failed with: bad footer");
65 }
66 }
67 return decompressed;
68 }
69 #endif
70
71 } // namespace ripley
72

  ViewVC Help
Powered by ViewVC 1.1.26