void texture::binding::operator=( binding &&other ) { precondition( _unit != invalid_unit, "invalid texture unit" ); precondition( theBound[_unit] == &other, "bound texture lost unit" ); other._unit = invalid_unit; theBound[_unit] = this; }
/*---------------------------------------------------------------------- Determine whether application *app needs to be updated. Returns latest app version from game server in *app. Not needed by most user programs. Returns dp_RES_OK if update needed, dp_RES_EMPTY if no update needed. ----------------------------------------------------------------------*/ DP_API dp_result_t DP_APIX dpCheckAppVersion( dp_t* dp, dp_appParam_t *app) { precondition(dp); precondition(app); getLatest(dp, app); /* Ignore errors */ if ((app->latest.major == dp_VERS_UNKNOWN) || (app->latest.minor == dp_VERS_UNKNOWN)) { DPRINT(("dpCheckAppVersion: no version info available for this app?\n")); return dp_RES_EMPTY; } if ((app->current.major > app->latest.major) || ((app->current.major == app->latest.major) && (app->current.minor >= app->latest.minor))) { DPRINT(("dpCheckAppVersion: this app is up to date.\n")); return dp_RES_EMPTY; } DPRINT(("dpCheckAppVersion: app needs updating: version cur %d/%d < latest %d/%d\n", app->current.major, app->current.minor, app->latest.major, app->latest.minor)); return dp_RES_OK; }
BOOL Bsc1::getOverloadArray(SZ sz, MBF mbf, OUT IINST **ppiinst, OUT ULONG *pciinst) { precondition(ppiinst); precondition(pciinst); IINST *rgiinst; ULONG cIinst; if (sz && sz[0] && sz[0] != '*') { Array<IINST> arIinst; parIinst = &arIinst; pbscCur = this; GenerateOverloads(sz, mbf, GatherOverloads,this); cIinst = arIinst.size(); rgiinst = (IINST*)malloc(cIinst*sizeof(IINST)); if (!rgiinst) return FALSE; for (UINT i=0; i < cIinst; i++) rgiinst[i] = arIinst[i]; } else { rgiinst = (IINST*)malloc(cEntities*sizeof(IINST)); if (!rgiinst) return FALSE; cIinst = 0; for (UINT i = 0; i < cEntities; i++) { if (fInstFilter(i, mbf) && fHasDefsOrRefs(i)) rgiinst[cIinst++] = i; } } *ppiinst = rgiinst; *pciinst = cIinst; return TRUE; }
std::shared_ptr<application> application::current( void ) { precondition( !stack.empty(), "getting empty stack" ); auto ptr = stack.back().lock(); precondition( bool(ptr), "deleted application" ); return ptr; }
amg(const Matrix &M, const params &p = params()) : prm(p) { precondition( backend::rows(M) == backend::cols(M), "Matrix should be square!" ); boost::shared_ptr<build_matrix> P, R; boost::shared_ptr<build_matrix> A = boost::make_shared<build_matrix>( M ); sort_rows(*A); while( backend::rows(*A) > prm.coarse_enough) { TIC("transfer operators"); boost::tie(P, R) = Coarsening::transfer_operators( *A, prm.coarsening); precondition( backend::cols(*P) > 0, "Zero-sized coarse level in amgcl (diagonal matrix?)" ); TOC("transfer operators"); TIC("move to backend") levels.push_back( level(A, P, R, prm) ); TOC("move to backend") TIC("coarse operator"); A = Coarsening::coarse_operator(*A, *P, *R, prm.coarsening); sort_rows(*A); TOC("coarse operator"); } TIC("coarsest level"); levels.push_back( level(A, prm, levels.empty()) ); TOC("coarsest level"); }
void application::pop( void ) { precondition( !stack.empty(), "popping empty stack" ); auto ptr = stack.back().lock(); precondition( ptr.get() == this, "popping wrong application" ); stack.pop_back(); }
int64_t sample_rate::resample( int64_t i, const sample_rate &rate ) const { precondition( _ratio.valid(), "invalid destination sample rate" ); precondition( rate._ratio.valid(), "invalid source sample rate" ); base::ratio tmp = i * ( _ratio / rate._ratio ); return tmp.round(); }
void Loader::compositionExit() { precondition(component != nullptr); precondition(composition != nullptr); component->setImplementation(composition); composition = nullptr; }
void Loader::componentExit() { precondition(lib != nullptr); precondition(component != nullptr); lib->getComponents().add(component); component = nullptr; }
void Loader::componentEnter(const TiXmlElement &element) { precondition(lib != nullptr); precondition(component == nullptr); const std::string name = getAttribute(element, "name"); component = ComponentFactory::produce(name); }
void DrawPort::removeConnectionPoint(RelativePosition *point) { precondition(point->hasAnchor()); precondition(point->getAnchor() == &this->getPosition()); point->removeAnchor(); postcondition(!point->hasAnchor()); }
void Loader::connectionEnter(const TiXmlElement &element) { precondition(composition != nullptr); precondition(lib != nullptr); ConnectionParser parser(*lib, element, *composition); Connection * connection = ConnectionFactory::produce(parser.startPort(), parser.endPort(), parser.path()); composition->getConnections().add(connection); }
void Loader::instanceEnter(const TiXmlElement &element) { precondition(lib != nullptr); precondition(composition != nullptr); InstanceParser parser(*lib, element); Instance *instance = InstanceFactory::produce(parser.component(), parser.name(), parser.position()); composition->getInstances().add(instance); }
void json::append( json &&that ) { precondition( is<json_object>(), "receiving object not a json object" ); precondition( that.is<json_object>(), "source not a json object" ); json_object &m = get<json_object>(); json_object &o = that.get<json_object>(); for ( auto &i: o ) m[i.first] = i.second; }
void Loader::compositionEnter(const TiXmlElement &element) { precondition(composition == nullptr); precondition(component != nullptr); CompositionInstance *instance = new CompositionInstance(component); instance->setWidth(std::atoi(getAttribute(element, "width").c_str())); instance->setHeight(std::atoi(getAttribute(element, "height").c_str())); composition = new Composition(instance); }
// create a BSC object using an existing PDB PDBAPI(BOOL) Bsc::open(PDB* ppdb, OUT Bsc** ppbsc) { precondition(ppbsc); precondition(ppdb); Bsc1* pbsc1 = new Bsc1; *ppbsc = pbsc1; if (!pbsc1) return FALSE; return pbsc1->init(ppdb); }
void read_dense(const std::string &fname, SizeT &n, SizeT &m, std::vector<Val> &v) { std::ifstream f(fname.c_str(), std::ios::binary); precondition(f, "Failed to open matrix file"); precondition(read(f, n), "File I/O error"); precondition(read(f, m), "File I/O error"); v.resize(n * m); precondition(read(f, v), "File I/O error"); }
BOOL MRE::FDelete() { precondition ( m_pstreamFileInfo ); precondition ( m_pstreamClassMods ); precondition ( m_pstreamFileMods ); precondition ( m_pstreamRudeFiles ); _TCHAR szStreamName[ ctchMrePathMax ]; Stream * pstream; EnumMapNiFi e(m_mpnifi); m_mrelog.LogNote ( "Note: deleting all streams.\n" ); // enumerate all the src file streams while ( e.next() ) { PFI pfi; NI ni; e.get ( &ni, &pfi ); assert ( ni == pfi->niFile ); if ( pfi->FHasTarget() ) { pfi->SetFstatus ( fsmOutOfDate ); _sntprintf ( szStreamName, countof(szStreamName), c_szMreFileFmt, ni ); if ( m_ppdb->OpenStream ( szStreamName, &pstream ) ) { pstream->Truncate ( 0 ); pstream->Release(); } } } // invalidate the current buffer, if any m_mrfibufRoot.FInitEmpty(); // get rid of the various streams m_pstreamClassInfo->Truncate ( 0 ); m_pstreamClassMods->Truncate ( 0 ); m_pstreamFileMods->Truncate ( 0 ); m_pstreamRudeFiles->Truncate ( 0 ); // get rid of the line change record data m_lcrechandler.Delete(); // reset all the in memory copies of the streams m_mpnici.reset(); m_rgtagniPending.reset(); m_rgtagclsdep.reset(); m_rgtagniRude.reset(); m_itagclsdepSav = m_rgtagclsdep.size(); m_ftagniPendingDirty = fFalse; m_itagniRudeSav = m_rgtagniRude.size(); return fTrue; }
ilu0( const Matrix &A, const params &, const typename Backend::params&) : luval( A.val ), dia ( backend::rows(A) ) { const size_t n = backend::rows(A); const value_type eps = amgcl::detail::eps<value_type>(1); std::vector<ptrdiff_t> work(n, -1); for(size_t i = 0; i < n; ++i) { ptrdiff_t row_beg = A.ptr[i]; ptrdiff_t row_end = A.ptr[i + 1]; for(ptrdiff_t j = row_beg; j < row_end; ++j) work[ A.col[j] ] = j; for(ptrdiff_t j = row_beg; j < row_end; ++j) { ptrdiff_t c = A.col[j]; // Exit if diagonal is reached if (static_cast<size_t>(c) >= i) { precondition( static_cast<size_t>(c) == i, "No diagonal value in system matrix" ); precondition( fabs(luval[j]) > eps, "Zero pivot in ILU" ); dia[i] = j; luval[j] = 1 / luval[j]; break; } // Compute the multiplier for jrow value_type tl = luval[j] * luval[dia[c]]; luval[j] = tl; // Perform linear combination for(ptrdiff_t k = dia[c] + 1; k < A.ptr[c + 1]; ++k) { ptrdiff_t w = work[A.col[k]]; if (w >= 0) luval[w] -= tl * luval[k]; } } // Refresh work for(ptrdiff_t j = row_beg; j < row_end; ++j) work[A.col[j]] = -1; } }
int reduce_by_key_sink( IKTuple &&ikeys, vector<V> const &ivals, OKTuple &&okeys, vector<V> &ovals, Comp, Oper ) { namespace fusion = boost::fusion; typedef typename extract_value_types<IKTuple>::type K; static_assert( std::is_same<K, typename extract_value_types<OKTuple>::type>::value, "Incompatible input and output key types"); precondition( fusion::at_c<0>(ikeys).nparts() == 1 && ivals.nparts() == 1, "reduce_by_key is only supported for single device contexts" ); precondition(fusion::at_c<0>(ikeys).size() == ivals.size(), "keys and values should have same size" ); const auto &queue = fusion::at_c<0>(ikeys).queue_list(); backend::select_context(queue[0]); const int NT_cpu = 1; const int NT_gpu = 256; const int NT = is_cpu(queue[0]) ? NT_cpu : NT_gpu; size_t count = fusion::at_c<0>(ikeys).size(); size_t num_blocks = (count + NT - 1) / NT; size_t scan_buf_size = alignup(num_blocks, NT); backend::device_vector<int> key_sum (queue[0], scan_buf_size); backend::device_vector<V> pre_sum (queue[0], scan_buf_size); backend::device_vector<V> post_sum (queue[0], scan_buf_size); backend::device_vector<V> offset_val(queue[0], count); backend::device_vector<int> offset (queue[0], count); /***** Kernel 0 *****/ auto krn0 = offset_calculation<K, Comp>(queue[0]); krn0.push_arg(count); boost::fusion::for_each(ikeys, do_push_arg(krn0)); krn0.push_arg(offset); krn0(queue[0]); VEX_FUNCTION(int, plus, (int, x)(int, y), return x + y;);
/*-------------------------------------------------------------------------- Save the apps list to disk. (Called at quit time to provide quick info on next startup). --------------------------------------------------------------------------*/ dp_result_t /* status */ dp_freezeAppsList( dp_t *dp) /* Owner of apps table */ { FILE* fp; dp_result_t err = dp_RES_OK; precondition(dp != NULL); precondition(dp->dpio != NULL); DPRINT(("dp_freezeAppsList:\n")); if (!dp->apps || (dptab_tableSize(dp->apps) == 0)) { DPRINT(("dptab_table_freeze: table has no entry\n")); return dp_RES_OK; } /* Get the file */ fp = fopen(APPS_CACHE_FILE, "wb"); if (fp == NULL) { DPRINT(("dp_freezeAppsList: can't open %s, errno %d\n", APPS_CACHE_FILE, errno)); return dp_RES_FULL; } /* Write the info (either NULL or a table) */ if(dp->apps != NULL) { char c = 1; if(fwrite(&c, sizeof(char), 1, fp) != 1) { fclose(fp); DPRINT(("dp_freezeAppsList: can't write %s, errno %d\n", APPS_CACHE_FILE, errno)); return dp_RES_FULL; } err = dptab_table_freeze(dp->apps, dp->dpio, fp); DPRINT(("dp_freezeAppsList: fp now at %ld\n", ftell(fp))); } else { char c = 0; if(fwrite(&c, sizeof(char), 1, fp) != 1) { fclose(fp); DPRINT(("dp_freezeAppsList: can't write %s, errno %d\n", APPS_CACHE_FILE, errno)); return dp_RES_FULL; } } /* Finish the file */ fclose(fp); DPRINT(("dp_freezeAppsList: returning err:%d\n", err)); return err; }
void ComponentFactory::dispose(IComponent *component) { precondition(component != nullptr); cleanup(*component); delete component; }
block_matrix_adapter(const Matrix &A) : A(A) { precondition( backend::rows(A) % BlockSize == 0 && backend::cols(A) % BlockSize == 0, "Matrix size is not divisible by block size!" ); }
// Copy vector from builtin backend. static boost::shared_ptr<vector> copy_vector(typename builtin<real>::vector const &x, const params &prm) { precondition(!prm.context().empty(), "Empty VexCL context!"); return boost::make_shared<vector>(prm.context(), x); }
// Create vector of the specified size. static boost::shared_ptr<vector> create_vector(size_t size, const params &prm) { precondition(!prm.context().empty(), "Empty VexCL context!"); return boost::make_shared<vector>(prm.context(), size); }
void cmd_line::parse( int argc, char *argv[] ) { precondition( argc > 0, "not enough arguments" ); std::vector<char *> tmp( argv+1, argv+argc ); parse( tmp ); }
std::string in_numeric_range(cmdline_param const & param, char const * value, void const * range_info) { const char * const MSG = "Error with {1}=\"{2}\": expected a value between " "{3=min} and {4=max} (inclusive), formatted as {5}."; precondition(range_info != nullptr); numeric_range_info const & nri = *reinterpret_cast<numeric_range_info const *>(range_info); number_info info; auto ptr_to_null_char = strchr(value, 0); auto end = scan_number(value, ptr_to_null_char, nri.allowed_formats, info); auto valid = (end == ptr_to_null_char); if (valid) { if (info.format == numeric_formats::floating_point_only) { if (!std::isnan(nri.min) && info.floating_point < nri.min) { valid = false; } else if (!std::isnan(nri.max) && info.floating_point > nri.max) { valid = false; } } else { int64_t n = static_cast<int64_t>(info.whole_number); if (info.negative) { n *= -1; } valid = n >= nri.min && n <= nri.max; } } return valid ? "" : interp(MSG, {param.get_preferred_name(), value, nri.min, nri.max, get_names_for_numeric_formats(nri.allowed_formats)}); }
void sample_rate::set_rate( double r, bool realtime ) { precondition( r > 0.0, "invalid sample rate {0}", r ); // people will often pass in 23.98 for 23.976 // so use an epsilon of 0.005 static const double kRateEps = 0.005; if ( std::abs( r - (24000.0/1001.0) ) < kRateEps ) set( 24000, 1001 ); else if ( std::abs( r - (30000.0/1001.0) ) < kRateEps ) set( 30000, 1001 ); else if ( std::abs( r - (48000.0/1001.0) ) < kRateEps ) set( 48000, 1001 ); else if ( std::abs( r - (60000.0/1001.0) ) < kRateEps ) set( 60000, 1001 ); else { // EDL files and such have frame rates // for speed changes that are fractional int64_t num = static_cast<int64_t>( r ); int64_t den = 1; double curRem = r - static_cast<double>( num ); while ( std::abs( curRem ) > kRateEps ) { den *= 10; num = static_cast<int64_t>( r * static_cast<double>( den ) ); curRem = r - ( static_cast<double>( num ) / static_cast<double>( den ) ); } set( num, den ); } _realtime = realtime; }
/*------------------------------------------------------------------------ Call this function after receiving a packet telling you to activate your account in response to dpAccountLogin() or dpAccountCreate() to activate your account. 'secretcode' is the secret code emailed to you by the server when the account was created. ------------------------------------------------------------------------*/ DP_API dp_result_t DP_APIX dpAccountActivateW( dp_t *dp, const wchar_t *secretcode) { precondition(dp); return tserv_account_activateW(dp->tserv, secretcode); }
void parser::parse_comment( std::istream &in ) { precondition( in.get() == '/', "missing '/' to start comment" ); while ( in.peek() == '/' ) in.get(); _func.add( '/' ); _func.add( '/' ); _func.add( ' ' ); while ( !in.eof() && in ) { int c = in.get(); if ( std::char_traits<char>::not_eof( c ) ) { if ( c == ']' ) break; else _func.add( static_cast<char>( c ) ); } } _func.push_code(); if ( in.peek() == '\n' ) in.get(); }