//print method void AudioStream::print (void) { if (streamIsSelected()) std::cout << " + "; else std::cout << " - "; std::cout << "Audio Stream: " << getId(); std::cout << ", Language: " << getLangCode(); std::cout << "-" << getLanguage(); std::cout << ", Format: " << getFormat(); std::cout << ", Quantization: " << getQuantization(); std::cout << ", Frequency: " << getFrequency(); std::cout << ", Channels: " << getChannels(); std::cout << ", Type: " << getLangExtension(); if (getSize() == 0) { std::cout << ", Size: na" << std::endl; } else { std::cout << ", Size: " << getSize() << " MB" << std::endl; } }
void AudioStream::printXml (void) { std::stringstream size; if (getSize() == 0) { size << "na"; } else { size << getSize(); } std::cout << " <audio size=\"" << size.str() << "\" id=\"" << getId() << "\" language=\"" << getLanguage() << "\" languageCode=\"" << getLangCode() << "\" format=\"" << getFormat() << "\" quantization=\"" << getQuantization() << "\" frequency=\"" << getFrequency() << "\" channels=\"" << getChannels() << "\" type=\"" << getLangExtension() << "\"/>" << std::endl; }
//Format as XML tag for dvdauthor std::string AudioStream::toXml(void) { std::ostringstream xml; xml << "<audio format=\"" << getFormat() << "\" channels=\"" << getChannels() << "\" "; xml << "quant=\"" << getQuantization() << "\" samplerate=\"" << getFrequency() << "\" lang=\"" << getLangCode() << "\"/>"; return xml.str(); }
/* Load, argument is a file listing the key file and translation files The key file contains all keys, each one on a different line A translation file contains pair of key-value for the given translation */ bool StringTable::load(const std::string filename) { std::string keyFile; std::vector<std::string> translationFiles; InputLineStream *inputLineStream; // Read index file inputLineStream= new InputLineStream(Toolkit::getFileManager()->openInputStreamBackend(filename)); if (inputLineStream->isEndOfStream()) { delete inputLineStream; return false; } else { keyFile = inputLineStream->readLine(); while (!inputLineStream->isEndOfStream()) { const std::string &s = inputLineStream->readLine(); if (s != "") translationFiles.push_back(s); } delete inputLineStream; } if (translationFiles.size() == 0) return false; languageCount = translationFiles.size(); // Temporary storage for keys and translations std::vector<std::string> keys; std::vector<std::map<std::string, std::string> > translations(translationFiles.size()); // Load keys inputLineStream = new InputLineStream(Toolkit::getFileManager()->openInputStreamBackend(keyFile)); if (inputLineStream->isEndOfStream()) { delete inputLineStream; return false; } else { size_t line = 0; while (!inputLineStream->isEndOfStream()) { std::string s = inputLineStream->readLine(); if (s.length() > 0) { if ((s.length() < 2) || (s[0] != '[') || (s[s.length()-1] != ']')) std::cerr << "StringTable::load(" << keyFile << ") : keys must be in bracket. Invalid key " << s << " at line " << line << " ignored" << std::endl; else keys.push_back(s); } line++; } delete inputLineStream; } // Load translations for (size_t i=0; i<translationFiles.size(); i++) { inputLineStream = new InputLineStream(Toolkit::getFileManager()->openInputStreamBackend(translationFiles[i])); if (inputLineStream->isEndOfStream()) { delete inputLineStream; return false; } else { while (!inputLineStream->isEndOfStream()) { const std::string &key = inputLineStream->readLine(); const std::string &value = inputLineStream->readLine(); translations[i][key] = value; } delete inputLineStream; } } // Create entries for (size_t i=0; i<keys.size(); i++) { const std::string &key = keys[i]; OneStringToken *entry = new OneStringToken; for (size_t j=0; j<translations.size(); j++) { std::map<std::string, std::string>::const_iterator it = translations[j].find(key); if (it != translations[j].end()) entry->data.push_back(it->second); else entry->data.push_back(""); } stringAccess[key] = strings.size(); strings.push_back(entry); } // Check for consistency for (std::map<std::string, size_t>::iterator it=stringAccess.begin(); it!=stringAccess.end(); ++it) { // For each entry... bool lcwp=false; int baseCount=0; const std::string &s = it->first; // we check that we only have valid format (from a FormatableString point of view)... for (size_t j=0; j<s.length(); j++) { char c = s[j]; if (lcwp && c!=' ' && c!='%') { if (isdigit(c)) baseCount++; else { std::cerr << "StringTable::load(\"" << filename << "\") : error, consistency : text=(" << s << "), Only %x where x is a number are supported in translations !" << std::endl; assert(false); return false; } } lcwp=(c=='%'); } // then we are sure that format are correct in all translation for (size_t i=0; i<strings[it->second]->data.size(); i++) { const std::string &s = strings[it->second]->data[i]; bool lcwp=false; int count=0; for (size_t j=0; j<s.length(); j++) { char c=s[j]; if (lcwp && c!=' ' && c!='%') { if (isdigit(c)) count++; else { std::cerr << "StringTable::load(\"" << filename << "\") : error, translation consistency : translation=(" << s << "Only %x where x is a number are supported in translations !" << std::endl; assert(false); return false; } } lcwp=(c=='%'); } // if not, issue an error message if (baseCount!=count && s!="") { std::cerr << "StringTable::load(\"" << filename << "\") : error, translation : in " << translationFiles[i] << ", text = [" << baseCount << "] (" << it->first << "), translation = [" << count << "] (" << s << "), doesn't match !" << std::endl; assert(false); return false; } } } for(unsigned i=0; i<translations.size(); ++i) { languageCodes[getStringInLang("[language-code]", i)] = i; } defaultLang = getLangCode("en"); return true; }