Container System 0.1.0
High-performance C++20 type-safe container framework with SIMD-accelerated serialization
Loading...
Searching...
No Matches
scenarios::ContentManagementSystem Class Reference

Content Management System. More...

Collaboration diagram for scenarios::ContentManagementSystem:
Collaboration graph

Classes

struct  Document
 

Public Member Functions

void simulate_cms_scenario ()
 

Private Member Functions

std::string generate_sample_content (int index)
 
void process_document (const Document &document)
 
void create_search_index_entry (const Document &document)
 
size_t count_words (const std::string &text)
 

Private Attributes

std::atomic< int > documents_processed_ {0}
 
std::atomic< int > documents_indexed_ {0}
 

Detailed Description

Content Management System.

Examples
real_world_scenarios.cpp.

Definition at line 482 of file real_world_scenarios.cpp.

Member Function Documentation

◆ count_words()

size_t scenarios::ContentManagementSystem::count_words ( const std::string & text)
inlineprivate
Examples
real_world_scenarios.cpp.

Definition at line 615 of file real_world_scenarios.cpp.

615 {
616 std::istringstream iss(text);
617 std::string word;
618 size_t count = 0;
619 while (iss >> word) {
620 count++;
621 }
622 return count;
623 }

Referenced by create_search_index_entry().

Here is the caller graph for this function:

◆ create_search_index_entry()

void scenarios::ContentManagementSystem::create_search_index_entry ( const Document & document)
inlineprivate
Examples
real_world_scenarios.cpp.

Definition at line 598 of file real_world_scenarios.cpp.

598 {
599 auto index_container = std::make_shared<value_container>();
600 index_container->set_source("text_analyzer", "indexing_service");
601 index_container->set_target("search_service", "index_updater");
602 index_container->set_message_type("search_index_update");
603
604 index_container->set("document_id", document.document_id);
605 index_container->set("indexed_title", document.title);
606 index_container->set("indexed_category", document.category);
607 index_container->set("word_count", static_cast<int32_t>(count_words(document.content)));
608 index_container->set("index_timestamp", static_cast<int64_t>(
609 std::chrono::duration_cast<std::chrono::milliseconds>(
610 std::chrono::system_clock::now().time_since_epoch()).count()));
611
612 index_container->serialize_string(value_container::serialization_format::binary).value();
613 }
size_t count_words(const std::string &text)

References scenarios::ContentManagementSystem::Document::category, scenarios::ContentManagementSystem::Document::content, count_words(), scenarios::ContentManagementSystem::Document::document_id, and scenarios::ContentManagementSystem::Document::title.

Referenced by process_document().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_sample_content()

std::string scenarios::ContentManagementSystem::generate_sample_content ( int index)
inlineprivate
Examples
real_world_scenarios.cpp.

Definition at line 561 of file real_world_scenarios.cpp.

561 {
562 std::stringstream content;
563 content << "This is sample content for document " << index << ". ";
564 content << "It contains important information for demonstration purposes.";
565 return content.str();
566 }

Referenced by simulate_cms_scenario().

Here is the caller graph for this function:

◆ process_document()

void scenarios::ContentManagementSystem::process_document ( const Document & document)
inlineprivate
Examples
real_world_scenarios.cpp.

Definition at line 568 of file real_world_scenarios.cpp.

568 {
569 auto container = std::make_shared<value_container>();
570 container->set_source("cms_upload_service", "document_processor");
571 container->set_target("search_indexer", "text_analyzer");
572 container->set_message_type("document_processing");
573
574 container->set("document_id", document.document_id);
575 container->set("title", document.title);
576 container->set("author", document.author);
577 container->set("category", document.category);
578 container->set("content_length", static_cast<int32_t>(document.content.length()));
579 container->set("upload_timestamp", static_cast<int64_t>(
580 std::chrono::duration_cast<std::chrono::milliseconds>(
581 document.upload_time.time_since_epoch()).count()));
582 container->set("tag_count", static_cast<int32_t>(document.tags.size()));
583 container->set("content", document.content);
584
585 for (size_t i = 0; i < document.tags.size(); ++i) {
586 container->set("tag_" + std::to_string(i), document.tags[i]);
587 }
588
589 container->serialize_string(value_container::serialization_format::binary).value();
592
593 if (documents_processed_ % 20 == 0) {
594 std::cout << " Processed " << documents_processed_.load() << " documents..." << std::endl;
595 }
596 }
void create_search_index_entry(const Document &document)

References scenarios::ContentManagementSystem::Document::author, scenarios::ContentManagementSystem::Document::category, scenarios::ContentManagementSystem::Document::content, create_search_index_entry(), scenarios::ContentManagementSystem::Document::document_id, documents_indexed_, documents_processed_, scenarios::ContentManagementSystem::Document::tags, scenarios::ContentManagementSystem::Document::title, and scenarios::ContentManagementSystem::Document::upload_time.

Referenced by simulate_cms_scenario().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ simulate_cms_scenario()

void scenarios::ContentManagementSystem::simulate_cms_scenario ( )
inline
Examples
real_world_scenarios.cpp.

Definition at line 498 of file real_world_scenarios.cpp.

498 {
499 std::cout << "\n=== Content Management System Scenario ===" << std::endl;
500
501 const int num_documents = 50;
502
503 std::queue<Document> document_queue;
504 std::mutex document_mutex;
505 std::condition_variable document_cv;
506 std::atomic<bool> uploading_active{true};
507
508 std::thread document_processor([&]() {
509 while (uploading_active || !document_queue.empty()) {
510 std::unique_lock<std::mutex> lock(document_mutex);
511 document_cv.wait(lock, [&]() { return !document_queue.empty() || !uploading_active; });
512
513 if (!document_queue.empty()) {
514 Document document = document_queue.front();
515 document_queue.pop();
516 lock.unlock();
517
518 process_document(document);
520 }
521 }
522 });
523
524 std::vector<std::string> categories = {"article", "report", "manual"};
525 std::vector<std::string> authors = {"john_smith", "jane_doe", "bob_wilson"};
526 std::vector<std::vector<std::string>> tag_sets = {
527 {"programming", "cpp", "tutorial"},
528 {"business", "report", "analysis"},
529 {"technical", "manual", "guide"}
530 };
531
532 for (int i = 0; i < num_documents; ++i) {
533 Document document;
534 document.document_id = "DOC" + std::to_string(10000 + i);
535 document.title = "Document Title " + std::to_string(i);
536 document.content = generate_sample_content(i);
537 document.author = authors[i % authors.size()];
538 document.category = categories[i % categories.size()];
539 document.tags = tag_sets[i % tag_sets.size()];
540 document.upload_time = std::chrono::system_clock::now();
541
542 {
543 std::lock_guard<std::mutex> lock(document_mutex);
544 document_queue.push(document);
545 }
546 document_cv.notify_one();
547
548 std::this_thread::sleep_for(std::chrono::milliseconds(10));
549 }
550
551 uploading_active = false;
552 document_cv.notify_all();
553 document_processor.join();
554
555 std::cout << "CMS simulation completed:" << std::endl;
556 std::cout << " Documents processed: " << documents_processed_.load() << std::endl;
557 std::cout << " Documents indexed: " << documents_indexed_.load() << std::endl;
558 }
void process_document(const Document &document)

References scenarios::ContentManagementSystem::Document::author, scenarios::ContentManagementSystem::Document::category, scenarios::ContentManagementSystem::Document::content, scenarios::ContentManagementSystem::Document::document_id, documents_indexed_, documents_processed_, generate_sample_content(), process_document(), scenarios::ContentManagementSystem::Document::tags, scenarios::ContentManagementSystem::Document::title, and scenarios::ContentManagementSystem::Document::upload_time.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ documents_indexed_

std::atomic<int> scenarios::ContentManagementSystem::documents_indexed_ {0}
private
Examples
real_world_scenarios.cpp.

Definition at line 495 of file real_world_scenarios.cpp.

495{0};

Referenced by process_document(), and simulate_cms_scenario().

◆ documents_processed_

std::atomic<int> scenarios::ContentManagementSystem::documents_processed_ {0}
private
Examples
real_world_scenarios.cpp.

Definition at line 494 of file real_world_scenarios.cpp.

494{0};

Referenced by process_document(), and simulate_cms_scenario().


The documentation for this class was generated from the following file: