static ChannelRef create(LoggerRef logger, int32_t id, ChannelGroupRef group, const std::string& alias) { ChannelImpl* impl1 = new ChannelImpl(logger, id, group, alias); ChannelImpl* impl2 = new ChannelImpl(logger, id + 1, group, alias); ChannelRef ret1(impl1); ChannelRef ret2(impl2); impl1->self = ret1; impl2->self = ret2; impl1->reverseRef = ret2; impl2->reverseWRef = ret1; return ret1; }
int main() { std::cout<<std::endl; Retirement ret(); Retirement ret1(1232); Retirement ret2(1234,"Kitchen"); std::cout<<std::endl; return 0; }
const OpStringC8 Multipart_CacheStorage::GetMIME_Type() const { if(first_bodypart_created) { MultipartStorage_Item *storage = used_cache_items.Last(); if(!storage || !storage->item) storage = unused_cache_items.First(); OpStringC8 def_ret; OpStringC8 ret(storage && storage->item? storage->item->GetMIME_Type() : def_ret); return ret; } OpStringC8 ret1(StreamCache_Storage::GetMIME_Type()); return ret1; }
/** * @return One or two intersection points between given entities. */ RS_VectorSolutions RS_Information::getIntersectionLineEllipse(RS_Line* line, RS_Ellipse* ellipse) { RS_VectorSolutions ret; if (line==NULL || ellipse==NULL) { return ret; } // rotate into normal position: double ang = ellipse->getAngle(); double rx = ellipse->getMajorRadius(); double ry = ellipse->getMinorRadius(); RS_Vector center = ellipse->getCenter(); RS_Vector a1 = line->getStartpoint().rotate(center, -ang); RS_Vector a2 = line->getEndpoint().rotate(center, -ang); RS_Vector origin = a1; RS_Vector dir = a2-a1; RS_Vector diff = origin - center; RS_Vector mDir = RS_Vector(dir.x/(rx*rx), dir.y/(ry*ry)); RS_Vector mDiff = RS_Vector(diff.x/(rx*rx), diff.y/(ry*ry)); double a = RS_Vector::dotP(dir, mDir); double b = RS_Vector::dotP(dir, mDiff); double c = RS_Vector::dotP(diff, mDiff) - 1.0; double d = b*b - a*c; if (d < 0) { RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: outside 0"); } else if ( d > 0 ) { double root = sqrt(d); double t_a = (-b - root) / a; double t_b = (-b + root) / a; /*if ( (t_a < 0 || 1 < t_a) && (t_b < 0 || 1 < t_b) ) { if ( (t_a < 0 && t_b < 0) || (t_a > 1 && t_b > 1) ) { RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: outside 1"); } else { RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: inside 1"); } } else {*/ RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: intersection 1"); RS_Vector ret1(false); RS_Vector ret2(false); //if ( 0 <= t_a && t_a <= 1 ) { //RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: 0<=t_a<=1"); ret1 = a1.lerp(a2, t_a); RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: ret1: %f/%f", ret1.x, ret1.y); //} //if ( 0 <= t_b && t_b <= 1 ) { //RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: 0<=t_b<=1"); ret2 = a1.lerp(a2, t_b); RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: ret2: %f/%f", ret2.x, ret2.y); //} if (ret1.valid && ret2.valid) { ret = RS_VectorSolutions(ret1, ret2); } else { if (ret1.valid) { ret = RS_VectorSolutions(ret1); } if (ret2.valid) { ret = RS_VectorSolutions(ret2); } } //} } else { double t = -b/a; if ( 0 <= t && t <= 1 ) { RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: 0<=t<=1"); RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: intersection 2"); ret = RS_VectorSolutions(a1.lerp(a2, t)); RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: ret1: %f/%f", ret.get(0).x, ret.get(0).y); } else { RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: outside 2"); } } ret.rotate(center, ang); return ret; /* RS_Arc* arc = new RS_Arc(NULL, RS_ArcData(ellipse->getCenter(), ellipse->getMajorRadius(), ellipse->getAngle1(), ellipse->getAngle2(), false)); RS_Line* other = (RS_Line*)line->clone(); double angle = ellipse->getAngle(); //double ratio = ellipse->getRatio(); // rotate entities: other->rotate(ellipse->getCenter(), -angle); other->scale(ellipse->getCenter(), RS_Vector(1.0, 1.0/ellipse->getRatio())); ret = getIntersectionLineArc(other, arc); ret.scale(ellipse->getCenter(), RS_Vector(1.0, ellipse->getRatio())); ret.rotate(ellipse->getCenter(), angle); delete arc; delete other; return ret; */ }
#include "common.hpp" class Class {}; // # global scope int global = 0; // Differently from C, expressions can be evaluated to initialize globals. int global2 = global + 1; int ret1() { callStack.push_back("before main!"); return 1; } int global3 = ret1(); // ERROR: only single expressions that initialize a global are allowed however. //global = 1; //if (1){} //callStack.push_back("global"); //File IO void ios_write_fail(std::string path) { throw std::ios_base::failure("Error: Could not write to file: " + path); } void ios_read_fail(std::string path) { throw std::ios_base::failure("Error: Could not read file: " + path);
int sum5(int a1, int a2, int a3, int a4, int a5) { int f = a1 * a4; int v = fact(ret3(ret1(), ret2())); return a1 * a2+ a3 * a4 + a5 * a1 + f + v; }
int main(int argc, char* argv[]) { std::shared_ptr<Empty> blank; std::shared_ptr<Program> prg(new Program()); std::shared_ptr<SharedDecl> shDecl1(new SharedDecl("y", blank)); prg->Add(shDecl1); std::shared_ptr<Node> initX(new Atom("2")); std::shared_ptr<SharedDecl> shDecl2(new SharedDecl("x", initX)); prg->Add(shDecl2); std::shared_ptr<Sub> sub1(new Sub("Main")); sub1->AddParam("a"); sub1->AddParam("b"); prg->Add(sub1); std::shared_ptr<Atom> atomA(new Atom("a")); std::shared_ptr<Atom> atomB(new Atom("b")); std::shared_ptr<BinaryOp> initRes(new BinaryOp("add", atomA, atomB)); std::shared_ptr<VarDecl> resDecl(new VarDecl("res", initRes)); sub1->Add(resDecl); std::shared_ptr<Atom> atom3i(new Atom("3")); std::shared_ptr<Atom> atom5i(new Atom("5")); std::shared_ptr<BinaryOp> newParam(new BinaryOp("add", atom3i, atom5i)); std::shared_ptr<Allocation> allocat(new Allocation(newParam)); std::shared_ptr<Atom> atomArr(new Atom("arr")); std::shared_ptr<Assignation> asignNew3(new Assignation(atomArr, allocat)); sub1->Add(asignNew3); std::shared_ptr<Atom> atomArrBis(new Atom("arr")); std::shared_ptr<Deallocation> deallocat(new Deallocation(atomArrBis)); sub1->Add(deallocat); std::shared_ptr<Atom> atomC(new Atom("res")); std::shared_ptr<BinaryOp> subCsumAB(new BinaryOp("substract", atomC, initRes)); std::shared_ptr<Assignation> incC(new Assignation(atomC, subCsumAB)); sub1->Add(incC); std::shared_ptr<Atom> atom0(new Atom("0")); std::shared_ptr<BinaryOp> cond1cond(new BinaryOp("equals", atomC, atom0)); std::shared_ptr<If> cond1(new If(cond1cond, "10", "20")); sub1->Add(cond1); std::shared_ptr<Atom> atom1(new Atom("1")); std::shared_ptr<Atom> atom10(new Atom("10")); std::shared_ptr<For> for1(new For("i", atom1, atom10, atom1)); sub1->Add(for1); std::shared_ptr<BinaryOp> addC1(new BinaryOp("add", atomC, atom1)); std::shared_ptr<Assignation> incResActually(new Assignation(atomC, addC1)); for1->Add(incResActually); std::shared_ptr<Loop> loop1(new Loop(cond1cond)); loop1->Add(for1); // don't double reference ever in practice... loop1->Add(addC1); sub1->Add(loop1); std::shared_ptr<Call> call1(new Call("testFun", "")); call1->AddParam(atomA); call1->AddParam(addC1); sub1->Add(call1); std::shared_ptr<Return> ret1(new Return(atom0)); sub1->Add(ret1); XMLDumpVisitor v; prg->Accept(&v); return 0; }