Changeset 17911 for trunk


Ignore:
Timestamp:
06/16/14 17:40:48 (10 years ago)
Author:
tbretz
Message:
Added a possibility to turn off exceptions for SetPtrAddress operations
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mcore/fits.h

    r17777 r17911  
    6161        kCompUnknown,
    6262        kCompFACT
     63    };
     64
     65    enum fitsstate
     66    {
     67        throwbit = 8
    6368    };
    6469
     
    477482    };
    478483
     484    void Exception(const std::string &txt)
     485    {
     486#ifdef __EXCEPTIONS
     487        if (exceptions()&throwbit)
     488            throw std::runtime_error(txt);
     489#endif
     490        gLog << ___err___ << "ERROR - " << txt << std::endl;
     491    }
     492
    479493protected:
    480494    std::ofstream fCopy;
     
    559573        if (!good())
    560574            return;
     575
     576        EnableAddressExceptions();
    561577
    562578        if (memcmp(simple, "SIMPLE  = ", 10))
     
    697713        {
    698714#ifdef __EXCEPTIONS
    699             throw std::runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
    700 #else
    701             gLog << ___err___ << "ERROR - You are trying to read a compressed fits with the base fits class. Please use factfits instead." << std::endl;
     715            throw std::runtime_error("Trying to read a compressed fits with the base fits class. Use factfits instead.");
     716#else
     717            gLog << ___err___ << "ERROR - Trying to read a compressed fits with the base fits class. Use factfits instead." << std::endl;
    702718#endif
    703719            clear(rdstate()|std::ios::badbit);
     
    711727        {
    712728#ifdef __EXCEPTIONS
    713             throw std::runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
    714 #else
    715             gLog << ___err___ << "ERROR - You are trying to read a compressed fits with the base fits class. Please use factfits instead." << std::endl;
     729            throw std::runtime_error("Trying to read a compressed fits with the base fits class. Use factfits instead.");
     730#else
     731            gLog << ___err___ << "ERROR - Trying to read a compressed fits with the base fits class. Use factfits instead." << std::endl;
    716732#endif
    717733            clear(rdstate()|std::ios::badbit);
     
    853869    }
    854870
     871    void EnableAddressExceptions(bool b=true)
     872    {
     873        if (b)
     874            exceptions(iostate(throwbit));
     875        else
     876            exceptions(iostate(exceptions()&~throwbit));
     877    }
     878
     879    void DisableAddressExceptions()
     880    {
     881        EnableAddressExceptions(false);
     882    }
     883
    855884    void *SetPtrAddress(const std::string &name)
    856885    {
     
    859888            std::ostringstream str;
    860889            str << "SetPtrAddress('" << name << "') - Column not found.";
    861 #ifdef __EXCEPTIONS
    862             throw std::runtime_error(str.str());
    863 #else
    864             gLog << ___err___ << "ERROR - " << str.str() << std::endl;
     890            Exception(str.str());
    865891            return NULL;
    866 #endif
    867892        }
    868893
     
    888913            std::ostringstream str;
    889914            str << "SetPtrAddress('" << name << "') - Column not found.";
    890 #ifdef __EXCEPTIONS
    891             throw std::runtime_error(str.str());
    892 #else
    893             gLog << ___err___ << "ERROR - " << str.str() << std::endl;
     915            Exception(str.str());
    894916            return false;
    895 #endif
    896917        }
    897918
     
    901922            str << "SetPtrAddress('" << name << "') - Element size mismatch: expected "
    902923                << fTable.cols[name].size << " from header, got " << sizeof(T);
    903 #ifdef __EXCEPTIONS
    904             throw std::runtime_error(str.str());
    905 #else
    906             gLog << ___err___ << "ERROR - " << str.str() << std::endl;
     924            Exception(str.str());
    907925            return false;
    908 #endif
    909926        }
    910927
     
    914931            str << "SetPtrAddress('" << name << "') - Element count mismatch: expected "
    915932                << fTable.cols[name].num << " from header, got " << cnt;
    916 #ifdef __EXCEPTIONS
    917             throw std::runtime_error(str.str());
    918 #else
    919             gLog << ___err___ << "ERROR - " << str.str() << std::endl;
     933            Exception(str.str());
    920934            return false;
    921 #endif
    922935        }
    923936
     
    962975            std::ostringstream str;
    963976            str <<"SetPtrAddress('" << name << "') - Column not found.";
    964 #ifdef __EXCEPTIONS
    965             throw std::runtime_error(str.str());
    966 #else
    967             gLog << ___err___ << "ERROR - " << str.str() << std::endl;
     977            Exception(str.str());
    968978            return false;
    969 #endif
    970979        }
    971980
     
    975984            str << "SetPtrAddress('" << name << "') - Element count mismatch: expected "
    976985                << fTable.cols[name].num << " from header, got " << cnt;
    977 #ifdef __EXCEPTIONS
    978             throw std::runtime_error(str.str());
    979 #else
    980             gLog << ___err___ << "ERROR - " << str.str() << std::endl;
     986            Exception(str.str());
    981987            return false;
    982 #endif
    983988        }
    984989
Note: See TracChangeset for help on using the changeset viewer.