⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmfilebuilder.cpp

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 CPP
字号:
/*****************************************************************************/
/*                             SOURCE FILE                                   */
/*****************************************************************************/
/*
       $Archive: $

      $Revision: $
          $Date: $
        $Author: $

   Description:  The class contains support for an ordered collection of strings
                 that can be used to create "ordered string buffers" that can 
                 then be "dumped to a file" 

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
static char OBJECT_ID[] = "$Revision: $ : $Date: $";
/*****************************************************************************/


#include "../../../stdafx.h"
#include "VMFileBuilder.h"



/*****************************************************************************/
/*
     FUNCTION NAME: VMStringFileBuilder

       DESCRIPTION: ctor - initialize all members

             INPUT: void

           RETURNS: void
*/
VMStringFileBuilder::VMStringFileBuilder( void )
{
}
/*	end of function "VMStringFileBuilder" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME: ~VMStringFileBuilder

       DESCRIPTION: dtor, call member to remove all heap allocations

             INPUT: void

           RETURNS: void
*/
VMStringFileBuilder::~VMStringFileBuilder( void )
{
  m_oStrings.clear();
}			  
/*	end of function "~VMStringFileBuilder" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME: AddTail

       DESCRIPTION: adds a string to the end of the internal collection	

             INPUT: pchString - the string to add

           RETURNS: true if worked, false if not
*/
bool VMStringFileBuilder::AddTail( const char* pchString )
{
  int iNewKey = m_oStrings.size();

  m_oStrings.insert( STRINGS_BY_LINE::value_type( iNewKey, std::string( pchString ) ) );

  return( true );
}
/*	end of function "AddTail" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME: SetAt

       DESCRIPTION: determines if the string passed in to pStr exists in
                    this class as an entry	

             INPUT: iIndex - index to use for the insert operation
                    pchString - the text to store
                    bReplace - replace existing string

           RETURNS: true if added, false if not	
*/
bool VMStringFileBuilder::SetAt( int iIndex, const char* pchString, bool bReplace )
{
  STRINGS_BY_LINE_ITER oIter;
  oIter = m_oStrings.find( iIndex );
  if ( oIter != m_oStrings.end() )
  {
    if ( bReplace == true )
    {
      m_oStrings.erase( oIter );
      m_oStrings.insert( STRINGS_BY_LINE::value_type( iIndex, std::string( pchString ) ) );
      return( true );      
    }
    else
    {
      return( false );
    }
  }
  else
  {
    m_oStrings.insert( STRINGS_BY_LINE::value_type( iIndex, std::string( pchString ) ) );
    return( true );      
  }
  return( false );
}
/*	end of function "SetAt" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME: RemoveAt

       DESCRIPTION: returns the string located at the given index.

             INPUT: iIndex - the element to get

           RETURNS: the string found at the index, or NULL if there is
                    no string at the given location
*/
bool VMStringFileBuilder::RemoveAt( int iIndex )
{
  STRINGS_BY_LINE_ITER oIter;
  oIter = m_oStrings.find( iIndex );
  if ( oIter != m_oStrings.end() )
  {
    m_oStrings.erase( oIter );
    return( true );      
  }
  else
  {
    return( false );
  }
}
/*	end of function "RemoveAt" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME: GetAt

       DESCRIPTION: returns the string located at the given index.

             INPUT: iIndex - the element to get
                    roOutput - results will go here

           RETURNS: true if index exists, false if not
*/
bool VMStringFileBuilder::GetAt( int iIndex, std::string& roOutput )
{
  STRINGS_BY_LINE_ITER oIter;
  oIter = m_oStrings.find( iIndex );
  if ( oIter != m_oStrings.end() )
  {
    roOutput = (*oIter).second;
    return( true );      
  }
  else
  {
    roOutput = "";
    return( false );
  }
}
/*	end of function "GetAt" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME: RemoveAll

       DESCRIPTION: clears the internal collection

             INPUT: none

           RETURNS: true
*/
bool VMStringFileBuilder::RemoveAll( void )
{
  m_oStrings.clear();
  return( true );
}
/*	end of function "RemoveAll" */
/*****************************************************************************/



/*****************************************************************************/
/* Check-in history */
/*
*$Log: $
*/
/*****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -