core/vil/file_formats/vil_nitf2_classification.cxx
Go to the documentation of this file.
00001 // vil_nitf2: Written by Rob Radtke (rob@) and Harry Voorhees (hlv@) of
00002 // Stellar Science Ltd. Co. (stellarscience.com) for
00003 // Air Force Research Laboratory, 2005.
00004 
00005 #include "vil_nitf2_classification.h"
00006 
00007 #include "vil_nitf2_tagged_record.h"
00008 #include "vil_nitf2_field_definition.h"
00009 #include "vil_nitf2_typed_field_formatter.h"
00010 
00011 #include <vcl_cassert.h>
00012 
00013 
00014 vil_nitf2_classification::type_field_defs_map & vil_nitf2_classification::s_field_definitions()
00015 {
00016   class type_field_defs_map_t : public vil_nitf2_classification::type_field_defs_map
00017   {
00018    public:
00019     ~type_field_defs_map_t()
00020     {
00021       for (iterator it = begin(), last = end();
00022            it != last; it++ )
00023       {
00024         delete it->second;
00025       }
00026     }
00027   };
00028   static type_field_defs_map_t field_definitions;
00029   return field_definitions;
00030 }
00031 
00032 const vil_nitf2_field_definitions* vil_nitf2_classification::
00033 get_field_definitions(const file_version& version,
00034                       vcl_string tag_prefix, vcl_string pretty_name_prefix)
00035 {
00036   vil_nitf2_field_definitions* field_defs = 0;
00037   if (version == V_NITF_20 || version == V_NITF_21) {
00038     type_field_defs_key key =
00039       vcl_make_pair(version, vcl_make_pair(tag_prefix, pretty_name_prefix));
00040     type_field_defs_map::const_iterator map_entry = s_field_definitions().find(key);
00041     if (map_entry != s_field_definitions().end()) {
00042       field_defs = map_entry->second;
00043     } else {
00044       field_defs = new vil_nitf2_field_definitions();
00045       add_field_defs(field_defs, version, tag_prefix, pretty_name_prefix);
00046       s_field_definitions().insert(vcl_make_pair(key, field_defs));
00047     }
00048   }
00049   else
00050     assert(!"vil_nitf2_classification::get_field_definitions() called with unsupported version!");
00051   return field_defs;
00052 }
00053 
00054 void vil_nitf2_classification::
00055 add_field_defs(vil_nitf2_field_definitions* defs, const file_version& version,
00056                vcl_string tag_prefix, vcl_string pretty_name_prefix)
00057 {
00058   const vcl_string& tp = tag_prefix;
00059   const vcl_string np = pretty_name_prefix + " ";
00060   switch (version)
00061   {
00062    case V_NITF_20:
00063     (*defs)
00064     .field(tp+"SCLAS", np+"Security Classification",
00065            NITF_ENUM(1, vil_nitf2_enum_values()
00066              .value("T", "Top Secret")
00067              .value("S", "Secret")
00068              .value("C", "Confidential")
00069              .value("R", "Restricted")
00070              .value("U", "Unclassified")),
00071             false, 0, 0)
00072     .field(tp+"SCODE", np+"Codewords",                NITF_STR_ECSA(40), true, 0, 0)
00073     .field(tp+"SCTLH", np+"Control and Handling",     NITF_STR_ECSA(40), true, 0, 0)
00074     .field(tp+"SREL",  np+"Releasing Instructions",   NITF_STR_ECSA(40), true, 0, 0)
00075     .field(tp+"SCAUT", np+"Classification Authority", NITF_STR_ECSA(20), true, 0, 0)
00076     .field(tp+"SCTLN", np+"Security Control Number",  NITF_STR_ECSA(20), true, 0, 0)
00077     .field(tp+"SDWNG", np+"Security Downgrade",       NITF_STR_ECSA(6),  true, 0, 0)
00078     .field(tp+"SDEVT", np+"Downgrading Event",        NITF_STR_ECSA(40), true, 0,
00079            new vil_nitf2_field_value_one_of<vcl_string>(tp+"SDWNG", "999998"));
00080     break;
00081    case V_NITF_21:
00082     (*defs)
00083       .field(tp+"SCLAS", np+"Security Classification",
00084              NITF_ENUM(1, vil_nitf2_enum_values()
00085                .value("T", "Top Secret")
00086                .value("S", "Secret")
00087                .value("C", "Confidential")
00088                .value("R", "Restricted")
00089                .value("U", "Unclassified")),
00090               false, 0, 0)
00091     .field(tp+"SCLSY", np+"Security Classification System", NITF_STR_ECSA(2),  true, 0, 0)
00092     .field(tp+"SCODE", np+"Codewords",                      NITF_STR_ECSA(11), true, 0, 0)
00093     .field(tp+"SCTLH", np+"Control and Handling",           NITF_STR_ECSA(2),  true, 0, 0)
00094     .field(tp+"SREL",  np+"Releasing Instructions",         NITF_STR_ECSA(20), true, 0, 0)
00095     //TODO: should this be an enum that accepts only DD, DE, GD, GE, 0, X and <blank>?
00096     .field(tp+"SDCTP", np+"Declassification Type",          NITF_STR_ECSA(2),  true, 0, 0)
00097     //this field def is only used for NITF2.1, so we can use NitfDT
00098     .field(tp+"SDCDT", np+"Declassification Date",          NITF_DAT(8),       true, 0, 0)
00099     //TODO: Should this instead be a NitfEnum that accepts only [X1-X8] and [x251-X259]??
00100     .field(tp+"SDCXM", np+"Declassification Exemption",     NITF_STR_ECSA(4),  true, 0, 0)
00101     .field(tp+"SDG",   np+"Downgrade",
00102            NITF_ENUM(1, vil_nitf2_enum_values()
00103              .value("S", "Secret")
00104              .value("C", "Confidential")
00105              .value("R", "Restricted")),
00106             true, 0, 0)
00107     //this field def is only used for NITF2.1, so we can use NitfDT
00108     .field(tp+"SDGDT", np+"Downgrade Date",                 NITF_DAT(8),       true, 0, 0)
00109     .field(tp+"SCLTX", np+"Classification Text",            NITF_STR_ECSA(43), true, 0, 0)
00110     .field(tp+"SCATP", np+"Classification Authority Type",
00111            NITF_ENUM(1, vil_nitf2_enum_values()
00112              .value("O", "Original classification authority")
00113              .value("D", "Derivative from a single source")
00114              .value("M", "Derivative from multiple sources")),
00115             true, 0, 0)
00116     .field(tp+"SCAUT", np+"Classification Authority",       NITF_STR_ECSA(40), true, 0, 0)
00117     .field(tp+"SCRSN", np+"Classification Reason",
00118            NITF_ENUM(1, vil_nitf2_enum_values()
00119              .value("A", "Military plans, weapons systems, or operations")
00120              .value("B", "Foreign government information")
00121              .value("C", "Intelligence activities (including special activities), intelligence sources or methods, or cryptology")
00122              .value("D", "Foreign relations or foreign activities of the United States, including confidential sources")
00123              .value("E", "Scientific, technological, or economic matters relating to national security")
00124              .value("F", "United States Government programs for safeguarding nuclear materials or facilities")
00125              .value("G", "Vulnerabilities or capabilities of systems, installations, projects or plans relating to the national security")),
00126             true, 0, 0)
00127     //order of data/time depends on NITF2.1 or NITF2.0, so just read in as string for now
00128     .field(tp+"SSRDT", np+"Security Source Date",           NITF_DAT(8),       true, 0, 0)
00129     .field(tp+"SCTLN", np+"Security Control Number",        NITF_STR_ECSA(15), true, 0, 0);
00130     break;
00131    default:
00132     assert(!"vil_nitf2_classification::add_field_defs() called with unsupported version!");
00133   }
00134 }