//++
//------------------------------------------------------------------------------------
// Details: Append another MI value object to *this MI value result.
// Type:    Method.
// Args:    vrVariable  - (R) MI value's name.
//          vrValue     - (R) The MI value.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
void CMICmnMIValueResult::Add(const CMIUtilString &vrVariable,
                              const CMICmnMIValue &vrValue) {
  if (!m_bEmptyConstruction)
    BuildResult(vrVariable, vrValue);
  else {
    m_bEmptyConstruction = false;
    m_strPartVariable = vrVariable;
    m_partMIValue = vrValue;
    BuildResult();
  }
}
//++
//------------------------------------------------------------------------------------
// Details: CMICmnMIValueResult constructor.
// Type:    Method.
// Args:    vrVariable      - (R) MI value's name.
//          vrValue         - (R) The MI value.
//          vbUseSpacing    - (R) True = put space separators into the string,
//          false = no spaces used.
// Return:  None.
// Throws:  None.
//--
CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable,
                                         const CMICmnMIValue &vrValue,
                                         const bool vbUseSpacing)
    : m_strPartVariable(vrVariable), m_partMIValue(vrValue),
      m_bEmptyConstruction(false), m_bUseSpacing(vbUseSpacing) {
  BuildResult();
}
//=======================================================================
// function:
// purpose:
//=======================================================================
void GEOMAlgo_ShellSolid::Perform()
{
  myErrorStatus=0;
  //
  try {
    if (myDSFiller==NULL) {
      myErrorStatus=10;
      return;
    }
    if(!myDSFiller->IsDone()) {
      myErrorStatus=11;
      return;
    }
    //
    Standard_Boolean bIsNewFiller;
    //
    bIsNewFiller=myDSFiller->IsNewFiller();
    if (bIsNewFiller) {
      Prepare();
      myDSFiller->SetNewFiller(!bIsNewFiller);
    }
    //
    myRank=(myDSFiller->DS().Object().ShapeType()==TopAbs_SHELL) ? 1 : 2;
    BuildResult();
  }
  catch (Standard_Failure) {
    myErrorStatus=12;
  }
}
//=======================================================================
//function : Perform
//purpose  :
//=======================================================================
void GEOMAlgo_Gluer2::Perform()
{
  myErrorStatus=0;
  myWarningStatus=0;
  //
  CheckData();
  if (myErrorStatus) {
    return;
  }
  //
  // Initialize the context
  GEOMAlgo_GluerAlgo::Perform();
  //
  PerformShapesToWork();
  if (myErrorStatus) {
    return;
  }
  if (myWarningStatus==1) {
    // no shapes to glue
    myShape=myArgument;
    return;
  }
  //
  FillVertices();
  if (myErrorStatus) {
    return;
  }
  //
  FillEdges();
  if (myErrorStatus) {
    return;
  }
  //
  FillWires();
  if (myErrorStatus) {
    return;
  }
  //
  FillFaces();
  if (myErrorStatus) {
    return;
  }
  //
  FillShells();
  if (myErrorStatus) {
    return;
  }
  //
  FillSolids();
  if (myErrorStatus) {
    return;
  }
  //
  FillCompSolids();
  if (myErrorStatus) {
    return;
  }
  //
  FillCompounds();
  if (myErrorStatus) {
    return;
  }
  //
  BuildResult();
  if (myErrorStatus) {
    return;
  }
  //
  PrepareHistory();
  if (myErrorStatus) {
    return;
  }
  //
  BRepLib::SameParameter(myShape, myTolerance, Standard_True);
}
Beispiel #5
0
const char *BadWords::Filter(const char *input, int *cch_back) {
    // Filter only if turned on (on is the default).
    if (cch_back != NULL) {
        *cch_back = -1;
    }
    if (!on_ || nodes_.size() == 0) {
        strncpyz(buffer_, input, sizeof(buffer_));
        return buffer_;
    }

    // Traverse the match graph, looking for matches. Handle non-alpha
    // wildcards and insertions, like f*k vs. fu*k.

    std::list<Match> matches;
    std::list<MatchEntry> progress;

    const char *pch = input;
    for (; *pch != 0; pch++) {
        // Ignore whitespace, but track it since it will cancel some matches
        char ch = *pch;

        // Treat newlines specially. This marks the boundary between
        // entered chat. This is tracked.
        if (ch == '\n') {
            std::list<MatchEntry>::iterator it = progress.begin();
            for (; it != progress.end(); it++) {
                it->has_newline = true;
                it->char_index_last = -1;
            }
            continue;
        }

        if (isspace(ch)) {
            std::list<MatchEntry>::iterator it = progress.begin();
            while (it != progress.end()) {
                it->last_space = pch - input;
                if (it->match) {
                    it->char_index_last = -1;
                }
                it++;
            }
            continue;
        }

        if (ch >= 'A' && ch <= 'Z') {
            ch += 'a' - 'A';
        }

        // If it is a letter, match against the match graph.
        if (ch >= 'a' && ch <= 'z') {
            int char_index = ch - 'a';

            // Examine in-progress matches.
            std::list<MatchEntry>::iterator it = progress.begin();
            while (it != progress.end()) {
                // Match a trailing repeated char.
                MatchEntry& entry = *it;
                if (entry.match) {
                    if (entry.char_index_last == char_index) {
                        entry.end = pch - input;
                        if (*(pch + 1) != 0) {
                            it++;
                            continue;
                        }
                    }
                    if (IsMatch(input, entry)) {
                        matches.push_back(Match(entry.start, entry.end));
                    }
                    it = progress.erase(it);
                    continue;
                }
                entry.char_count++;

                // Not matched yet. Is it a match now?
                dword *next_index =
                        &nodes_[entry.current_index].indexes[char_index];
                if (*next_index & kfMatMatch) {
                    if ((!entry.has_newline && entry.wildcard_replacements == 0)
                            || (*next_index & kfMatWildcards) != 0) {
                        // Add a new entry that is the match, ahead of the
                        // iterator, so it gets processed even if this is the
                        // last char.
                        MatchEntry new_entry = entry;
                        new_entry.end = pch - input;
                        new_entry.char_index_last = char_index;
                        new_entry.standalone =
                                (*next_index & kfMatStandalone) != 0;
                        new_entry.standalone |= (new_entry.last_space != -1);
                        new_entry.standalone |=
                                ((new_entry.wildcard_count) != 0);
                        new_entry.match = true;
                        progress.insert(boost::next(it), new_entry);
                    }
                }

                // Follow this char_index to the next node, if there one
                if (*next_index & kfMatIndex) {
                    entry.end = pch - input;
                    entry.current_index = (*next_index & kfMatIndex);
                    entry.char_index_last = char_index;
                    it++;
                    continue;
                }
                // No next node; allow the entry to persist if it is letter
                // doubling.
                if (entry.char_index_last == char_index) {
                    entry.end = pch - input;
                    entry.char_count--;
                    it++;
                    continue;
                }

                // Remove the entry
                it = progress.erase(it);
            }
           
            // Start a new match, if there is one 
            dword node_index = nodes_[0].indexes[char_index] & kfMatIndex;
            if (node_index != 0) {
                MatchEntry entry(pch - input, pch - input, node_index,
                        char_index);
                entry.char_count = 1;
                progress.push_back(entry);
            }
            continue;
        }

        // Not a-z, handle skip and insertion. Insertion is easy, just
        // preserve existing MatchEntrys. Skips require wildcarding:
        // clone existing MatchEntrys, and step them for each next node.
        // Add new match entries for all first char matches.

        std::list<MatchEntry>::iterator it = progress.begin();
        int next_indexes[26];
        int index_count;

        // Start new wildcard match entries only if this is a whitespace
        // boundary. Otherwise it is easy to cause an explosion of match
        // entries by simply typing "***************".

        if (pch == input || isspace(*(pch - 1))) {
            index_count = GetNextCharIndexes(0, next_indexes);
            for (int i = 0; i < index_count; i++) {
                // Push to the front so these entries aren't enumerated again
                dword *next_index = &nodes_[0].indexes[next_indexes[i]];
                MatchEntry entry(pch - input, pch - input,
                        (*next_index & kfMatIndex), -1);
                entry.wildcard_count = 1;
                entry.wildcard_replacements = 1;
                progress.push_front(entry);
            }
        }

        // Handle wildcarding in existing entries
        while (it != progress.end()) {
            // Don't span existing matched entries over wildcard chars.
            MatchEntry& entry = *it;
            if (entry.match) {
                if (IsMatch(input, entry)) {
                    matches.push_back(Match(entry.start, entry.end));
                }
                it = progress.erase(it);
                continue;
            }
            entry.wildcard_count++;

            // Enumerate next nodes, and make new stepped MatchEntrys for each.
            index_count = GetNextCharIndexes(entry.current_index, next_indexes);
            for (int i = 0; i < index_count; i++) {
                dword *next_index =
                        &nodes_[entry.current_index].indexes[next_indexes[i]];
                // Only match if there is a trailing whitespace boundary
                if (*(pch + 1) == 0 || isspace(*(pch + 1))) {
                    if ((*next_index & (kfMatMatch | kfMatWildcards)) ==
                            (kfMatMatch | kfMatWildcards)) {
                        // And there is more string to be evaled
                        if (*(pch + 1) != 0) {
                            // Add a floating MatchEntry, in order to suck up
                            // repeated chars of the match.
                            MatchEntry new_entry = entry;
                            new_entry.end = pch - input;

                            // Standalone, because since there is a wildcard,
                            // the entry is by definition standalone only.
                            new_entry.standalone = true;
                            new_entry.match = true;
                            new_entry.wildcard_replacements++;
                            progress.insert(it, new_entry);
                        } else {
                            // There is a wildcard, so by definition, it is
                            // standalone only.
                            MatchEntry new_entry = entry;
                            new_entry.standalone = true;
                            new_entry.end = pch - input;
                            new_entry.wildcard_replacements++;
                            if (IsMatch(input, new_entry)) {
                                matches.push_back(Match(new_entry.start,
                                        new_entry.end));
                            }
                        }
                    }
                }

                // If there is a child at this char (already know there is)
                if (*next_index & kfMatIndex) {
                    // And there has been kcWildcardsEntryMax wildcards only
                    if (entry.wildcard_count <= kcWildcardsEntryMax) {
                        // Then add a new match entry to track this path.
                        MatchEntry new_entry = entry;
                        new_entry.current_index = (*next_index & kfMatIndex);
                        new_entry.end = pch - input;
                        new_entry.wildcard_replacements++;
                        progress.insert(it, new_entry);
                    }
                }
            }
            it++;
        }
    }

    if (matches.size() > 1) {
        // See if the matches overlap; if so clean them up.
        bool overlap = false;
        std::list<Match>::iterator it = matches.begin();
        for (; it != matches.end(); it++) {
            std::list<Match>::iterator it_next = boost::next(it);
            if (it_next != matches.end()) {
                if ((*it).end >= (*it_next).start) {
                    overlap = true;
                    break;
                }
            }
        }
        if (overlap) {
            CleanupMatches(matches);
        }
    }

    // Find the earliest starting entry that spans the end.
    // If this overlaps a match, start from the match.
    if (cch_back != NULL) { 
        int earliest = -1;
        std::list<MatchEntry>::iterator it = progress.begin();
        for (; it != progress.end(); it++) {
            if (earliest == -1 || (*it).start < earliest) {
                earliest = (*it).start;
            }
        }
        if (earliest != -1) {
            std::list<Match>::iterator itm = matches.begin();
            for (; itm != matches.end(); itm++) {
                if (itm->end >= earliest) {
                    earliest = itm->start;
                }
            }
            *cch_back = (pch - input) - earliest;
        }
    }

    // Any matches? If not, return the original line
    if (matches.size() == 0) {
        strncpyz(buffer_, input, sizeof(buffer_));
        return buffer_;
    }

    // Finally, build the new string.
    return BuildResult(input, matches);
}
// @brief: handles webclient
// @param[in]: socket - socket that client is connected on
// @param[in]: ip_addr - ip address of the client
void WebHostEmulator::HandleClient(SOCKET* socket, const std::string ip_addr)
{
#ifdef __DEBUG
	static int ThreadCounter = 0;
	const int ThreadID = ThreadCounter++;
	printf("Thread %i started\n", ThreadID);
#endif

	std::queue <std::string> RecvQueue;
	std::string Received, overflow;

	while (1) {
		// Recieve
		std::string RecvBuffer;
		RecvBuffer.resize(8192);
	
		int iResult = recv(*socket, &RecvBuffer[0], RecvBuffer.length(), 0);

		if (iResult <= 0) {
#ifdef __DEBUG
			printf("Thread %i ended\n", ThreadID);
#endif
			closesocket(*socket);
			delete socket;
			return;
		}

		RecvBuffer.resize(iResult);

		if (parseHTTP (RecvBuffer, Received, overflow) != 0) {
			continue;
		}
		
#ifdef __DEBUG
		printf("Received Message:-----\n%s\nEnd Received-----\n\n", Received.c_str());
#endif

		// Send
		size_t found;
		std::string Body, ContentLength, ContentType, Header, Response;

		found = Received.find("GET");
		if (found == 0) {
			size_t start = Received.find("/");
			size_t end = Received.find(" ", start);

			ContentType = GetReq(std::string(Received, start, end - start), Body);
			Header = BuildHeader(Body, 200, ContentType, true);

			Response = Header + Body;

			iResult = send(*socket, Response.c_str(), Response.size(), 0);
		}

		found = Received.find("POST");
		if (found == 0) {

			size_t start = Received.find("/");
			size_t end = Received.find(" ", start);

			std::string Result = PostReq(
				std::string(Received, start, end - start),
				GetBody(Received),
				ip_addr
				);

			ContentType = "text/html"; // This is a temp fix.

			Body = BuildResult(Result, std::string("result.html"));
			Header = BuildHeader(Body, 200, ContentType, false);

			Response = Header + Body;

			iResult = send(*socket, Response.c_str(), Response.size(), 0);
		}

		Received.clear();
	}

#ifdef __DEBUG
	printf("Thread %i ended\n", ThreadID);
#endif

	closesocket(*socket);

	delete socket;
	return;
}