コード例 #1
0
void Pretty::visitBinary(JCBinary* that) {
    that->lhs->accept(this);
    addSpace();
    print(treeinfo::descByTag(that->treeTag));
    addSpace();
    that->rhs->accept(this);
}
コード例 #2
0
 vector<string> fullJustify(vector<string> &words, int L) {
     vector<string>res;
     int len = words.size(), i = 0;
     while(i < len)
     {
         int rowlen = 0, j = i;
         while(j < len && rowlen + words[j].size() <= L)
             rowlen += (words[j++].size() + 1);
         if(j - i == 1)
         {
             res.push_back(words[i]);
             addSpace(res.back(), L - words[i].size());
             i = j; continue;
         }
         int charaLen = rowlen - (j - i);
         int meanSpace = j < len ? (L - charaLen) / (j - i - 1) : 1;
         int leftSpace = j < len ? (L - charaLen) % (j - i - 1) : L - charaLen - (j - i -1);
         string tmp;
         for(int k = i; k < j - 1; k++)
         {
             tmp += words[k];
             addSpace(tmp, meanSpace);
             if(j < len && leftSpace > 0)
             {
                 tmp.push_back(' ');
                 leftSpace--;
             }
         }
         tmp += words[j - 1];
         if(leftSpace > 0)addSpace(tmp, leftSpace); 
         res.push_back(tmp);
         i = j;
     }
     return res;
 }
コード例 #3
0
  void DOMElement::dumpInfo(FILE * f, int recursion)
  {
    NodeList nodes = getChildNodes();

    addSpace(f, recursion);
    fprintf(f, "NODE <%s> (%d children, %d deep)",
	    getTagName().c_str(), (int) nodes.size(), recursion);

    std::string str = getTextContent();
    if(str.size() > 0 && str.size() < 100) {
      fprintf(f, " TEXT = \"%s\"", str.c_str());
    }

    fprintf(f, "\n");

    int i = 1;

    fflush(f);

    for(NodeList::iterator it = nodes.begin(); it != nodes.end(); it++) {
      addSpace(f, recursion);
      fprintf(f, "Child %d/%d\n", i, (int) nodes.size());
      (*it).dumpInfo(f, recursion + 1);
      i++;
    }
  }
コード例 #4
0
void Pretty::visitMethodDef(JCMethodDecl* that) {
    if (that->mods != nullptr) {
        that->mods->accept(this);
    }

    that->resType->accept(this);
    addSpace();
    print(that->name.desc);
    addSpace();

    printTreeList(that->params, ",", "(", ") ");
    that->body->accept(this);
}
コード例 #5
0
void Pretty::printModifiers(JCModifiers* modifier) {
    long long flags = modifier->flags;
    if ((flags & Flags::PUBLIC) != 0) {
        print("public");
        addSpace();
    }
    if ((flags & Flags::PRIVATE) != 0) {
        print("private");
        addSpace();
    }
    if ((flags & Flags::STATIC) != 0) {
        print("static");
        addSpace();
    }
}
コード例 #6
0
ファイル: kernel_sum.hpp プロジェクト: michaelkook/kqp
        virtual void load(const pugi::xml_node &node) {
            static const std::string SUB_NAME("sub");

            m_sum = 0;
            m_spaces.clear();
            m_weights.clear();

            for(auto child: node) {
                if (child.type() == pugi::xml_node_type::node_element && child.name() == SUB_NAME) {
                    Real weight = kqp::attribute<Real>(child, "weight", 1.);

                    pugi::xml_node selected;
                    for(auto grandchild: child) {
                        if (grandchild.type() == pugi::xml_node_type::node_element) {
                            if (selected.empty()) {
                                selected = grandchild;
                            } else { 
                                KQP_THROW_EXCEPTION(exception, "A unary kernel element should have no more than one child"); 
                            }
                        }
                    }
                    if (selected.empty())
                        KQP_THROW_EXCEPTION(exception, "A unary kernel element should have one child");

                    auto space = kqp::our_dynamic_cast< SpaceBase<Scalar> >(SpaceFactory::load(selected));

                    addSpace(weight, space);
                }
            }
        }
コード例 #7
0
void Pretty::visitReturn(JCReturn* that) {
    print("return");
    if (that->expr != nullptr) {
        addSpace();
        that->expr->accept(this);
    }
}
コード例 #8
0
void Pretty::visitVarDef(JCVariableDecl* that) {
    that->vartype->accept(this);
    addSpace();
    print(that->name.desc);
    if (that->init != nullptr) {
        print(" = ");
        that->init->accept(this);
    }
}
コード例 #9
0
ファイル: ODESimulator.cpp プロジェクト: sub77/hobbycode
	Space* ODESimulator::createSpace()
	{
		ODESpace * newSpace = new ODESpace();

		// Add this new Space as a child of the Simulator's root Space.
		dSpaceAdd(mRootSpaceID, (dGeomID) newSpace->internal_getSpaceID());

		addSpace(newSpace);
		return newSpace;
	}
コード例 #10
0
 vector<string> fullJustify(vector<string> &words, int L) {
     // IMPORTANT: Please reset any member data you declared, as
     // the same Solution instance will be reused for each test case.
     vector<string>res;
     int len = words.size();
     for(int i=0;i < len;)
     {
         //if(words[i].size() == 0){i++; continue;}
         int rowlen = 0, j;
         for(j = i;j < len && rowlen + words[j].size() <= L;)
             rowlen += (words[j++].size() + 1);
         //j-i是该行放入单词的数目
         if(j - i == 1)
         {//处理放入一个单词的特殊情况
             res.push_back(words[i]);
             addSpace(res.back(), L - words[i].size());
             i = j; continue;
         }
         //charaLen是当前行字母总长度
         int charaLen = rowlen - (j - i);
         //平均每个单词后的空格,j < len 表示不是最后一行
         int meanSpace = j < len ? (L - charaLen) / (j - i - 1) : 1;
         //多余的空格
         int leftSpace = j < len ? (L - charaLen) % (j - i - 1) : L - charaLen - (j - i -1);
         string tmp;
         for(int k = i; k < j - 1; k++)
         {
             tmp += words[k];
             addSpace(tmp, meanSpace);
             if(j < len && leftSpace > 0)
             {
                 tmp.push_back(' ');
                 leftSpace--;
             }
         }
         tmp += words[j - 1];//放入最后一个单词
         if(leftSpace > 0)addSpace(tmp, leftSpace); //对最后一行
         res.push_back(tmp);
         i = j;
     }
     return res;
 }
コード例 #11
0
void Pretty::printTreeList(vector<T>& list, string split, string wLeft, string wRight) {
    print(wLeft);
    bool isFirst = true;
    for (auto& item : list) {
        if (!isFirst) {
            print(split);
            addSpace();
        } else {
            isFirst = false;
        }
        item->accept(this);
    }
    print(wRight);
}
コード例 #12
0
ファイル: sevensegment.cpp プロジェクト: asta1992/CPlusPlus
std::string getOutputString(std::string numberString) {
	std::string lineString { };

	if (numberString.size() && numberString.front() == '-')
		numberString.front() = digitOffset + 10;

	addSpace(numberString);

	for (unsigned int i = 0; i < allDigits[0].size(); i++) {
		for (char c : numberString) {
			lineString += allDigits[c - digitOffset][i] + " ";
		}
		lineString += "\n";
	}
	return lineString;
}
コード例 #13
0
ファイル: mgTextScan.cpp プロジェクト: duaneking/SeaOfMemes
//-----------------------------------------------------------------
// format the textbox contents. 
void mgTextScan::scan(
  unsigned int &posn)            // starting position
{
  // parse buffer and format text
  m_clipped = false;  

  // set state to default
  m_page->getDefaultFormat(m_justify, m_leftMargin, m_rightMargin, m_indent, m_wrap);
  m_page->getDefaultFont(m_fontFace, m_fontSize, m_fontItalic, m_fontBold, m_color);
  m_baseFontSize = m_fontSize;
  newFont();

  // temporaries for when we return values to defaults
  mgString face;
  short left, right, indent, size;
  BOOL wrap, italic, bold;
  DWORD color;
  mgTextAlign justify;

  unsigned int count = 0;
  BOOL endBuffer = false;
  while (!m_clipped && !endBuffer)
  {
    mgFormatCmd cmd = m_buffer->readCommand(posn);
    switch (cmd)
    {
      case mgJustifyCmd: 
      {
        m_justify = m_buffer->readJustify(posn);
        if (m_justify == mgTextAlignHDefault)
          m_page->getDefaultFormat(m_justify, left, right, indent, wrap);
        break;
      }
        
      case mgLeftMarginCmd: 
      {
        short value = m_buffer->readLeftMargin(posn);
        if (value == MGDEFAULTSHORT)
          m_page->getDefaultFormat(justify, m_leftMargin, right, indent, wrap);
        else m_leftMargin = (m_page->getUnits()*value)/100;
        newMargins();
        break;
      }

      case mgRightMarginCmd: 
      {
        short value = m_buffer->readRightMargin(posn);
        if (value == MGDEFAULTSHORT)
          m_page->getDefaultFormat(justify, left, m_rightMargin, indent, wrap);
        else m_rightMargin = (m_page->getUnits()*value)/100;
        newMargins();
        break;
      }

      case mgIndentCmd:
      {
        short value = m_buffer->readIndent(posn);
        if (value == MGDEFAULTSHORT)
          m_page->getDefaultFormat(justify, left, right, m_indent, wrap);
        else m_indent = (m_page->getUnits() * value)/100;
        newMargins();
        break;
      }

      case mgWrapCmd: 
      {
        mgBooleanAttr value = m_buffer->readWrap(posn);
        if (value == mgDefaultBoolean)
          m_page->getDefaultFormat(justify, left, right, indent, m_wrap);
        else m_wrap = value == mgTrue;
        break;
      }

      case mgFontFaceCmd: 
        m_buffer->readFontFace(posn, m_fontFace);
        if (m_fontFace.equals("default"))
          m_page->getDefaultFont(m_fontFace, size, italic, bold, color);
        newFont();
        break;
  
      case mgFontSizeCmd: 
      {
        short value = m_buffer->readFontSize(posn);
        if (value == MGDEFAULTSHORT)
          m_page->getDefaultFont(face, m_fontSize, italic, bold, color);
        else m_fontSize = (m_baseFontSize * value)/100;
        newFont();
        break;
      }
  
      case mgFontItalicCmd: 
      {
        mgBooleanAttr value = m_buffer->readFontItalic(posn);
        if (value == mgDefaultBoolean)
          m_page->getDefaultFont(face, size, m_fontItalic, bold, color);
        else m_fontItalic = value == mgTrue;
        newFont();
        break;
      }
  
      case mgFontBoldCmd: 
      {
        mgBooleanAttr value = m_buffer->readFontBold(posn);
        if (value == mgDefaultBoolean)
          m_page->getDefaultFont(face, size, italic, m_fontBold, color);
        else m_fontBold = value == mgTrue;
        newFont();
        break;
      }
  
      case mgColorCmd:
        m_color = m_buffer->readColor(posn);
        if (m_color == MGDEFAULTCOLOR)
          m_page->getDefaultFont(face, size, italic, bold, m_color);
        break;
        
      case mgAnchorCmd:
//        m_anchor = (mgAnchorDesc*) m_buffer->readPtr(posn);
        break;
          
      case mgSpaceCmd: 
        newWord();
        addSpace(m_buffer->readSpace(posn));
        break;

      case mgTabCmd: 
      {
        newWord();
        short value = m_buffer->readTab(posn);
        value = (m_page->getUnits() * value)/100;
        addTab(value);
        break;
      }

      case mgTextCmd:
      {
        int textLen;
        const char* text;
        m_buffer->readText(posn, textLen, text);

        if (!m_wrap)
          addFrag(false, text, textLen);
        else
        {
          // writeText has converted whitespace to blanks and removed
          // duplicate blanks.  However, a single word may be broken into 
          // multiple fragments due to tags within the word.
          // ex: <b>T</b>est
          while (textLen > 0)
          {
            int c = 0xFF & text[0];
            BOOL isBlank = isspace(c) != 0;
            if (isBlank)
            {
              newWord();
              text++;
              textLen--;
            }
            // count characters of next word
            int len = 0;
            while (len < textLen)
            {
              c = 0xFF & text[len];
              if (!isspace(c))
                len++;
              else break;
            }

            addFrag(isBlank, text, len);

            text += len;
            textLen -= len;
          }
        }
        break;
      }

      case mgChildCmd:
      {
        // read child info 
        const void* child;
        mgTextAlign halign;
        mgTextAlign valign;
        m_buffer->readChild(posn, child, halign, valign);

        newWord();  // breaks the current word
        addChild(child, halign, valign);
        break;
      } 

      case mgBreakCmd: 
      {
        int height = m_buffer->readBreak(posn);
        newWord();  // breaks the current word
        newLine(height);
        break;
      }

      case mgClearCmd: 
      {
        mgTextAlign clear = m_buffer->readClear(posn);
        clearMargins(clear);
        break;
      }

      case mgTargetCmd:
        addTarget((int*) m_buffer->readTarget(posn));
        break;

      case mgDoneCmd:
        newWord();  // breaks the current word
        done();   // end of input
        endBuffer = true;
        break;
    } 
  } 
}
コード例 #14
0
ファイル: toolbar.cpp プロジェクト: admiral0/Antico-Deluxe
AmeToolBar::AmeToolBar(QWidget *parent)
	: QToolBar(parent)
{
        setMovable(false);
        addSpace(10);
}
コード例 #15
0
ファイル: i2of5.cpp プロジェクト: gpazo/xtuple-svn
void renderI2of5(OROPage * page, const QRectF &r, const QString & _str, ORBarcodeData * bc)
{
  QString str = _str;
  qreal narrow_bar = bc->narrowBarWidth;
  qreal bar_width_mult = 2.5; // the wide bar width multiple of the narrow bar
  qreal wide_bar = narrow_bar * bar_width_mult;

  if(str.length() % 2)
  {
    str = "0" + str; // padding zero if number of characters is not even
  }

  // this is our mandatory minimum quiet zone
  qreal quiet_zone = narrow_bar * 10;
  if(quiet_zone < 0.1)
    quiet_zone = 0.1;

  // what kind of area do we have to work with
  qreal draw_width = r.width();

  // how long is the value we need to encode?
  int val_length = str.length();

  // L = (C(2N+3)+6+N)X
  // L length of barcode (excluding quite zone
  // C the number of characters in the value excluding the start/stop
  // N the bar width multiple for wide bars
  // X the width of a bar (pixels in our case)
  qreal L;
  qreal C = val_length;
  qreal N = bar_width_mult;
  qreal X = narrow_bar;

  L = (C * (2.0*N + 3.0) + 6.0 + N) * X;

  // now we have the actual width the barcode will be so can determine the actual
  // size of the quiet zone (we assume we center the barcode in the given area)
  // At the moment the way the code is written is we will always start at the minimum
  // required quiet zone if we don't have enough space.... I guess we'll just have over-run
  // to the right
  //
  // calculate the starting position based on the alignment option
  if(bc->align == 1) // center
  {
    qreal nqz = (draw_width - L) / 2.0;
    if(nqz > quiet_zone)
      quiet_zone = nqz;
  }
  else if(bc->align > 1) // right
    quiet_zone = draw_width - (L + quiet_zone);
  //else if(align < 1) {} // left : do nothing

  QPointF pos(r.left() + quiet_zone, r.top());

  // start character
  pos = addBar(page, r, pos, bc, narrow_bar);
  pos = addSpace(page, r, pos, bc, narrow_bar);
  pos = addBar(page, r, pos, bc, narrow_bar);
  pos = addSpace(page, r, pos, bc, narrow_bar);

  for(int i = 0; i < str.length()-1; i+=2)
  {
    for(int iElt = 0; _i2of5charmap [0][iElt] != '\0'; iElt++)
    {
      for(int offset=0; offset<=1; offset++)
      {
        QChar c = str.at(i+offset);
        if(!c.isDigit()) {
          break; // invalid character
        }
        int iChar = c.digitValue();
        qreal width = _i2of5charmap[iChar][iElt] == 'W' ? wide_bar : narrow_bar;
        pos = addElement(page, r, pos, bc, width, offset==1);
      }
    }
  }

  // stop character
  pos = addBar(page, r, pos, bc, wide_bar);
  pos = addSpace(page, r, pos, bc, narrow_bar);
  pos = addBar(page, r, pos, bc, narrow_bar);


  return;
}