Giter Club home page Giter Club logo

ccbi2ccb's People

Contributors

nkligang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ccbi2ccb's Issues

Should this section of code be written the way it is?

I'm looking at a section of this code (line 254-271 in ccbi2ccb.cpp) and right now it looks like this:

} else if (m_mapPropertyCount.size() > 1) {
  std::map<std::string, int>::iterator itClass = m_mapPropertyCount.begin();
  std::string klass = itClass->first;
  int prority = 0;
  itClass++;
  for (; itClass != m_mapPropertyCount.end(); itClass++)
  {
    std::map<std::string, int>::iterator parenetIt = m_mapClassPriorty.find(itClass->first);
    if (parenetIt != m_mapClassPriorty.end())
    {
      if (parenetIt->second > prority) {
        klass = itClass->first;
        prority = parenetIt->second;
      }
    }
  }
  return klass;
}

I'm a bit confused by how the first part of it works.

//Okay, make the iterator. That makes sense
std::map<std::string, int>::iterator itClass = m_mapPropertyCount.begin();
//Set klass to the first item. Okay, I guess you could do it like that...
std::string klass = itClass->first;
// Wait what? We are not setting it to the actual priority of the value of klass???
int prority = 0;
itClass++;

So the first class in the list is being set as having a priority of 0, regardless of it's actual priority? I think this part of the function should be written as something like this:

} else if (m_mapPropertyCount.size() > 1) {
  std::map<std::string, int>::iterator itClass = m_mapPropertyCount.begin();
  std::string klass = ""; 
  int prority = 0;
  for (; itClass != m_mapPropertyCount.end(); itClass++)
  {
    std::map<std::string, int>::iterator parenetIt = m_mapClassPriorty.find(itClass->first);
    if (parenetIt != m_mapClassPriorty.end())
    {
      if (parenetIt->second > prority) {
        klass = itClass->first;
        prority = parenetIt->second;
      }
    }
  }
  return klass;
}

By writing it this way, we start with an empty string, which would be considered as a class that has a priority of 0. All other values would have a priority of 1 or higher, meaning the first class in the list would be set as the value of klass, and the priority would be correct.

Or maybe I am missing something?

Line 158 in ccbiReader.cpp is incorrect

size_t ccbiReader::readBytes(void * _DstBuf, size_t _ElementSize, size_t _Count)
{
  size_t _s = _ElementSize * _Count;
  if (currentByte + _s <= (size_t)byteSize)
  {
    memcpy(_DstBuf, (char*)bytes + currentByte, _s);
    currentByte += (int)_s;
    return _s;
  }
  else if (currentByte < byteSize)
  {
    memcpy(_DstBuf, (char*)bytes + currentByte, byteSize - currentByte);
    currentByte = byteSize;
    return byteSize - currentByte; // This is line 158
  }
  else
  {
    return 0;
  }
}

Line 158 should be returning the number of bytes read, but because of line 157 (currentByte = byteSize;) , line 158 will always calculate to 0. This is because currentByte was changed before the amount read was calculated. A correction would look something like this:

size_t ccbiReader::readBytes(void * _DstBuf, size_t _ElementSize, size_t _Count)
{
  size_t _s = _ElementSize * _Count;
  if (currentByte + _s <= (size_t)byteSize)
  {
    memcpy(_DstBuf, (char*)bytes + currentByte, _s);
    currentByte += (int)_s;
    return _s;
  }
  else if (currentByte < byteSize)
  {
    memcpy(_DstBuf, (char*)bytes + currentByte, byteSize - currentByte);
    size_t ret = byteSize - currentByte;
    currentByte = byteSize;
    return ret;
  }
  else
  {
    return 0;
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.