void File::WriteToDisk(std::string &basePath, DiskWriter *writer) { if (!written || rewrite) { writer->WriteFile(basePath.c_str(), filename.c_str(), data.getData(), data.getLength()); data=CharArray(); written=true; rewrite=false; ReportChange(); } }
int do_CharArray(char *cmd, char *tmpdir, int cmdno) { int length, outlength, res=0; char *out; length = strlen(cmd); read_input_char(tmpdir, &out, &outlength, cmdno); #ifdef DEBUG printf("%s: args=%s, arglength=%d\n", cmd, out, outlength); #endif CharArray(&cmd, &length, &out, &outlength, &res); write_output_char(tmpdir, out, cmdno); free(out); return res; }
void Cache::CacheServiceGateway(unsigned long carId, unsigned short modId, unsigned char version, Biop::ServiceGateway &srg) { cMutexLock lock(&listenerMutex); //printf("Caching gateway %ld, %d\n", carId, modId); if (!gateway) { //not yet cached Directory::Ptr newdir(new ServiceGateway(0,0,CharArray(), (CacheListener *)this)); gateway=newdir; gateway->setVersion(version); gateway.asDirectory()->AddInfo(srg); gateway.asDirectory()->AssignChildren(&unassigned); } else if (gateway->version != version) { gateway->setVersion(version); gateway.asDirectory()->UpdateInfo(srg, &writer); } }
value_t rb_glob(String *pattern) { auto array = new (collector) Array; Platform::wrap([&] { std::vector<CharArray> segments; CharArray path = File::normalize_path(pattern->string); path.split([&](const CharArray &part) { segments.push_back(part); }, CharArray("/")); if(File::absolute_path(path)) glob(array, segments, 1, segments[0].size() ? segments[0] : "/"); else glob(array, segments, 0, ""); }); return array; }
void InitSymData( TYPEPTR typ, TYPEPTR ctyp, int level ) { TOKEN token; unsigned long size; SKIP_TYPEDEFS( typ ); if( typ->decl_type == TYPE_ENUM ) typ = typ->object; /* 07-nov-90 */ token = CurToken; if( CurToken == T_LEFT_BRACE ) { NextToken(); if( CurToken == T_RIGHT_BRACE || CurToken == T_COMMA ) { CErr1( ERR_EMPTY_INITIALIZER_LIST ); } } size = SizeOfArg( typ ); switch( typ->decl_type ) { case TYPE_ARRAY: if( CharArray( typ->object ) ) { InitCharArray( typ ); } else if( WCharArray( typ->object ) ) { InitWCharArray( typ ); } else { if( token == T_LEFT_BRACE ) { ctyp = typ; } else if( level == 0 ) { CErr1( ERR_NEED_BRACES ); } if( typ == ctyp ) { /* initialize new current type */ /* first zero out the whole array; otherwise overlapping fields caused by designated initializers will make life very difficult */ ZeroBytes( size ); RelSeekBytes( -size ); } InitArray( typ, ctyp ); } break; case TYPE_FCOMPLEX: case TYPE_DCOMPLEX: case TYPE_LDCOMPLEX: case TYPE_STRUCT: if( token == T_LEFT_BRACE ) { ctyp = typ; } else if( level == 0 ) { CErr1( ERR_NEED_BRACES ); } if( typ == ctyp ) { /* initialize new current type */ /* zero out all fields; otherwise overlapping fields caused by designated initializers will make life very difficult */ ZeroBytes( size ); RelSeekBytes( -size ); } InitStruct( typ, ctyp ); break; case TYPE_UNION: if( token == T_LEFT_BRACE ) { ctyp = typ; } else if( level == 0 ) { CErr1( ERR_NEED_BRACES ); } InitUnion( typ, ctyp ); break; case TYPE_CHAR: case TYPE_UCHAR: case TYPE_BOOL: case TYPE_SHORT: case TYPE_USHORT: case TYPE_INT: case TYPE_UINT: case TYPE_LONG: case TYPE_ULONG: case TYPE_POINTER: StorePointer( typ, size ); break; case TYPE_LONG64: case TYPE_ULONG64: StoreInt64( typ ); break; case TYPE_FLOAT: case TYPE_DOUBLE: case TYPE_FIMAGINARY: case TYPE_DIMAGINARY: StoreFloat( typ->decl_type, size ); break; case TYPE_LONG_DOUBLE: case TYPE_LDIMAGINARY: //StoreFloat( typ->decl_type, size ); StoreFloat( TYPE_DOUBLE, size ); break; default: break; } if( token == T_LEFT_BRACE ) { if( CurToken == T_COMMA ) { NextToken(); } if( CurToken != T_RIGHT_BRACE ) { CErr1( ERR_TOO_MANY_INITS ); } while( CurToken != T_RIGHT_BRACE ) { if( CurToken == T_EOF ) break; if( CurToken == T_SEMI_COLON )break; if( CurToken == T_LEFT_BRACE )break; NextToken(); } MustRecog( T_RIGHT_BRACE ); } }
local void InitArrayVar( SYMPTR sym, SYM_HANDLE sym_handle, TYPEPTR typ ) { unsigned i; unsigned n; TYPEPTR typ2; SYM_HANDLE sym2_handle; SYM_ENTRY sym2; TREEPTR opnd; TREEPTR value; TOKEN token; typ2 = typ->object; SKIP_TYPEDEFS( typ2 ); switch( typ2->decl_type ) { case TYPE_CHAR: case TYPE_UCHAR: case TYPE_SHORT: case TYPE_USHORT: case TYPE_INT: case TYPE_UINT: case TYPE_LONG: case TYPE_ULONG: case TYPE_LONG64: case TYPE_ULONG64: case TYPE_FLOAT: case TYPE_DOUBLE: case TYPE_POINTER: case TYPE_LONG_DOUBLE: case TYPE_FIMAGINARY: case TYPE_DIMAGINARY: case TYPE_LDIMAGINARY: case TYPE_BOOL: NextToken(); // skip over T_LEFT_BRACE if( CharArray( typ->object ) ) { sym2_handle = MakeNewSym( &sym2, 'X', typ, SC_STATIC ); sym2.flags |= SYM_INITIALIZED; if( sym2.u.var.segment == 0 ) { /* 01-dec-91 */ SetFarHuge( &sym2, 0 ); SetSegment( &sym2 ); SetSegAlign( &sym2 ); /* 02-feb-92 */ } SymReplace( &sym2, sym2_handle ); GenStaticDataQuad( sym2_handle ); InitCharArray( typ ); AssignAggregate( VarLeaf( sym, sym_handle ), VarLeaf( &sym2, sym2_handle ), typ ); } else if( WCharArray( typ->object ) ) { sym2_handle = MakeNewSym( &sym2, 'X', typ, SC_STATIC ); sym2.flags |= SYM_INITIALIZED; if( sym2.u.var.segment == 0 ) { /* 01-dec-91 */ SetFarHuge( &sym2, 0 ); SetSegment( &sym2 ); SetSegAlign( &sym2 ); /* 02-feb-92 */ } SymReplace( &sym2, sym2_handle ); GenStaticDataQuad( sym2_handle ); InitWCharArray( typ ); AssignAggregate( VarLeaf( sym, sym_handle ), VarLeaf( &sym2, sym2_handle ), typ ); } else { n = typ->u.array->dimension; i = 0; for( ;; ) { // accept some C++ { {1},.. } token = CurToken; if( token == T_LEFT_BRACE ) NextToken(); opnd = VarLeaf( sym, sym_handle ); value = CommaExpr(); opnd = ExprNode( opnd, OPR_INDEX, IntLeaf( i ) ); opnd->expr_type = typ2; opnd->op.result_type = typ2; AddStmt( AsgnOp( opnd, T_ASSIGN_LAST, value ) ); if( token == T_LEFT_BRACE ) MustRecog( T_RIGHT_BRACE ); ++i; if( CurToken == T_EOF ) break; if( CurToken == T_RIGHT_BRACE )break; MustRecog( T_COMMA ); if( CurToken == T_RIGHT_BRACE )break; if( i == n ) { CErr1( ERR_TOO_MANY_INITS ); } } if( typ->u.array->unspecified_dim ) { typ->u.array->dimension = i; } else { while( i < n ) { value = IntLeaf( 0 ); opnd = VarLeaf( sym, sym_handle ); opnd = ExprNode( opnd, OPR_INDEX, IntLeaf( i ) ); opnd->expr_type = typ2; opnd->op.result_type = typ2; AddStmt( AsgnOp( opnd, T_ASSIGN_LAST, value ) ); ++i; } } } MustRecog( T_RIGHT_BRACE ); break; case TYPE_FCOMPLEX: case TYPE_DCOMPLEX: case TYPE_LDCOMPLEX: case TYPE_STRUCT: case TYPE_UNION: if( SimpleStruct( typ2 ) ) { unsigned base; unsigned size; NextToken(); // skip over T_LEFT_BRACE n = typ->u.array->dimension; i = 0; base = 0; size = SizeOfArg( typ2 ); for( ;; ) { token = CurToken; if( token == T_LEFT_BRACE ) { NextToken(); } InitStructVar( base, sym, sym_handle, typ2 ); if( token == T_LEFT_BRACE ) { MustRecog( T_RIGHT_BRACE ); } ++i; if( CurToken == T_EOF ) break; if( CurToken == T_RIGHT_BRACE ) break; MustRecog( T_COMMA ); if( CurToken == T_RIGHT_BRACE ) break; if( i == n ) { CErr1( ERR_TOO_MANY_INITS ); } base += size; } if( typ->u.array->unspecified_dim ) { typ->u.array->dimension = i; } else { while( i < n ) { // mop up base += size; InitStructVar( base, sym, sym_handle, typ2 ); ++i; } } NextToken(); // skip over T_RIGHT_BRACE break; } default: AggregateVarDeclEquals( sym, sym_handle ); break; } }
void ComparableModels::WriteConnectingLines(const std::string &LineFilename, const double mismatch) { vgl_point_3d<double> ScannerLocation; World.getScannerLocation(ScannerLocation); vtkSmartPointer<vtkPolyData> polydata = vtkPolyData::New(); vtkSmartPointer<vtkPoints> Points = vtkSmartPointer<vtkPoints>::New(); std::vector<bool> LineType; for(unsigned int i = 0; i < UsedWorldPoints.size(); i++) { vgl_point_3d<double> P0 = World.Points_[UsedWorldPoints[i]].getCoord(); Points->InsertNextPoint(P0.x(), P0.y(), P0.z()); vgl_point_3d<double> P1 = MatchingModelPoints[i].getCoord(); Points->InsertNextPoint(P1.x(), P1.y(), P1.z()); double dist_world = vgl_distance(P0, ScannerLocation); double dist_model = vgl_distance(P1, ScannerLocation); if(dist_world > (dist_model + mismatch)) //bad LineType.push_back(0); //false = bad else LineType.push_back(1); //true = good } polydata->SetPoints(Points); vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New(); unsigned int NumLines = UsedWorldPoints.size(); for(unsigned int i = 0; i < NumLines; i++) { vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New(); line->GetPointIds()->SetId(0,2*i); line->GetPointIds()->SetId(1,2*i + 1); lines->InsertNextCell(line); } polydata->SetLines(lines); //Color lines vtkSmartPointer<vtkUnsignedCharArray> LineColors = vtkSmartPointer<vtkUnsignedCharArray>::New(); LineColors->SetNumberOfComponents(3); LineColors->SetName("LineColors"); vtkSmartPointer<vtkUnsignedIntArray> LineConsistencies = vtkSmartPointer<vtkUnsignedIntArray>::New(); LineConsistencies->SetNumberOfComponents(1); LineConsistencies->SetName("LineConsistencies"); //create empty unsigned char arrays unsigned char r[3]; unsigned char g[3]; //fill the char arrays CharArray(Colors::Red(), r); CharArray(Colors::Green(), g); for(unsigned int i = 0; i < NumLines; i++) { if(LineType[i]) { LineColors->InsertNextTupleValue(g); LineConsistencies->InsertNextValue(1); } else { LineColors->InsertNextTupleValue(r); LineConsistencies->InsertNextValue(0); } } polydata->GetCellData()->AddArray(LineColors); polydata->GetCellData()->AddArray(LineConsistencies); vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); writer->SetFileName(LineFilename.c_str()); writer->SetInput(polydata); writer->Write(); }
template<typename T, Class *Context::*field> value_t internal_allocate(Class *instance_of) { if(!subclass_of(context->*field, instance_of)) { std::string class_name = Type::names[Type::ToTag<T>::value]; CharArray instance_of_str = rescue_inspect(instance_of); raise(context->type_error, "Unable to create instance of " + instance_of_str + " with allocator for class " + CharArray(class_name)); } return new (collector) T(instance_of); }
void WriteAxisFile(const vgl_point_3d<double> &Origin, const vgl_vector_3d<double> &V0, const vgl_vector_3d<double> &V1, const vgl_vector_3d<double> &V2, const std::string &OutputFilename) { unsigned char r[3], g[3], b[3]; CharArray(Colors::Red(), r); CharArray(Colors::Green(), g); CharArray(Colors::Blue(), b); double XaxisPoint[3], YaxisPoint[3], ZaxisPoint[3]; VXLHelpers::GetArray(VXLHelpers::PointAlong(Origin, V0, 1.0), XaxisPoint); VXLHelpers::GetArray(VXLHelpers::PointAlong(Origin, V1, 1.0), YaxisPoint); VXLHelpers::GetArray(VXLHelpers::PointAlong(Origin, V2, 1.0), ZaxisPoint); vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New(); //setup colors vtkSmartPointer<vtkUnsignedCharArray> Colors = vtkSmartPointer<vtkUnsignedCharArray>::New(); Colors->SetNumberOfComponents(3); Colors->SetName("Colors"); Colors->InsertNextTupleValue(r); Colors->InsertNextTupleValue(g); Colors->InsertNextTupleValue(b); double o[3] = {0.0, 0.0, 0.0}; pts->InsertNextPoint(o); pts->InsertNextPoint(XaxisPoint); pts->InsertNextPoint(YaxisPoint); pts->InsertNextPoint(ZaxisPoint); vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New(); //x axis vtkSmartPointer<vtkLine> xaxis = vtkSmartPointer<vtkLine>::New(); xaxis->GetPointIds()->SetId(0,0); xaxis->GetPointIds()->SetId(1,1); lines->InsertNextCell(xaxis); //y axis vtkSmartPointer<vtkLine> yaxis = vtkSmartPointer<vtkLine>::New(); yaxis->GetPointIds()->SetId(0,0); yaxis->GetPointIds()->SetId(1,2); lines->InsertNextCell(yaxis); //z axis vtkSmartPointer<vtkLine> zaxis = vtkSmartPointer<vtkLine>::New(); zaxis->GetPointIds()->SetId(0,0); zaxis->GetPointIds()->SetId(1,3); lines->InsertNextCell(zaxis); vtkSmartPointer<vtkPolyData> pdata = vtkSmartPointer<vtkPolyData>::New(); //add the points to the dataset pdata->SetPoints(pts); //add the lines to the dataset pdata->SetLines(lines); //color the lines pdata->GetCellData()->AddArray(Colors); //write the file vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); writer->SetInput(pdata); writer->SetFileName(OutputFilename.c_str()); writer->Write(); }
CharArray ruby_path_from_null(const char *path) { return ruby_path(CharArray((const char_t *)path, std::strlen(path))); }