本文整理汇总了C++中Branch类的典型用法代码示例。如果您正苦于以下问题:C++ Branch类的具体用法?C++ Branch怎么用?C++ Branch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Branch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void AudioSelector::enableAutoSelect(AudioSource *source, int prio)
{
assert(branch_map.find(source) != branch_map.end());
Branch *branch = branch_map[source];
branch->setSelectionPrio(prio);
branch->enableAutoSelect();
} /* AudioSelector::enableAutoSelect */
示例2: test_snippet
void test_snippet(std::string const& source)
{
Branch branch;
branch.compile(source);
if (test_fail_on_static_error(&branch))
return;
Stack context;
evaluate_branch(&context, &branch);
if (test_fail_on_runtime_error(context))
return;
// Try stripping orphaned state, this should not have an effect.
caValue trash;
strip_orphaned_state(&branch, &context.state, &trash);
if (!is_null(&trash)) {
std::cout << "Falsely orphaned state in " << get_current_test_name() << std::endl;
std::cout << "Code = " << source << std::endl;
std::cout << "Trash = " << trash.toString() << std::endl;
declare_current_test_failed();
return;
}
}
示例3: test_trimmed_state
void test_trimmed_state(std::string const& source, std::string const& dest,
std::string const& expectedTrash)
{
Branch sourceBranch;
sourceBranch.compile(source);
if (test_fail_on_static_error(&sourceBranch))
return;
Stack context;
evaluate_branch(&context, &sourceBranch);
if (test_fail_on_runtime_error(context))
return;
Branch destBranch;
destBranch.compile(dest);
if (test_fail_on_static_error(&destBranch))
return;
caValue trash;
strip_orphaned_state(&destBranch, &context.state, &trash);
if (expectedTrash != trash.toString()) {
declare_current_test_failed();
std::cout << "In test " << get_current_test_name() << std::endl;
std::cout << expectedTrash << " != " << trash.toString() << std::endl;
}
}
示例4: while
bool BranchList::add(docstring const & s)
{
bool added = false;
size_t i = 0;
while (true) {
size_t const j = s.find_first_of(separator_, i);
docstring name;
if (j == docstring::npos)
name = s.substr(i);
else
name = s.substr(i, j - i);
// Is this name already in the list?
bool const already =
find_if(list.begin(), list.end(),
BranchNamesEqual(name)) != list.end();
if (!already) {
added = true;
Branch br;
br.setBranch(name);
br.setSelected(false);
br.setFileNameSuffix(false);
list.push_back(br);
}
if (j == docstring::npos)
break;
i = j + 1;
}
return added;
}
示例5: test_state_is_reset_when_if_fails
void test_state_is_reset_when_if_fails()
{
Branch branch;
Stack context;
Term* c = branch.compile("c = true");
branch.compile("if c { state i = 0; i += 1 } else { 'hi' }");
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{i: 1}]}");
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{i: 2}]}");
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{i: 3}]}");
set_bool(c, false);
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [null, null]}");
set_bool(c, true);
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{i: 1}]}");
}
示例6: SceneNode
Tree::Tree(const std::string& name, double initialLength, double initialThickness,
int initialBranches, int leavesPerBranch, int leafStartLevel,
double thicknessReduction, double lengthReduction, int recursiveDepth, int seed)
: SceneNode(name)
{
totalBranches = 0;
totalLeaves = 0;
::initialLength = initialLength;
::initialThickness = initialThickness;
::initialBranches = initialBranches;
::leavesPerBranch = leavesPerBranch;
::leafStartLevel = leafStartLevel;
::thicknessReduction = thicknessReduction;
::lengthReduction = lengthReduction;
::recursiveDepth = recursiveDepth;
wood.bump("woodbump.png");
srand( seed );
Branch* trunk = new Branch("Trunk", 0, initialThickness, initialLength);
trunk->rotate('x', -90);
add_child(trunk);
//std::cerr << "Total Branches: " << totalBranches
// << " Total Leaves: " << totalLeaves << std::endl;
}
示例7: CreatBranch
Component* Branch::CreatBranch()
{
Branch *pBranch = new Branch;
pBranch->Init();
pBranch->SetSpecial(-1);
return pBranch;
}
示例8: QLatin1String
bool RemoteBranchModel::refreshBranches(const QString &workingDirectory, bool remoteBranches,
int *currentBranch, QString *errorMessage)
{
// Run branch command with verbose.
QStringList branchArgs;
branchArgs << QLatin1String(GitClient::noColorOption) << QLatin1String("-v");
QString output;
*currentBranch = -1;
if (remoteBranches)
branchArgs.push_back(QLatin1String("-r"));
if (!runGitBranchCommand(workingDirectory, branchArgs, &output, errorMessage))
return false;
if (debug)
qDebug() << Q_FUNC_INFO << workingDirectory << output;
// Parse output
m_workingDirectory = workingDirectory;
m_branches.clear();
const QStringList branches = output.split(QLatin1Char('\n'));
const int branchCount = branches.size();
bool isCurrent;
for (int b = 0; b < branchCount; b++) {
Branch newBranch;
if (newBranch.parse(branches.at(b), &isCurrent)) {
m_branches.push_back(newBranch);
if (isCurrent)
*currentBranch = b;
}
}
reset();
return true;
}
示例9: test_state_is_reset_when_if_fails2
void test_state_is_reset_when_if_fails2()
{
// Similar to test_state_is_reset_when_if_fails, but this one doesn't
// have an 'else' block and it uses test_oracle.
internal_debug_function::oracle_clear();
Branch branch;
Term* a = branch.compile("a = true");
branch.compile("if a { state s = test_oracle() }");
internal_debug_function::oracle_send(1);
internal_debug_function::oracle_send(2);
internal_debug_function::oracle_send(3);
Stack context;
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{s: 1}]}");
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{s: 1}]}");
set_bool(a, false);
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [null, null]}");
set_bool(a, true);
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{s: 2}]}");
}
示例10: test_type_not_prematurely_used
void test_type_not_prematurely_used()
{
// Verify that a circa-defined type is not used until interpreter time. Modifying
// a type's release() handler after there are already instances of it, is not good.
Branch branch;
branch.compile(
"type MyType; \n"
"def f() -> MyType\n"
"def g(MyType t)\n"
"s = f()\n"
"g(s)\n"
"l = [s s s]\n"
"type MyCompoundType {\n"
" MyType t\n"
"}\n"
"state MyType st\n"
"state MyType st2 = create(MyType)\n"
);
Type* myType = (Type*) circa_find_type(&branch, "MyType");
Type* myCompoundType = (Type*) circa_find_type(&branch, "MyCompoundType");
test_assert(!myType->inUse);
test_assert(!myCompoundType->inUse);
circa::Value value1, value2;
create(myType, &value1);
create(myCompoundType, &value2);
test_assert(myType->inUse);
test_assert(myCompoundType->inUse);
}
示例11: repro_source_after_rename
void repro_source_after_rename()
{
Branch branch;
// Simple test
Term* a = branch.compile("a = 1");
rename(a, "apple");
test_equals(get_term_source_text(a), "apple = 1");
// Rename a function argument
Term* b = branch.compile("b = 5");
Term* add = branch.compile("add( b , 10)");
rename(b, "banana");
test_equals(get_term_source_text(add), "add( banana , 10)");
// Rename a function
Term* myfunc = import_function(&branch, NULL, "def myfunc(int)");
Term* myfunc_call = branch.compile("myfunc(555)");
rename(myfunc, "my_renamed_func");
test_equals(get_term_source_text(myfunc_call), "my_renamed_func(555)");
}
示例12: test_lazy
void test_lazy()
{
#ifdef DEFERRED_CALLS_FIRST_DRAFT
Branch branch;
Term* a = branch.compile("a = add(1 2)");
set_lazy_call(a, true);
Stack context;
push_frame(&context, &branch);
run_interpreter(&context);
test_equals(get_register(&context, a), ":Unevaluated");
Frame* frame = push_frame(&context, &branch);
frame->pc = a->index;
frame->startPc = frame->pc;
frame->endPc = frame->pc + 1;
frame->strategy = ByDemand;
run_interpreter(&context);
test_equals(get_register(&context, a), "3");
reset_stack(&context);
Term* b = branch.compile("b = add(a a)");
push_frame(&context, &branch);
run_interpreter(&context);
test_equals(get_register(&context, a), "3");
test_equals(get_register(&context, b), "6");
#endif
}
示例13: test_custom_object
void test_custom_object()
{
g_currentlyAllocated = 0;
g_totalAllocated = 0;
Branch branch;
branch.compile(
"type MyType; \n"
"def create_object() -> MyType\n"
"def check_object(MyType t)\n"
"s = create_object()\n"
"check_object(s)\n"
);
circa_install_function(&branch, "create_object", create_object);
circa_install_function(&branch, "check_object", check_object);
circa_setup_object_type(circa_find_type(&branch, "MyType"),
sizeof(CustomObject), CustomObjectRelease);
// Shouldn't allocate any objects before running.
test_equals(g_currentlyAllocated, 0);
test_equals(g_totalAllocated, 0);
Stack stack;
push_frame(&stack, &branch);
run_interpreter(&stack);
test_assert(&stack);
circa_clear_stack(&stack);
// Running the script should only cause 1 object allocation.
test_equals(g_currentlyAllocated, 0);
test_equals(g_totalAllocated, 1);
}
示例14: bug_reproducing_list_after_eval
void bug_reproducing_list_after_eval()
{
// There once was a bug where source repro would fail when using a list
// in a vectorized function, but only after that piece of code had been
// evaluated. This was because vectorize_vv was calling apply() which
// was changing the 'statement' property of its inputs.
Branch branch;
Term* sum = branch.compile("[1 1] + [1 1]");
Term* in0 = sum->input(0);
Term* in1 = sum->input(0);
test_equals(get_term_source_text(in0), "[1 1]");
test_equals(get_term_source_text(in1), "[1 1]");
test_equals(get_input_source_text(sum, 0), "[1 1] ");
test_equals(get_input_source_text(sum, 1), " [1 1]");
test_equals(get_branch_source_text(&branch), "[1 1] + [1 1]");
evaluate_branch(&branch);
test_equals(get_term_source_text(in0), "[1 1]");
test_equals(get_term_source_text(in1), "[1 1]");
test_equals(get_input_source_text(sum, 0), "[1 1] ");
test_equals(get_input_source_text(sum, 1), " [1 1]");
test_equals(get_branch_source_text(&branch), "[1 1] + [1 1]");
}
示例15: cpp_accessor_for_type
std::string cpp_accessor_for_type(Type* type)
{
#if 0
std::stringstream out;
std::string indent = " ";
out << "struct " << get_cpp_type_name(type) << "\n";
out << "{\n";
out << indent << "Term* _term\n";
out << "\n";
out << indent << get_cpp_type_name(type) << "(Term* term) : _term(term) {}\n";
out << "\n";
Branch* prototype = type->prototype;
for (int i=0; i < prototype.length(); i++) {
Term* field = prototype[i];
out << indent << get_cpp_type_name(field->type) << "& " << field->name << "() ";
out << "{ return " << get_cpp_type_accessor(field->type) << "(_term->field(" <<
i << ")); }\n";
}
out << "};\n";
return out.str();
#endif
return "";
}