int
main(void)
{
	StringStack	stack;

	//用初始化构造函数构造一个字符串常量数组
	MyString	my[] = {
		MyString("hello"), 
		MyString("programmer"), 
		MyString("It`s a nice day"), 
		MyString("keep do it"), 
		MyString("Never give up") 
	};

	//字符串常量指针入栈,注意存的是指针,所以采用取地址操作
	for (int i = 0; i < sizeof my / sizeof *my; i++) {
		stack.push(&my[i]);
	}

	//返回的是一个常量对象指正,故只有常量成员函数才能调用
	const MyString* cm;
	for (int i = 0; i < sizeof my / sizeof *my; i++) {
		//注意此处cm是指针,直接进行赋值即可不需要进行取地址操作
		cm = stack.pop();
		cm->print();
	}

	return 0;
}
Example #2
0
inline void _ctp_end_brackets(POSTFIX &postfix, StringStack &oper_stack)
{
	while(oper_stack.getSize())
	{
		if(oper_stack.get_last()=="("){
			oper_stack.remove();
			break;
		}
		
		String s;
		
		s=oper_stack.get_last();
		oper_stack.remove();
		
		if(isalpha(s[0])) {
			//don't worry: this seems allright!!!
			String name;
			name="'";
			name+=s;
			postfix.add(name);
		}else{
			postfix.add(s);
		}
		
			
			
				
	}
}
Example #3
0
void reverse_stack(StringStack &from, StringStack &to){
	while(from.get_top_position()){
		
		to.add(from.get_last());
		from.remove();
		
	}
}
Example #4
0
int main() {
  StringStack ss;
  for(int i = 0; i < iCsz; i++)
    ss.push(&iceCream[i]);
  const string* cp;
  while((cp = ss.pop()) != 0)
    cout << *cp << endl;
} ///:~
Example #5
0
int main() {
  StringStack ss;
  for (int i = 0; i < iCsz; i++)
    ss.push(&iceCream[i]);

  const MyString *cp;
  while((cp = ss.pop()) != NULL)
	  cp->print();
}
int main() {
	StringStack ss;
	for (int i = 0; i < iCsz; i++)
		ss.push(new MyString(&iceCream[i]));
	const MyString* cp;
	
	while ((cp = ss.pop()) != 0) {
		cp->print();
		delete cp;
	}
} ///:~
Example #7
0
int main() {
    StringStack ss;
    myString* ms;
    for(int i = 0; i < iCsz; i++){
	ms = new myString(iceCream[i]);
	ss.push(ms);
    }
    const myString* cp;
    while((cp = ss.pop()) != 0)
	cout << cp->str << endl;
}
Example #8
0
int main(int argc, char const *argv[])
{
	StringStack SS;
	for (int i = 0; i < ICsz; ++i)
	{
		SS.push(iceCream[i]);
	}
	const char* cp;
	while((cp = SS.pop()) != 0)
		cout << cp << endl;
	return 0;
}
Example #9
0
int main() {
  ifstream in("InheritStack.cpp");
  assure(in, "InheritStack.cpp");
  string line;
  StringStack textlines;
  while(getline(in, line))
    textlines.push(new string(line));
  string* s;
  while((s = textlines.pop()) != 0) { // No cast!
    cout << *s << endl;
    delete s;
  }
} ///:~
Example #10
0
void ScreenUpdates_Enable (void)
{
	ASSERT_MESSAGE(!ScreenUpdates_Enabled(), "screen updates already enabled");
	g_wait_stack.pop_back();
	if (g_wait_stack.empty()) {
		map::AutoSaver().startTimer();
		gtk_grab_remove(GTK_WIDGET(g_wait.m_window));
		destroy_floating_window(g_wait.m_window);
		g_wait.m_window = 0;
	} else if (GTK_WIDGET_VISIBLE(g_wait.m_window)) {
		gtk_label_set_text(g_wait.m_label, g_wait_stack.back().c_str());
		ScreenUpdates_process();
	}
}
Example #11
0
const char *execute(S32 argc, const char *argv[])
{
#ifdef TORQUE_MULTITHREAD
   if(isMainThread())
   {
#endif
      Namespace::Entry *ent;
      StringTableEntry funcName = StringTable->insert(argv[0]);
      ent = Namespace::global()->lookup(funcName);

      if(!ent)
      {
         warnf(ConsoleLogEntry::Script, "%s: Unknown command.", argv[0]);

         // Clean up arg buffers, if any.
         STR.clearFunctionOffset();
         return "";
      }
      return ent->execute(argc, argv, &gEvalState);
#ifdef TORQUE_MULTITHREAD
   }
   else
   {
      SimConsoleThreadExecCallback cb;
      SimConsoleThreadExecEvent *evt = new SimConsoleThreadExecEvent(argc, argv, false, &cb);
      Sim::postEvent(Sim::getRootGroup(), evt, Sim::getCurrentTime());
      
      return cb.waitForResult();
   }
#endif
}
Example #12
0
bool CommandLineInterface::DoDirs()
{

    StringStack tempStack;
    
    std::string cwd;
    if (!GetCurrentWorkingDirectory(cwd))
    {
        return false;
    }
    
    // cwd is top of stack
    if (m_RawOutput)
    {
        m_Result << cwd;
    }
    else
    {
        AppendArgTagFast(sml_Names::kParamDirectory, sml_Names::kTypeString, cwd);
    }
    
    // print rest of stack making a new one
    while (m_DirectoryStack.size())
    {
        if (m_RawOutput)
        {
            m_Result << ' ' << m_DirectoryStack.top();
        }
        else
        {
            AppendArgTagFast(sml_Names::kParamDirectory, sml_Names::kTypeString, m_DirectoryStack.top());
        }
        
        tempStack.push(m_DirectoryStack.top());
        m_DirectoryStack.pop();
    }
    
    // put the old stack back together
    while (tempStack.size())
    {
        m_DirectoryStack.push(tempStack.top());
        tempStack.pop();
    }
    return true;
}
Example #13
0
//------------------------------------------------------------------------------
const char *execute(SimObject *object, S32 argc, const char *argv[], bool thisCallOnly)
{
   static char idBuf[16];
   if(argc < 2)
      return "";

   // [neo, 10/05/2007 - #3010]
   // Make sure we don't get recursive calls, respect the flag!   
   // Should we be calling handlesMethod() first?
   if( !thisCallOnly )
   {
      ICallMethod *com = dynamic_cast<ICallMethod *>(object);
      if(com)
         com->callMethodArgList(argc, argv, false);
   }

   if(object->getNamespace())
   {
      dSprintf(idBuf, sizeof(idBuf), "%d", object->getId());
      argv[1] = idBuf;

      StringTableEntry funcName = StringTable->insert(argv[0]);
      Namespace::Entry *ent = object->getNamespace()->lookup(funcName);

      if(ent == NULL)
      {
         //warnf(ConsoleLogEntry::Script, "%s: undefined for object '%s' - id %d", funcName, object->getName(), object->getId());

         // Clean up arg buffers, if any.
         STR.clearFunctionOffset();
         return "";
      }

      // Twiddle %this argument
      const char *oldArg1 = argv[1];
      dSprintf(idBuf, sizeof(idBuf), "%d", object->getId());
      argv[1] = idBuf;

      SimObject *save = gEvalState.thisObject;
      gEvalState.thisObject = object;
      const char *ret = ent->execute(argc, argv, &gEvalState);
      gEvalState.thisObject = save;

      // Twiddle it back
      argv[1] = oldArg1;

      return ret;
   }
   warnf(ConsoleLogEntry::Script, "Con::execute - %d has no namespace: %s", object->getId(), argv[0]);
   return "";
}
Example #14
0
/** Test-driving code for StringStacks.
 */
int main() {
   StringStack* testStack = new StringStack();
   cout << "Pushing \"AAA\" ... ";        //no "endl", keep next on same line
   testStack->push("AAA"); 
   cout << "Pushing \"BBB\" ... " << endl;
   testStack->push("BBB"); 
   cout << "Size is now " << testStack->size() << endl;
   testStack->pop();
   cout << "Pop---size is now " << testStack->size() << endl;
   string c = testStack->pop();
   cout << "I popped the string \""
        << c << "\", size now " << testStack->size() << endl;
   cout << "Can I pop again?" << endl;
   string d = testStack->pop();
   cout << "Oops!  I got: \"" << d << "\"" << endl;
   //delete(testStack);
   StringStack test2 = (*testStack);
   return (0);
}
Example #15
0
void ScreenUpdates_Disable (const std::string& message, const std::string& title)
{
	if (g_wait_stack.empty()) {
		map::AutoSaver().stopTimer();

		while (gtk_events_pending()) {
			gtk_main_iteration();
		}

		const bool isActiveApp = MainFrame_isActiveApp();

		g_wait = create_wait_dialog(title, message);

		if (isActiveApp) {
			gtk_widget_show(GTK_WIDGET(g_wait.m_window));
			gtk_grab_add(GTK_WIDGET(g_wait.m_window));
			ScreenUpdates_process();
		}
	} else if (GTK_WIDGET_VISIBLE(g_wait.m_window)) {
		gtk_label_set_text(g_wait.m_label, message.c_str());
		ScreenUpdates_process();
	}
	g_wait_stack.push_back(message);
}
Example #16
0
void MessageGenerator::doType(StringStack& parent, int indent, const char* tag, IXmlType* type, StringBuffer& buf)
{
    const char* typeName = type->queryName();

    if (type->isComplexType())
    {
        if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end())
        {
            //DBGLOG("Recursive type: %s, ignored", type->queryName());
        }
        else 
        {
            int flds = type->getFieldCount();
            for (int i=0; i<flds; i++)
            {
                const char* fldName = type->queryFieldName(i);
                buf.appendf("<%s>", fldName);
                if (typeName)
                    parent.push_back(typeName);
                doType(parent,indent+1,fldName,type->queryFieldType(i),buf);
                buf.appendf("</%s>", fldName);
                if (typeName)
                    parent.pop_back();
            }
        }
    }
    else if (type->isArray())
    {
        if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end())
        {
            //DBGLOG("Recursive type: %s, ignored", type->queryName());
        }
        else
        {
            const char* itemName = type->queryFieldName(0);
            IXmlType* itemType = type->queryFieldType(0);
            if (typeName)
                parent.push_back(typeName);
            for (int i=0; i<m_items; i++)
            {
                buf.appendf("<%s>", itemName);
                doType(parent,indent+2,itemName, itemType, buf);
                buf.appendf("</%s>", itemName);
            }
            if (m_ecl2esp)
                buf.appendf("<%s/>", itemName);
            if (typeName)
                parent.pop_back();
        }
    }
    else
    {
        //TODO: handle restriction etc
        if (strcmp(typeName,"string")==0) // string type: [tag-typeName]
        {
            if (m_gx)
                buf.append("*** MISSING ***");
            else
                if (m_ecl2esp)
                    buf.append("[?]");
                else
                    buf.appendf("[%s]", tag);
        }
        else
            setDefaultValue(buf,type,tag);
    }
}
Example #17
0
void MessageGenerator::doType(StringStack& parent, int indent, const char* tag, IXmlType* type, IPTree* tmplat, StringBuffer& buf)
{
    const char* typeName = type->queryName();
    if (type->isComplexType())
    {
        if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end())
        {
            //DBGLOG("Recursive type: %s, ignored", typeName);
        }
        else 
        {
            int flds = type->getFieldCount();
            for (int i=0; i<flds; i++)
            {
                const char* fldName = type->queryFieldName(i);
                buf.appendf("<%s>", fldName);
                IPTree* existing = tmplat->queryBranch(fldName);
                if (typeName)
                    parent.push_back(typeName);
                if (existing)
                    doType(parent,indent+1,fldName, type->queryFieldType(i), existing, buf);
                else
                    doType(parent,indent+1,fldName,type->queryFieldType(i),buf);
                buf.appendf("</%s>", fldName);
                if (typeName)
                    parent.pop_back();
            }
        }
    }
    else if (type->isArray())
    {
        if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end())
        {
            //DBGLOG("Recursive type: %s, ignored", typeName);
        }
        else 
        {
            const char* itemName = type->queryFieldName(0);
            IXmlType* itemType = type->queryFieldType(0);
            int childCount = tmplat->numChildren();
            if (typeName)
                parent.push_back(typeName);
            if (childCount>0)
            {
                Owned<IPTreeIterator> items = tmplat->getElements(itemName);
                for (items->first(); items->isValid(); items->next())
                {
                    buf.appendf("<%s>", itemName);
                    doType(parent,indent+2,itemName,itemType,&items->query(),buf);
                    buf.appendf("</%s>", itemName);
                }
            }
            else
            {
                for (int i=0; i<m_items; i++)
                {
                    buf.appendf("<%s>", itemName);
                    doType(parent,indent+2,itemName, itemType, buf);
                    buf.appendf("</%s>", itemName);
                }
                if (m_ecl2esp)
                    buf.appendf("<%s/>", itemName);
            }
            if (typeName)
                parent.pop_back();
        }
    }
    else
    {
        const char* existing = tmplat->queryProp(".");
        if (existing && isNotBlank(existing))
            encodeXML(existing,buf);
        else if (m_gx)
            buf.append("*** MISSING ***");
        else
        {
            DefValMap::const_iterator it = m_cfgDefValues.find(tag);
            if (it != m_cfgDefValues.end())
                buf.append(it->second.c_str());
            else
                type->getSampleValue(buf,tag);
        }
    }
}
Example #18
0
bool ScreenUpdates_Enabled (void)
{
	return g_wait_stack.empty();
}