Пример #1
0
 // object propery access.
 inline bool  set_prop(HVM vm, value obj, value key, value value) { return ni()->set_prop(vm,obj,key,value); }
Пример #2
0
 // object creation, of_class == 0 - "Object"
 inline value  create_object(HVM vm, value of_class = 0) { return ni()->create_object(vm, of_class); }
Пример #3
0
 inline value  create_object(HVM vm, const char* class_path )
 {
     value cls = value_by_path(vm, class_path); assert( is_class(vm,cls) );
     return ni()->create_object(vm, cls);
 }
Пример #4
0
 // path here is a global "path" of the object, something like: "one", "one.two", etc.
 inline value        value_by_path(HVM vm, const char* path) { value r = v_undefined(); ni()->get_value_by_path(vm, &r, path); return r; }
Пример #5
0
 inline value        value_by_path(const char* path) { HVM vm = get_current_vm(); assert(vm); value r = v_undefined(); ni()->get_value_by_path(vm, &r, path); return r; }
Пример #6
0
 inline value        v_bytes(HVM vm, const unsigned char* data, unsigned datalen) { return ni()->bytes_value(vm,data,datalen); }
Пример #7
0
 // convert value to string represenatation.
 inline std::ustring to_string(HVM vm,value v) { return c_string(ni()->to_string(vm,v)); }
Пример #8
0
CDoc* PApp::OpenWindow(const entry_ref& doc, bool show)
{
	try
	{
		BNode n(&doc);
		char mime[256];

		BNodeInfo ni(&n);
		if (ni.GetType(mime) != B_OK)
			mime[0] = 0;

		if (gPrefs->GetPrefInt(prf_I_AutodetectProjects, 1)) {
			if (!strcmp(doc.name, "Jamfile"))
				ni.SetType("text/x-jamfile");
			else if (!strcasecmp(doc.name, "Makefile"))
				ni.SetType("text/x-makefile");
			ni.GetType(mime);
		}

		if (strcmp(mime, "text/x-vnd.Hekkel-Pe-Group") == 0 ||
			strcmp(mime, "text/x-pe-group") == 0)
		{
			PGroupWindow *w = dynamic_cast<PGroupWindow*>(CDoc::FindDoc(doc));
			if (w)
			{
				if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1))
					w->SetWorkspaces(1 << current_workspace());
				if (show)
					w->Activate(true);
				return CDoc::FindDoc(doc);
			}
			else
				return new PGroupWindow(&doc);
		}
		else if (ProjectRoster->IsProjectType(mime))
		{
			BWindow *w = dynamic_cast<BWindow*>(CDoc::FindDoc(doc));
			if (w)
			{
				if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1))
					w->SetWorkspaces(1 << current_workspace());
				if (show)
					w->Activate(true);
				return CDoc::FindDoc(doc);
			}
			else
			{
				PProjectWindow* prjWin = PProjectWindow::Create(&doc, mime);
				if (prjWin && prjWin->InitCheck() == B_OK)
				{
					prjWin->Show();
					return prjWin;
				}
				else
				{
					delete prjWin;
					return gApp->NewWindow(&doc);
				}
			}
		}
		else
		{
			PDoc *d = dynamic_cast<PDoc*>(CDoc::FindDoc(doc));
			if (d)
			{
				if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1))
					d->SetWorkspaces(1 << current_workspace());
				if (show)
					d->Activate(true);
				return CDoc::FindDoc(doc);
			}
			else
				return NewWindow(&doc, show);
		}
	}
	catch (HErr& e)
	{
		e.DoError();
	}

	return NULL;
} /* PApp::OpenWindow */
Пример #9
0
pbool PScene::unpack(const PXmlElement* xmlElement)
{
    // Sanity check
    if (pstrcmp(xmlElement->name(), "scene") != 0)
    {
        PLOG_ERROR("It is not a scene element");
        return false;
    }

    // Delete all scene nodes
    PDELETE(m_root);

    PResourceManager *resourceManager = context()->module<PResourceManager>("resource-manager");

    // Delete all effects
    PList<PAbstractEffect *>::iterator it = m_effects.begin();
    PList<PAbstractEffect *>::iterator ie = m_effects.end();
    while (it != ie)
    {
        PAbstractEffect *effect = *it;
        effect->m_scene = P_NULL;
        PDELETE(effect);
        ++it;
    }

    // Recursively unpack its children
    PXmlElement childElement = xmlElement->firstChild();
    while (childElement.isValid())
    {
        if (pstrcmp(childElement.name(), "root") == 0)
        {
            const pchar *rootNameValue = childElement.attribute("name");
            PASSERT(rootNameValue != P_NULL);
            m_root = PNEW(PRootNode(rootNameValue, this));
            if (!m_root->unpack(&childElement))
            {
                return false;
            }
        }
        else if (pstrcmp(childElement.name(), "effect") == 0)
        {
            PAbstractEffect *effect = s_effectFactory.unpack(&childElement, this);
            if (effect == P_NULL)
            {
                return false;
            }
        }
        else if (pstrcmp(childElement.name(), "texture") == 0)
        {
            const pchar *textureId = childElement.attribute("id");
            if (textureId != P_NULL)
            {
                PTexture *texture = resourceManager->getTexture(textureId);
                if (texture == P_NULL)
                {
                    PLOG_ERROR("Failed to find texture %s.", textureId);
                }
                else
                {
                    const pchar *wrapValue = childElement.attribute("wrap");
                    if (wrapValue != P_NULL)
                    {
                        if (pstrcmp(wrapValue, "repeat") == 0)
                        {
                            texture->setRepeatWrappingEnabled(true, true);
                        }
                    }
                    
                    const pchar *mipmapValue = childElement.attribute("mipmap");
                    if (mipmapValue != P_NULL)
                    {
                        if (pstrcmp(mipmapValue, "true") == 0)
                        {
                            // TODO:
                            PASSERT_NOTIMPLEMENTED();
                        }
                    }
                }
            }
            else
            {
                PLOG_ERROR("Failed to find the id of the texture is missing.");
            }
        }
        else
        {
            PLOG_WARNING("Unknown element node (%s) in scene.", childElement.name());
        }

        childElement = childElement.nextSibling();
    } 

    // Find the main camera.
    const pchar *mainCameraValue = xmlElement->attribute("maincamera");
    m_mainCamera = P_NULL;
    if (mainCameraValue == P_NULL)
    {
        // When the main camera is not specified, use the first camera in the 
        // scene nodes as the main camera.
        PNode::iterator ni(m_root);
        
        PNode *node = *(++ni); // Skip the root
        while (node != P_NULL)
        {
            PCamera *camera = dynamic_cast<PCamera *>(node);
            if (camera != P_NULL)
            {
                m_mainCamera = camera;
                break;
            }
            node = *(++ni);
        }

        if (m_mainCamera == P_NULL)
        {
            PLOG_WARNING("No camera is found. The scene may not be rendered properly.");
        }
    }
    else
    {
        PNode::iterator ni(m_root);
        
        PNode *node = *(++ni); // Skip the root
        while (node != P_NULL)
        {
            if (node->name() == mainCameraValue)
            {
                PCamera *camera = dynamic_cast<PCamera *>(node);
                if (camera != P_NULL)
                {
                    m_mainCamera = camera;
                    break;
                }
            }
            node = *(++ni);
        }
        
        if (m_mainCamera == P_NULL)
        {
            PLOG_WARNING("There is no such camera called %s in the scene.");
        }
    }

    return true;
}
Пример #10
0
 const_iterator end() const
 {
     node_pointer ni(m_roots.get(), m_roots->end());
     return const_iterator(ni);
 }
Пример #11
0
/*
 *************************************************************************
 *
 * computeFillBoxesAndNeighborhoodSets
 *
 *************************************************************************
 */
void
PatchLevelBorderFillPattern::computeFillBoxesAndNeighborhoodSets(
   boost::shared_ptr<hier::BoxLevel>& fill_box_level,
   boost::shared_ptr<hier::Connector>& dst_to_fill,
   const hier::BoxLevel& dst_box_level,
   const hier::IntVector& fill_ghost_width,
   bool data_on_patch_border)
{
   TBOX_ASSERT_OBJDIM_EQUALITY2(dst_box_level, fill_ghost_width);

   fill_box_level.reset(new hier::BoxLevel(
         dst_box_level.getRefinementRatio(),
         dst_box_level.getGridGeometry(),
         dst_box_level.getMPI()));

   dst_to_fill.reset(new hier::Connector(dst_box_level,
         *fill_box_level,
         fill_ghost_width));

   const hier::BoxContainer& dst_boxes = dst_box_level.getBoxes();

   const int dst_level_num = dst_box_level.getGridGeometry()->
      getEquivalentLevelNumber(dst_box_level.getRefinementRatio());

   hier::IntVector dst_to_dst_width(fill_ghost_width);
   if (data_on_patch_border) {
      dst_to_dst_width += hier::IntVector::getOne(fill_ghost_width.getDim());
   }

   const hier::Connector& dst_to_dst =
      dst_box_level.findConnector(dst_box_level,
         dst_to_dst_width,
         hier::CONNECTOR_IMPLICIT_CREATION_RULE,
         true);

   /*
    * To get the level border, grow each patch box and remove
    * the level from it.
    */
   hier::LocalId last_id = dst_box_level.getLastLocalId();
   for (hier::RealBoxConstIterator ni(dst_boxes.realBegin());
        ni != dst_boxes.realEnd(); ++ni) {
      const hier::Box& dst_box = *ni;
      hier::BoxContainer fill_boxes(
         hier::Box::grow(dst_box, fill_ghost_width));
      hier::Connector::ConstNeighborhoodIterator nabrs =
         dst_to_dst.find(dst_box.getBoxId());
      for (hier::Connector::ConstNeighborIterator na = dst_to_dst.begin(nabrs);
           na != dst_to_dst.end(nabrs); ++na) {
         if (dst_box.getBlockId() == na->getBlockId()) {
            fill_boxes.removeIntersections(*na);
         } else {
            boost::shared_ptr<const hier::BaseGridGeometry> grid_geometry(
               dst_box_level.getGridGeometry());

            const hier::BlockId& dst_block_id = dst_box.getBlockId();
            const hier::BlockId& nbr_block_id = na->getBlockId();

            TBOX_ASSERT(grid_geometry->areNeighbors(dst_block_id,
                  nbr_block_id));

            hier::Transformation::RotationIdentifier rotation =
               grid_geometry->getRotationIdentifier(dst_block_id,
                  nbr_block_id);
            hier::IntVector offset(
               grid_geometry->getOffset(dst_block_id, nbr_block_id, dst_level_num));

            hier::Transformation transformation(rotation, offset,
                                                nbr_block_id, dst_block_id);

            hier::Box nbr_box(*na);
            transformation.transform(nbr_box);

            fill_boxes.removeIntersections(nbr_box);
         }
      }

      if (!fill_boxes.empty()) {
         d_max_fill_boxes = tbox::MathUtilities<int>::Max(d_max_fill_boxes,
               fill_boxes.size());
         hier::Connector::NeighborhoodIterator base_box_itr =
            dst_to_fill->makeEmptyLocalNeighborhood(dst_box.getBoxId());
         for (hier::BoxContainer::iterator li = fill_boxes.begin();
              li != fill_boxes.end(); ++li) {
            hier::Box fill_box(*li,
                               ++last_id,
                               dst_box.getOwnerRank());
            TBOX_ASSERT(fill_box.getBlockId() == dst_box.getBlockId());
            fill_box_level->addBoxWithoutUpdate(fill_box);
            dst_to_fill->insertLocalNeighbor(fill_box, base_box_itr);
         }
      }
   }
   fill_box_level->finalize();
}
Пример #12
0
 const_iterator begin() const
 {
     node_pointer ni(m_roots.get(), m_roots->begin());
     return const_iterator(ni);
 }
Пример #13
0
 iterator end()
 {
     node_pointer ni(m_roots.get(), m_roots->end());
     return iterator(ni);
 }
Пример #14
0
Файл: rda.cpp Проект: igstan/rtc
void RDAfact::debug_dump(FILE * outf, bool brief)
{
  if(is_bot){
    fprintf(outf, "bot\n");
  } else if(brief){
    int numaos = 0; 
    int numnodes = 0;
    int numrets = 0;
    int numargs = 0;
    for(LocAidNode * np = this->head; np; np = np->next){
      numaos++;
      numnodes += np->nodes.Length();
      numrets += np->rets.Length();
      numargs += np->args.Length();
    }
    fprintf(outf, "%d aos, %d nodes, %d rets, %d args\n",
		numaos, numnodes, numrets, numargs);
  } else {
    LocAidNode * np;
    fprintf(outf, "\n");
    for(np = this->head; np; np = np->next){
      fprintf(outf, "\t[ ");
      np->getAO().write_string_rep(outf, true);
      fprintf(outf, ":");
      suco_iterator<PgmExpr *> ni(np->nodes);
      while(ni.Iterate()){
        switch(ni.Current()->getKind()){
/*
          case PgmExpr::fCall: {
              AID& aid = ((PExprCall *)ni.Current())->getAid();
              fprintf(outf, " call<%d,%d>", aid.filestem_id, aid.aid);
            } break;
*/
          case PgmExpr::fAssign: {
              AID& aid = ((PExprAssign *)ni.Current())->getAid();
              fprintf(outf, " assign<%d,%d>", aid.filestem_id, aid.aid);
            } break;
          case PgmExpr::fVerify: {
              PExprVerify& pv = *(PExprVerify *)ni.Current();
              AID& aid = pv.getAid();
              fprintf(outf, " verify%s%s<%d,%d>",
			pv.getVtKindString(), pv.getVpKindString(),
			aid.filestem_id, aid.aid);
            } break;
          case PgmExpr::fDecl: {
              fprintf(outf, " decl(");
              ((PExprDecl *)ni.Current())->getAO().write_string_rep(outf, true);
              fprintf(outf, ")");
            } break;
          default:
            fprintf(outf, "Invalid PgmExpr recorded in RDAfact:\n");
            ni.Current()->debug_dump(outf, 2);
        }
      }
      suco_iterator<PExprArg *> ai(np->args);
      while(ai.Iterate()){
        AID& aid = ((PExprArg *)ai.Current())->getAid();
        fprintf(outf, " arg<%d,%d>", aid.filestem_id, aid.aid);
      }
      suco_iterator<PgmStmt *> ri(np->rets);
      while(ri.Iterate()){
        AID& aid = ((PgmStmt *)ri.Current())->getAid();
        fprintf(outf, " ret<%d,%d>", aid.filestem_id, aid.aid);
      }
      fprintf(outf, " ]\n");
    }
  }
}
Пример #15
0
status_t
TerminalThemesAddon::ApplyThemeR5(BMessage &theme, uint32 flags)
{
	BMessage termpref;
	status_t err;
	struct termprefs tp;
	
	err = MyMessage(theme, termpref);
	if (err)
		return err;
	tp.magic = TP_MAGIC;
	tp.version = TP_VERSION;
	tp.x = 0; // don't open at specific coords
	tp.y = 0;
	if (termpref.FindInt32(TP_COLS, (int32 *)&tp.p.cols) != B_OK)
		tp.p.cols = 80;
	if (termpref.FindInt32(TP_ROWS, (int32 *)&tp.p.rows) != B_OK)
		tp.p.rows = 25;
	if (termpref.FindInt32(TP_TABWIDTH, (int32 *)&tp.p.tab_width) != B_OK)
		tp.p.tab_width = 8;
	BFont tFont;
	tp.p.font_size = 12;
	strcpy(tp.p.font, "Courier10 BT/Roman");
	if (FindFont(termpref, TP_FONT, 0, &tFont) == B_OK) {
		font_family ff;
		font_style fs;
		tFont.GetFamilyAndStyle(&ff, &fs);
		strcpy(tp.p.font, ff);
		strcat(tp.p.font, "/");
		strcat(tp.p.font, fs);
		tp.p.font_size = (uint32)tFont.Size();
	}
	tp.p.cursor_blink_rate = 1000000;
	tp.p.refresh_rate = 0;
	
	if (FindRGBColor(termpref, TP_BG, 0, &tp.p.bg) != B_OK)
		tp.p.bg = make_color(255,255,255,255);
	if (FindRGBColor(termpref, TP_FG, 0, &tp.p.fg) != B_OK)
		tp.p.fg = make_color(0,0,0,255);
	if (FindRGBColor(termpref, TP_CURBG, 0, &tp.p.curbg) != B_OK)
		tp.p.curbg = make_color(255,255,255,255);
	if (FindRGBColor(termpref, TP_CURFG, 0, &tp.p.curfg) != B_OK)
		tp.p.curfg = make_color(0,0,0,255);
	if (FindRGBColor(termpref, TP_SELBG, 0, &tp.p.selbg) != B_OK)
		tp.p.selbg = make_color(0,0,0,255);
	if (FindRGBColor(termpref, TP_SELFG, 0, &tp.p.selfg) != B_OK)
		tp.p.selfg = make_color(255,255,255,255);
	
	if (termpref.FindInt32(TP_ENCODING, (int32 *)&tp.p.encoding) != B_OK)
		tp.p.encoding = 0; // UTF-8
	
	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) {
		BPath pTermPref;
		if (find_directory(B_USER_SETTINGS_DIRECTORY, &pTermPref) < B_OK)
			return EINVAL;
		pTermPref.Append("Terminal");
		BFile fTermPref(pTermPref.Path(), B_WRITE_ONLY|B_CREATE_FILE|B_ERASE_FILE);
		if (fTermPref.InitCheck() != B_OK) {
			return fTermPref.InitCheck();
		}
		fTermPref.Write(&tp, sizeof(struct termprefs));
		BNodeInfo ni(&fTermPref);
		if (ni.InitCheck() == B_OK)
			ni.SetType("application/x-vnd.Be-pref");
	}

	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) {
		BList teamList;
		app_info ainfo;
		int32 count, i;
		be_roster->GetAppList(&teamList);
		count = teamList.CountItems();
		for (i = 0; i < count; i++) {
			if (be_roster->GetRunningAppInfo((team_id)(teamList.ItemAt(i)), &ainfo) == B_OK) {
				if (!strcmp(ainfo.signature, kBeOSTerminalAppSig)) {
					err = B_OK;
					BMessage msg(MSG_R5_SET_PREF);
					BMessenger msgr(NULL, ainfo.team);
					tp.x = 0;
					tp.y = 0;
					
					//msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref));
					msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs));
					msg.AddSpecifier("Window", 0L);
					err = msgr.SendMessage(&msg);
				}
			}
		}
	}
	
	return B_OK;
}
Пример #16
0
void BoxLevelStatistics::computeLocalBoxLevelStatistics(const BoxLevel& box_level)
{
   box_level.cacheGlobalReducedData();

   /*
    * Compute per-processor statistics.  Some quantities are readily
    * available while others are computed in the loop following.
    *
    * Aspect ratio uses a generalized formula that goes to 1 when box
    * has same length on all sides (regardless of dimension),
    * degenerates to the rectangular aspect ratio in 2D, and grows
    * appropriately for dimensions higher than 2.
    */

   d_sq.d_values[HAS_ANY_BOX] = (box_level.getLocalNumberOfBoxes() > 0);
   d_sq.d_values[NUMBER_OF_CELLS] =
      static_cast<double>(box_level.getLocalNumberOfCells());
   d_sq.d_values[NUMBER_OF_BOXES] =
      static_cast<double>(box_level.getLocalNumberOfBoxes());
   d_sq.d_values[MAX_BOX_VOL] = 0;
   d_sq.d_values[MIN_BOX_VOL] = tbox::MathUtilities<double>::getMax();
   d_sq.d_values[MAX_BOX_LEN] = 0;
   d_sq.d_values[MIN_BOX_LEN] = tbox::MathUtilities<double>::getMax();
   d_sq.d_values[MAX_ASPECT_RATIO] = 0;
   d_sq.d_values[SUM_ASPECT_RATIO] = 0;
   d_sq.d_values[SUM_SURFACE_AREA] = 0.;
   d_sq.d_values[SUM_NORM_SURFACE_AREA] = 0.;

   const BoxContainer& boxes = box_level.getBoxes();

   for (RealBoxConstIterator ni(boxes.realBegin());
        ni != boxes.realEnd(); ++ni) {

      const Box& box = *ni;
      const IntVector boxdims = box.numberCells();
      const double boxvol = static_cast<double>(boxdims.getProduct());
      const int longdim = boxdims.max();
      const int shortdim = boxdims.min();
      double aspect_ratio = 0.0;
      double surfarea = 0.;
      for (int d = 0; d < d_dim.getValue(); ++d) {
         surfarea += 2 * double(boxvol) / boxdims(d);
         double tmp = static_cast<double>(boxdims(d)) / shortdim - 1.0;
         aspect_ratio += tmp * tmp;
      }
      aspect_ratio = 1.0 + sqrt(aspect_ratio);

      d_sq.d_values[MAX_BOX_VOL] =
         tbox::MathUtilities<double>::Max(d_sq.d_values[MAX_BOX_VOL],
            boxvol);
      d_sq.d_values[MIN_BOX_VOL] =
         tbox::MathUtilities<double>::Min(d_sq.d_values[MIN_BOX_VOL],
            boxvol);

      d_sq.d_values[MAX_BOX_LEN] =
         tbox::MathUtilities<double>::Max(d_sq.d_values[MAX_BOX_LEN],
            longdim);
      d_sq.d_values[MIN_BOX_LEN] =
         tbox::MathUtilities<double>::Min(d_sq.d_values[MIN_BOX_LEN],
            shortdim);

      d_sq.d_values[MAX_ASPECT_RATIO] =
         tbox::MathUtilities<double>::Max(d_sq.d_values[MAX_ASPECT_RATIO],
            aspect_ratio);

      d_sq.d_values[SUM_ASPECT_RATIO] += aspect_ratio;
      d_sq.d_values[SUM_SURFACE_AREA] += surfarea;

   }

   /*
    * Smallest surface area possible for the number of cells perfectly
    * distributed in d_mpi.
    */
   const double ideal_surfarea =
      2 * d_dim.getValue()
      * pow(double(box_level.getGlobalNumberOfCells()) / d_mpi.getSize(),
         double(d_dim.getValue() - 1) / d_dim.getValue());

   d_sq.d_values[SUM_NORM_SURFACE_AREA] =
      d_sq.d_values[SUM_SURFACE_AREA] / ideal_surfarea;

}