本文整理汇总了C++中Observable类的典型用法代码示例。如果您正苦于以下问题:C++ Observable类的具体用法?C++ Observable怎么用?C++ Observable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Observable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(runtime_vars_data, register_callback) {
Observable<std::shared_ptr<const RuntimeVarsData>> obj;
folly::dynamic jsonObj = folly::dynamic::object("key1", "value1")
("key2", "value2");
string json = folly::to<string>(folly::toJson(jsonObj));
obj.set(std::make_shared<const RuntimeVarsData>(json));
int counter = 0;
{
auto handle = obj.subscribeAndCall(
[&counter](std::shared_ptr<const RuntimeVarsData>,
std::shared_ptr<const RuntimeVarsData>) {
counter++;
});
EXPECT_EQ(counter, 1);
jsonObj["key2"] = "value3";
json = folly::to<string>(folly::toJson(jsonObj));
obj.set(std::make_shared<const RuntimeVarsData>(json));
}
EXPECT_EQ(counter, 2);
auto newJson = folly::format(
"{{\"key3\": \"value3\","
"\"key4\": {}}}", json).str();
obj.set(std::make_shared<const RuntimeVarsData>(newJson));
EXPECT_EQ(counter, 2);
}
示例2: while
//Return a list of data points
//Each should take the data average value of each continuous observable
//Each should represent one combination of possible discrete values
vector<DataPoint*> PhaseSpaceBoundary::GetDiscreteCombinations() const
{
if( storedCombinationID == uniqueID && !StoredCombinations.empty() )
{
return StoredCombinations;
}
while( !StoredCombinations.empty() )
{
if( StoredCombinations.back() != NULL ) delete StoredCombinations.back();
StoredCombinations.pop_back();
}
//Calculate all possible combinations of discrete observables
vector<string> thisAllNames = this->GetAllNames();
vector<vector<double> > discreteValues;
vector<string> discreteNames, continuousNames;
vector<vector<double> > discreteCombinations = StatisticsFunctions::DiscreteCombinations( &thisAllNames, this, discreteNames, continuousNames, discreteValues );
(void) continuousNames;
//Create the data points to return
vector<DataPoint*> newDataPoints;
DataPoint* tempPoint = this->GetMidPoint();
if( tempPoint == NULL ) return newDataPoints;
for( unsigned int combinationIndex = 0; combinationIndex < discreteCombinations.size(); ++combinationIndex )
{
DataPoint* templateDataPoint = new DataPoint( *tempPoint );
//Output the discrete values for this combination
for( unsigned int discreteIndex = 0; discreteIndex < discreteNames.size(); ++discreteIndex )
{
//Set the data point
Observable* oldValue = templateDataPoint->GetObservable( discreteNames[discreteIndex] );
Observable* newValue = new Observable( oldValue->GetName(), discreteCombinations[combinationIndex][discreteIndex], oldValue->GetUnit() );
templateDataPoint->SetObservable( discreteNames[discreteIndex], newValue );
delete newValue;
}
newDataPoints.push_back( templateDataPoint );
}
delete tempPoint;
StoredCombinations = newDataPoints;
storedCombinationID = uniqueID;
return newDataPoints;
}
示例3: DataPoint
//Use accept/reject method to create data
int Foam::GenerateData( int DataAmount )
{
//if( newDataSet->GetDataNumber() < DataAmount ) newDataSet->ReserveDataSpace( DataAmount );
for( int dataIndex = 0; dataIndex < DataAmount; ++dataIndex )
{
//Generate the discrete observables, and select the correct Foam generator to use
int combinationIndex = 0;
int incrementValue = 1;
DataPoint * temporaryDataPoint = new DataPoint(allNames);
for( int discreteIndex = int(discreteNames.size() - 1); discreteIndex >= 0; --discreteIndex )
{
//Create the discrete observable
Observable * temporaryObservable = generationBoundary->GetConstraint( *discreteNames_ref[unsigned(discreteIndex)] )->CreateObservable(rootRandom);
double currentValue = temporaryObservable->GetValue();
temporaryDataPoint->SetObservable( *discreteNames_ref2[unsigned(discreteIndex)], temporaryObservable );
delete temporaryObservable;
//Calculate the index
for (unsigned int valueIndex = 0; valueIndex < discreteValues[unsigned(discreteIndex)].size(); ++valueIndex )
{
if ( fabs( discreteValues[unsigned(discreteIndex)][valueIndex] - currentValue ) < DOUBLE_TOLERANCE )
{
combinationIndex += ( incrementValue * int(valueIndex) );
incrementValue *= int(discreteValues[unsigned(discreteIndex)].size());
break;
}
}
}
//Use the index calculated to select a Foam generator and generate an event with it
Double_t* generatedEvent = new Double_t[ continuousNames.size() ];
foamGenerators[unsigned(combinationIndex)]->MakeEvent();
foamGenerators[unsigned(combinationIndex)]->GetMCvect(generatedEvent);
//Store the continuous observables
for (unsigned int continuousIndex = 0; continuousIndex < continuousNames.size(); ++continuousIndex )
{
string unit = generationBoundary->GetConstraint( *continuousNames_ref[continuousIndex] )->GetUnit();
double newValue = minima[continuousIndex] + ( ranges[continuousIndex] * generatedEvent[continuousIndex] );
temporaryDataPoint->SetObservable( *continuousNames_ref2[continuousIndex], newValue, unit );
//cout << continuousNames[continuousIndex] << "\t" << newValue << "\t" << 0.0 << "\t" << unit << endl;
}
delete[] generatedEvent;
// Store the event
temporaryDataPoint->SetDiscreteIndex(dataIndex);
newDataSet->AddDataPoint(temporaryDataPoint);
}
//cout << "Destroying Generator(s)" << endl;
//this->RemoveGenerator();
return DataAmount;
}
示例4: pthread_mutex_lock
vector<DataPoint*> RapidFitIntegrator::getGSLIntegrationPoints( unsigned int number, vector<double> maxima, vector<double> minima, DataPoint* templateDataPoint, vector<string> doIntegrate, PhaseSpaceBoundary* thisBound )
{
pthread_mutex_lock( &GSL_DATAPOINT_GET_THREADLOCK );
bool pointsGood = true;
if( !_global_doEval_points.empty() )
{
if( _global_doEval_points[0] != NULL )
{
vector<string> allConsts = thisBound->GetDiscreteNames();
for( unsigned int i=0; i< allConsts.size(); ++i )
{
double haveVal = _global_doEval_points[0]->GetObservable( allConsts[i] )->GetValue();
double wantVal = templateDataPoint->GetObservable( allConsts[i] )->GetValue();
if( haveVal != wantVal )
{
pointsGood = false;
break;
}
}
}
}
if( ( number != _global_doEval_points.size() ) || (( ( _global_range_minima != minima ) || ( _global_range_maxima != maxima ) ) || !pointsGood ) )
{
clearGSLIntegrationPoints();
_global_doEval_points = initGSLDataPoints( number, maxima, minima, templateDataPoint, doIntegrate );
_global_range_minima = minima;
_global_range_maxima = maxima;
_global_observable_names = doIntegrate;
}
vector<string> allObs = _global_doEval_points[0]->GetAllNames();
for( unsigned int i=0; i< _global_doEval_points.size(); ++i )
{
DataPoint* thisPoint = _global_doEval_points[i];
for( unsigned int j=0; j< allObs.size(); ++j )
{
Observable* thisObs = thisPoint->GetObservable( j );
thisObs->SetBinNumber( -1 );
thisObs->SetBkgBinNumber( -1 );
}
thisPoint->ClearPerEventData();
}
pthread_mutex_unlock( &GSL_DATAPOINT_GET_THREADLOCK );
return _global_doEval_points;
}
示例5: getWeight
double getWeight( DataPoint * x )
{
vector<string> xListOfNames = x->GetAllNames();
vector<string>::iterator xIter = xListOfNames.begin();
Observable * xVar = 0;
double xVal = 1.;
while ( ( xVar = x->GetObservable( *xIter ) ) ) {
if ( (*xIter == "fsig_sw") ) {
xVal = xVar->GetValue();
}
++xIter;
if ( xIter == xListOfNames.end() ) break;
}
return xVal;
}
示例6: getDistance
double getDistance(DataPoint * x, DataPoint * y)
{
double distance = 0.;
double diff = 0.; (void) diff; // Unused
vector<string> xListOfNames = x->GetAllNames();
vector<string> yListOfNames = y->GetAllNames();
vector<string>::iterator xIter = xListOfNames.begin();
vector<string>::iterator yIter = yListOfNames.begin();
Observable * xVar = 0;
Observable * yVar = 0;
double xVal = 0.;
double yVal = 0.;
char buffer[100]; (void) buffer; // Unused
while ( (xVar = x->GetObservable( *xIter ) ) && (yVar = y->GetObservable( *yIter ) ) ) {
//cout << *xIter << endl;
//if ( (*xIter == "time") ) {
// xVal = ( xVar->GetValue() - 1.6 )/1.2;
// yVal = ( yVar->GetValue() - 1.6 )/1.2;
//}
if ( (*xIter == "mass") ) {
xVal = ( xVar->GetValue() - 5200. )/350.;
yVal = ( yVar->GetValue() - 5200. )/350.;
}
else if ( (*xIter == "cosTheta1") ) {
xVal = ( xVar->GetValue() );
yVal = ( yVar->GetValue() );
}
else if( (*xIter == "cosTheta2") ) {
xVal = ( xVar->GetValue() );
yVal = ( yVar->GetValue() );
}
else if ( (*xIter == "phi") ) {
xVal = ( xVar->GetValue() )/3.14159;
yVal = ( yVar->GetValue() )/3.14159;
}
else {
xVal = 0.;
yVal = 0.;
}
distance += ( (xVal - yVal)*(xVal - yVal) );
//sprintf(buffer, " %f %f %f", xVar->GetValue(), yVar->GetValue(), sqrt(distance));
//cout << (*xIter) << buffer << endl;
++xIter, ++yIter;
if ( xIter == xListOfNames.end() || yIter == yListOfNames.end() ) break;
}
return sqrt(distance);
}
示例7: BasicRxnClass
FunctionalRxnClass::FunctionalRxnClass(string name, GlobalFunction *gf, TransformationSet *transformationSet, System *s) :
BasicRxnClass(name,1,"",transformationSet,s)
{
this->cf=0;
this->gf=gf;
for(int vr=0; vr<gf->getNumOfVarRefs(); vr++) {
if(gf->getVarRefType(vr)=="Observable") {
Observable *obs = s->getObservableByName(gf->getVarRefName(vr));
obs->addDependentRxn(this);
} else {
cerr<<"When creating a FunctionalRxnClass of name: "+name+" you provided a function that\n";
cerr<<"depends on an observable type that I can't yet handle! (which is "+gf->getVarRefType(vr)+"\n";
cerr<<"try using type: 'MoleculeObservable' for now.\n";
cerr<<"quiting..."<<endl; exit(1);
}
}
}
示例8: setGlobalObservableDependency
void CompositeFunction::setGlobalObservableDependency(ReactionClass *r, System *s) {
for(int i=0; i<this->n_gfs; i++) {
GlobalFunction *gf=gfs[i];
for(int vr=0; vr<gf->getNumOfVarRefs(); vr++) {
if(gf->getVarRefType(vr)=="Observable") {
Observable *obs = s->getObservableByName(gf->getVarRefName(vr));
obs->addDependentRxn(r);
} else {
cerr<<"When creating a FunctionalRxnClass of name: "+r->getName()+" you provided a function that\n";
cerr<<"depends on an observable type that I can't yet handle! (which is "+gf->getVarRefType(vr)+"\n";
cerr<<"try using type: 'MoleculeObservable' for now.\n";
cerr<<"quiting..."<<endl; exit(1);
}
}
}
}
示例9: getDistances
vector<double> getDistances( DataPoint * x, DataPoint * y )
{
vector<double> distances;
vector<string> xListOfNames = x->GetAllNames();
vector<string> yListOfNames = y->GetAllNames();
vector<string>::iterator xIter = xListOfNames.begin();
vector<string>::iterator yIter = yListOfNames.begin();
Observable * xVar = 0;
Observable * yVar = 0;
while ( (xVar = x->GetObservable( *xIter ) ) && (yVar = y->GetObservable( *yIter ) ) ) {
if ( (*xIter == "time" ) || (*xIter == "mass" )) {
//cout << fabs(xVar->GetValue() - yVar->GetValue() ) << endl;
distances.push_back( fabs(xVar->GetValue() - yVar->GetValue() ) );
}
else if ( (*xIter == "cosTheta") ) {
distances.push_back( fabs(xVar->GetValue() - yVar->GetValue()) );
}
/*
else if( (*xIter == "cosPsi") ) {
distances.push_back( fabs( xVar->GetValue() - yVar->GetValue() ) );
}
else if ( (*xIter == "phi") ) {
double diff = diffmod2pi( xVar->GetValue() - yVar->GetValue() );
distances.push_back( diff );
}
*/
++xIter, ++yIter;
if ( xIter == xListOfNames.end() || yIter == yListOfNames.end() ) break;
}
return distances;
}
示例10: if
double Bd2JpsiKstar_sWave_Fs::angularFactor( )
{
double returnValue=0.;
int globalbin=-1;
int xbin=-1, ybin=-1, zbin=-1;
double num_entries_bin=-1.;
//Observable* cos1Obs = cos1Obs = _datapoint->GetObservable( cosPsiName );
Observable* cos1Obs = _datapoint->GetObservable( cosPsiName );
if( cos1Obs->GetBkgBinNumber() != -1 )
{
return cos1Obs->GetBkgAcceptance();
}
else
{
Observable* cos2Obs = _datapoint->GetObservable( cosThetaName );
Observable* phiObs = _datapoint->GetObservable( phiName );
//Find global bin number for values of angles, find number of entries per bin, divide by volume per bin and normalise with total number of entries in the histogram
xbin = xaxis->FindFixBin( cosPsi ); if( xbin > nxbins ) xbin = nxbins; if( xbin == 0 ) xbin = 1;
ybin = yaxis->FindFixBin( cosTheta ); if( ybin > nybins ) ybin = nybins; if( ybin == 0 ) ybin = 1;
zbin = zaxis->FindFixBin( phi ); if( zbin > nzbins ) zbin = nzbins; if( zbin == 0 ) zbin = 1;
globalbin = histo->GetBin( xbin, ybin, zbin );
num_entries_bin = (double)histo->GetBinContent(globalbin);
//Angular factor normalized with phase space of histogram and total number of entries in the histogram
returnValue = (double)num_entries_bin;// / (deltax * deltay * deltaz) / (double)total_num_entries;
//returnValue = (double)num_entries_bin / histo->Integral();
cos1Obs->SetBkgBinNumber( xbin ); cos1Obs->SetBkgAcceptance( returnValue );
cos2Obs->SetBkgBinNumber( ybin ); cos2Obs->SetBkgAcceptance( returnValue );
phiObs->SetBkgBinNumber( zbin ); phiObs->SetBkgAcceptance( returnValue );
}
return returnValue;
}
示例11: updatePhaseSpaceBoundary
void updatePhaseSpaceBoundary( DataPoint * x, PhaseSpaceBoundary * newPhase, PhaseSpaceBoundary * oldPhase, vector<double> distances )
{
vector<string> xListOfNames = x->GetAllNames();
vector<string>::iterator xIter = xListOfNames.begin();
Observable * xVar = 0;
double min = 0., max = 0.;
int i = 0;
char buffer[100]; (void) buffer;// Unused
while ( ( xVar = x->GetObservable( *xIter ) ) ) {
if ( *xIter == "time" || *xIter == "cosTheta" || *xIter == "mass"){//|| *xIter == "cosPsi" || *xIter == "phi") {
min = xVar->GetValue() - distances[ (unsigned)i ];
max = xVar->GetValue() + distances[ (unsigned)i ];
if ( min > oldPhase->GetConstraint( *xIter )->GetMinimum() ) ((ObservableContinuousConstraint *)newPhase->GetConstraint( *xIter ))->SetMinimum( min );
if ( max < oldPhase->GetConstraint( *xIter )->GetMaximum() ) ((ObservableContinuousConstraint *)newPhase->GetConstraint( *xIter ))->SetMaximum( max );
//cout << *xIter << " " << buffer << endl;
}
++xIter;
if ( xIter == xListOfNames.end() ) break;
i++;
}
}
示例12: exit
void GlobalFunction::prepareForSimulation(System *s)
{
try {
p=FuncFactory::create();
for(unsigned int vr=0; vr<n_varRefs; vr++)
{
if(varRefTypes[vr]=="Observable") {
Observable *obs = s->getObservableByName(varRefNames[vr]);
if(obs==NULL) {
cout<<"When creating global function: "<<this->name<<endl<<" could not find the observable: ";
cout<<varRefNames[vr]<<" of type "<<varRefTypes[vr]<<endl;
cout<<"Quitting."<<endl;
exit(1);
}
obs->addReferenceToMyself(p);
} else {
cout<<"here"<<endl;
cout<<"Uh oh, an unrecognized argType ("<<varRefTypes[vr]<<") for a function! "<<varRefNames[vr]<<endl;
cout<<"Try using the type: \"MoleculeObservable\""<<endl;
cout<<"Quitting because this will give unpredicatable results, or just crash."<<endl;
exit(1);
}
}
for(unsigned int i=0; i<n_params; i++) {
p->DefineConst(paramNames[i],s->getParameter(paramNames[i]));
}
p->SetExpr(this->funcExpression);
}
catch (mu::Parser::exception_type &e)
{
cout<<"Error preparing function "<<name<<" in class GlobalFunction!! This is what happened:"<<endl;
cout<< " "<<e.GetMsg() << endl;
cout<<"Quitting."<<endl;
exit(1);
}
}
示例13: main
int main(int argc, char const *argv[]) {
Observable<std::string> s;
s.registerObserver("GREEN", bar);
s.registerObserver("ORANGE", std::bind(foo, 42));
s.registerObserver("RED", std::bind(foo, 12345));
s.registerObserver("RED", [&] {
std::cout << "Hello RED event" << std::endl;
});
s.notify("GREEN");
s.notify("ORANGE");
s.notify("RED");
return 0;
}
示例14: Sidebar
EnvironmentSidebar::EnvironmentSidebar(ScenarioEditor& scenarioEditor, wxWindow* sidebarContainer, wxWindow* bottomBarContainer)
: Sidebar(scenarioEditor, sidebarContainer, bottomBarContainer)
{
wxSizer* waterSizer = new wxGridSizer(2);
m_MainSizer->Add(waterSizer, wxSizerFlags().Expand());
waterSizer->Add(new VariableSliderBox(this, _("Water height"), g_EnvironmentSettings.waterheight, 0.f, 1.2f), wxSizerFlags().Expand());
waterSizer->Add(new VariableSliderBox(this, _("Water shininess"), g_EnvironmentSettings.watershininess, 0.f, 250.f), wxSizerFlags().Expand());
waterSizer->Add(new VariableSliderBox(this, _("Water waviness"), g_EnvironmentSettings.waterwaviness, 0.f, 10.f), wxSizerFlags().Expand());
waterSizer->Add(new VariableSliderBox(this, _("Water murkiness"), g_EnvironmentSettings.watermurkiness, 0.f, 1.f), wxSizerFlags().Expand());
waterSizer->Add(new VariableColourBox(this, _("Water colour"), g_EnvironmentSettings.watercolour), wxSizerFlags().Expand());
waterSizer->Add(new VariableColourBox(this, _("Water tint"), g_EnvironmentSettings.watertint), wxSizerFlags().Expand());
waterSizer->Add(new VariableColourBox(this, _("Reflection tint"), g_EnvironmentSettings.waterreflectiontint), wxSizerFlags().Expand());
waterSizer->Add(new VariableSliderBox(this, _("Refl. tint strength"), g_EnvironmentSettings.waterreflectiontintstrength, 0.f, 1.f), wxSizerFlags().Expand());
wxSizer* sunSizer = new wxGridSizer(2);
m_MainSizer->Add(sunSizer, wxSizerFlags().Expand().Border(wxTOP, 8));
sunSizer->Add(new VariableSliderBox(this, _("Sun rotation"), g_EnvironmentSettings.sunrotation, -M_PIf, M_PIf), wxSizerFlags().Expand());
sunSizer->Add(new VariableSliderBox(this, _("Sun elevation"), g_EnvironmentSettings.sunelevation, -M_PIf/2, M_PIf/2), wxSizerFlags().Expand());
sunSizer->Add(new VariableSliderBox(this, _("Sun overbrightness"), g_EnvironmentSettings.sunoverbrightness, 1.0f, 3.0f), wxSizerFlags().Expand());
sunSizer->Add(m_LightingModelList = new VariableListBox(this, _("Light model"), g_EnvironmentSettings.lightingmodel), wxSizerFlags().Expand());
m_MainSizer->Add(new LightControl(this, wxSize(150, 150), g_EnvironmentSettings));
m_MainSizer->Add(m_SkyList = new VariableListBox(this, _("Sky set"), g_EnvironmentSettings.skyset), wxSizerFlags().Expand());
m_MainSizer->Add(new VariableColourBox(this, _("Sun colour"), g_EnvironmentSettings.suncolour), wxSizerFlags().Expand());
m_MainSizer->Add(new VariableColourBox(this, _("Terrain ambient colour"), g_EnvironmentSettings.terraincolour), wxSizerFlags().Expand());
m_MainSizer->Add(new VariableColourBox(this, _("Object ambient colour"), g_EnvironmentSettings.unitcolour), wxSizerFlags().Expand());
m_Conn = g_EnvironmentSettings.RegisterObserver(0, &SendToGame);
}
示例15: OnMapReload
void EnvironmentSidebar::OnMapReload()
{
AtlasMessage::qGetEnvironmentSettings qry_env;
qry_env.Post();
g_EnvironmentSettings = qry_env.settings;
g_EnvironmentSettings.NotifyObservers();
}